Changeset 8c3637b


Ignore:
Timestamp:
2015-05-24T19:43:09Z (5 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
a852b2b
Parents:
93e0901
Message:

imcb_get_local_contacts() so an IM plugin can request the local contact list
before finishing login. Makes sense since processing the contact list can be
a major part of the login process.

Location:
protocols
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    r93e0901 r8c3637b  
    312312        }
    313313
    314         if (ic->acc->flags & ACC_FLAG_LOCAL_CONTACTS) {
     314        if ((ic->acc->flags & ACC_FLAG_LOCAL_CONTACTS) &&
     315            !(ic->flags & OPT_LOCAL_CONTACTS_SENT)) {
    315316                GHashTableIter nicks;
    316                 gpointer k, v;
     317                gpointer handle;
    317318                g_hash_table_iter_init(&nicks, ic->acc->nicks);
    318                 while (g_hash_table_iter_next(&nicks, &k, &v)) {
    319                         ic->acc->prpl->add_buddy(ic, (char *) k, NULL);
     319                while (g_hash_table_iter_next(&nicks, &handle, NULL)) {
     320                        ic->acc->prpl->add_buddy(ic, (char *) handle, NULL);
    320321                }
    321322        }
     
    495496                bee->ui->user_nick_hint(bee, bu, nick);
    496497        }
     498}
     499
     500/* Returns the local contacts for an IM account (based on assigned nicks).
     501   Linked list should be freed, the strings themselves not! So look at it
     502   like a GSList<const char*> I guess? Empty list means NULL retval (as
     503   always with GSList). */
     504GSList *imcb_get_local_contacts(struct im_connection *ic)
     505{
     506        GHashTableIter nicks;
     507        GSList *ret = NULL;
     508       
     509        g_hash_table_iter_init(&nicks, ic->acc->nicks);
     510        gpointer handle;
     511        while (g_hash_table_iter_next(&nicks, &handle, NULL)) {
     512                ret = g_slist_prepend(ret, (char *) handle);
     513        }
     514       
     515        /* If the protocol asked for the list, assume we won't have to send it
     516           anymore in imcb_connected(). */
     517        ic->flags |= OPT_LOCAL_CONTACTS_SENT;
     518       
     519        return ret;
    497520}
    498521
  • protocols/nogaim.h

    r93e0901 r8c3637b  
    5757
    5858/* Sharing flags between all kinds of things. I just hope I won't hit any
    59    limits before 32-bit machines become extinct. ;-) */
     59   limits before 32-bit machines become extinct. ;-)
     60   
     61   Argh! This needs to be renamed to be more clear which field they're used
     62   for. As said it's currently mixed which is nonsense. Some are for the
     63   im_connection flags field, some for imcb_buddy_status(), some for typing
     64   notifications, and who knows what else... */
    6065#define OPT_LOGGED_IN   0x00000001
    6166#define OPT_LOGGING_OUT 0x00000002
     
    7075#define OPT_PONGS       0x00010000 /* Service sends us keep-alives */
    7176#define OPT_PONGED      0x00020000 /* Received a keep-alive during last interval */
     77#define OPT_LOCAL_CONTACTS_SENT 0x00040000 /* Protocol already requested local contact list, so don't send it after finishing login. */
    7278
    7379/* ok. now the fun begins. first we create a connection structure */
     
    324330G_MODULE_EXPORT void imcb_buddy_nick_hint(struct im_connection *ic, const char *handle, const char *nick);
    325331G_MODULE_EXPORT void imcb_buddy_action_response(bee_user_t *bu, const char *action, char * const args[], void *data);
     332G_MODULE_EXPORT GSList *imcb_get_local_contacts(struct im_connection *ic);
    326333
    327334G_MODULE_EXPORT void imcb_buddy_typing(struct im_connection *ic, const char *handle, uint32_t flags);
  • protocols/rpc/rpc.c

    r93e0901 r8c3637b  
    605605}
    606606
     607static JSON_Value *rpc_imcb_get_local_contacts(struct im_connection *ic, void *func_, JSON_Array *params) {
     608        JSON_Value *resp = json_value_init_object();
     609        JSON_Value *arr = json_value_init_array();
     610        GSList *contacts = imcb_get_local_contacts(ic);
     611        GSList *c;
     612        for (c = contacts; c; c = c->next) {
     613                json_array_append_string(json_array(arr), (const char*) c->data);
     614        }
     615        g_slist_free(contacts);
     616        json_object_set_value(json_object(resp), "result", arr);
     617        return resp;
     618}
     619
    607620static JSON_Value *rpc_imcb_chat_new(struct im_connection *ic, void *func_, JSON_Array *params) {
    608621        struct rpc_groupchat *rc = rpc_groupchat_new(ic, json_array_get_string(params, 0));
     
    719732        { "imcb_buddy_msg", imcb_buddy_msg, rpc_imcb_buddy_msg, "ssii" },
    720733        { "imcb_buddy_typing", imcb_buddy_typing, rpc_imcb_buddy_typing, "si" },
     734        { "imcb_get_local_contacts", NULL, rpc_imcb_get_local_contacts, "" },
    721735        { "imcb_chat_new", NULL, rpc_imcb_chat_new, "s" },
    722736       
Note: See TracChangeset for help on using the changeset viewer.