Changeset 631ec80


Ignore:
Timestamp:
2012-11-25T14:26:23Z (11 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
7f557d5
Parents:
96dd574
Message:

Changed mode/room management a little bit.

Location:
protocols/twitter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    r96dd574 r631ec80  
    5353        struct twitter_data *td = ic->proto_data;
    5454
     55        /* Create the room now that we "logged in". */
     56        if (td->flags & TWITTER_MODE_CHAT)
     57                twitter_groupchat_init(ic);
     58
    5559        imcb_log(ic, "Getting initial statuses");
    5660
     
    7680}
    7781
     82struct 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
    78108static void twitter_oauth_start(struct im_connection *ic);
    79109
     
    86116        if (set_getbool(&ic->acc->set, "oauth") && !td->oauth_info)
    87117                twitter_oauth_start(ic);
    88         else if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "one") != 0 &&
    89                 !(td->flags & TWITTER_HAVE_FRIENDS)) {
     118        else if ((td->flags & TWITTER_MODE_ONE) &&
     119                !(td->flags & TWITTER_HAVE_FRIENDS)) {
    90120                imcb_log(ic, "Getting contact list");
    91121                twitter_get_friends_ids(ic, -1);
     
    354384        td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH);
    355385        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;
    356394
    357395        twitter_login_finish(ic);
  • protocols/twitter/twitter.h

    r96dd574 r631ec80  
    105105
    106106void twitter_log(struct im_connection *ic, char *format, ... );
     107struct groupchat *twitter_groupchat_init(struct im_connection *ic);
    107108
    108109#endif //_TWITTER_H
  • protocols/twitter/twitter_lib.c

    r96dd574 r631ec80  
    7070};
    7171
    72 static void twitter_groupchat_init(struct im_connection *ic);
    73 
    7472/**
    7573 * Frees a twitter_xml_user struct.
     
    148146        // Check if the buddy is already in the buddy list.
    149147        if (!bee_user_by_handle(ic->bee, ic, name)) {
    150                 char *mode = set_getstr(&ic->acc->set, "mode");
    151 
    152148                // The buddy is not in the list, add the buddy and set the status to logged in.
    153149                imcb_add_buddy(ic, name, NULL);
    154150                imcb_rename_buddy(ic, name, fullname);
    155                 if (g_strcasecmp(mode, "chat") == 0) {
     151                if (td->flags & TWITTER_MODE_CHAT) {
    156152                        /* Necessary so that nicks always get translated to the
    157153                           exact Twitter username. */
    158154                        imcb_buddy_nick_hint(ic, name, name);
    159155                        imcb_chat_add_buddy(td->timeline_gc, name);
    160                 } else if (g_strcasecmp(mode, "many") == 0)
     156                } else if (td->flags & TWITTER_MODE_MANY)
    161157                        imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL);
    162158        }
     
    305301
    306302        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);
    311303
    312304        txl = g_new0(struct twitter_xml_list, 1);
     
    663655}
    664656
    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 
    685657/**
    686658 * Function that is called to see the statuses in a groupchat window.
     
    695667
    696668        // 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);
    703670
    704671        for (l = list; l; l = g_slist_next(l)) {
     
    744711        GSList *l = NULL;
    745712        struct twitter_xml_status *status;
    746         char from[MAX_STRING];
    747         gboolean mode_one;
     713        char from[MAX_STRING] = "";
    748714        guint64 last_id = 0;
    749715
    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) {
    753717                g_snprintf(from, sizeof(from) - 1, "%s_%s", td->prefix, ic->acc->user);
    754718                from[MAX_STRING - 1] = '\0';
     
    765729
    766730                strip_html(status->text);
    767                 if (mode_one)
     731                if (td->flags & TWITTER_MODE_ONE)
    768732                        prefix = g_strdup_printf("\002<\002%s\002>\002 ",
    769                                                 status->user->screen_name);
     733                                                status->user->screen_name);
    770734                else
    771735                        twitter_add_buddy(ic, status->user->screen_name, status->user->name);
     
    774738
    775739                imcb_buddy_msg(ic,
    776                                mode_one ? from : status->user->screen_name,
    777                                text ? text : status->text, 0, status->created_at);
     740                               *from ? from : status->user->screen_name,
     741                               text ? text : status->text, 0, status->created_at);
    778742
    779743                // Update the timeline_id to hold the highest id, so that by the next request
     
    1017981
    1018982        // 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)
    1020984                twitter_groupchat(ic, output);
    1021985        else
Note: See TracChangeset for help on using the changeset viewer.