Changeset 631ec80
- Timestamp:
- 2012-11-25T14:26:23Z (12 years ago)
- Branches:
- master
- Children:
- 7f557d5
- Parents:
- 96dd574
- Location:
- protocols/twitter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r96dd574 r631ec80 53 53 struct twitter_data *td = ic->proto_data; 54 54 55 /* Create the room now that we "logged in". */ 56 if (td->flags & TWITTER_MODE_CHAT) 57 twitter_groupchat_init(ic); 58 55 59 imcb_log(ic, "Getting initial statuses"); 56 60 … … 76 80 } 77 81 82 struct groupchat *twitter_groupchat_init(struct im_connection *ic) 83 { 84 char *name_hint; 85 struct groupchat *gc; 86 struct twitter_data *td = ic->proto_data; 87 GSList *l; 88 89 if (td->timeline_gc) 90 return td->timeline_gc; 91 92 td->timeline_gc = gc = imcb_chat_new(ic, "twitter/timeline"); 93 94 name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user); 95 imcb_chat_name_hint(gc, name_hint); 96 g_free(name_hint); 97 98 for (l = ic->bee->users; l; l = l->next) { 99 bee_user_t *bu = l->data; 100 if (bu->ic == ic) 101 imcb_chat_add_buddy(td->timeline_gc, bu->handle); 102 } 103 imcb_chat_add_buddy(gc, ic->acc->user); 104 105 return gc; 106 } 107 78 108 static void twitter_oauth_start(struct im_connection *ic); 79 109 … … 86 116 if (set_getbool(&ic->acc->set, "oauth") && !td->oauth_info) 87 117 twitter_oauth_start(ic); 88 else if ( g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "one") != 0&&89 118 else if ((td->flags & TWITTER_MODE_ONE) && 119 !(td->flags & TWITTER_HAVE_FRIENDS)) { 90 120 imcb_log(ic, "Getting contact list"); 91 121 twitter_get_friends_ids(ic, -1); … … 354 384 td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH); 355 385 td->log_id = -1; 386 387 s = set_getstr(&ic->acc->set, "mode"); 388 if (g_strcasecmp(s, "one") == 0) 389 td->flags |= TWITTER_MODE_ONE; 390 else if (g_strcasecmp(s, "many") == 0) 391 td->flags |= TWITTER_MODE_MANY; 392 else 393 td->flags |= TWITTER_MODE_CHAT; 356 394 357 395 twitter_login_finish(ic); -
protocols/twitter/twitter.h
r96dd574 r631ec80 105 105 106 106 void twitter_log(struct im_connection *ic, char *format, ... ); 107 struct groupchat *twitter_groupchat_init(struct im_connection *ic); 107 108 108 109 #endif //_TWITTER_H -
protocols/twitter/twitter_lib.c
r96dd574 r631ec80 70 70 }; 71 71 72 static void twitter_groupchat_init(struct im_connection *ic);73 74 72 /** 75 73 * Frees a twitter_xml_user struct. … … 148 146 // Check if the buddy is already in the buddy list. 149 147 if (!bee_user_by_handle(ic->bee, ic, name)) { 150 char *mode = set_getstr(&ic->acc->set, "mode");151 152 148 // The buddy is not in the list, add the buddy and set the status to logged in. 153 149 imcb_add_buddy(ic, name, NULL); 154 150 imcb_rename_buddy(ic, name, fullname); 155 if ( g_strcasecmp(mode, "chat") == 0) {151 if (td->flags & TWITTER_MODE_CHAT) { 156 152 /* Necessary so that nicks always get translated to the 157 153 exact Twitter username. */ 158 154 imcb_buddy_nick_hint(ic, name, name); 159 155 imcb_chat_add_buddy(td->timeline_gc, name); 160 } else if ( g_strcasecmp(mode, "many") == 0)156 } else if (td->flags & TWITTER_MODE_MANY) 161 157 imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL); 162 158 } … … 305 301 306 302 td = ic->proto_data; 307 308 /* Create the room now that we "logged in". */309 if (!td->timeline_gc && g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "chat") == 0)310 twitter_groupchat_init(ic);311 303 312 304 txl = g_new0(struct twitter_xml_list, 1); … … 663 655 } 664 656 665 static void twitter_groupchat_init(struct im_connection *ic)666 {667 char *name_hint;668 struct groupchat *gc;669 struct twitter_data *td = ic->proto_data;670 GSList *l;671 672 td->timeline_gc = gc = imcb_chat_new(ic, "twitter/timeline");673 674 name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user);675 imcb_chat_name_hint(gc, name_hint);676 g_free(name_hint);677 678 for (l = ic->bee->users; l; l = l->next) {679 bee_user_t *bu = l->data;680 if (bu->ic == ic)681 imcb_chat_add_buddy(td->timeline_gc, bu->handle);682 }683 }684 685 657 /** 686 658 * Function that is called to see the statuses in a groupchat window. … … 695 667 696 668 // Create a new groupchat if it does not exsist. 697 if (!td->timeline_gc) 698 twitter_groupchat_init(ic); 699 700 gc = td->timeline_gc; 701 if (!gc->joined) 702 imcb_chat_add_buddy(gc, ic->acc->user); 669 gc = twitter_groupchat_init(ic); 703 670 704 671 for (l = list; l; l = g_slist_next(l)) { … … 744 711 GSList *l = NULL; 745 712 struct twitter_xml_status *status; 746 char from[MAX_STRING]; 747 gboolean mode_one; 713 char from[MAX_STRING] = ""; 748 714 guint64 last_id = 0; 749 715 750 mode_one = g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "one") == 0; 751 752 if (mode_one) { 716 if (td->flags & TWITTER_MODE_ONE) { 753 717 g_snprintf(from, sizeof(from) - 1, "%s_%s", td->prefix, ic->acc->user); 754 718 from[MAX_STRING - 1] = '\0'; … … 765 729 766 730 strip_html(status->text); 767 if ( mode_one)731 if (td->flags & TWITTER_MODE_ONE) 768 732 prefix = g_strdup_printf("\002<\002%s\002>\002 ", 769 733 status->user->screen_name); 770 734 else 771 735 twitter_add_buddy(ic, status->user->screen_name, status->user->name); … … 774 738 775 739 imcb_buddy_msg(ic, 776 mode_one? from : status->user->screen_name,777 740 *from ? from : status->user->screen_name, 741 text ? text : status->text, 0, status->created_at); 778 742 779 743 // Update the timeline_id to hold the highest id, so that by the next request … … 1017 981 1018 982 // See if the user wants to see the messages in a groupchat window or as private messages. 1019 if ( g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "chat") == 0)983 if (td->flags & TWITTER_MODE_CHAT) 1020 984 twitter_groupchat(ic, output); 1021 985 else
Note: See TracChangeset
for help on using the changeset viewer.