diff options
author | dequis <dx@dxzone.com.ar> | 2017-01-07 23:50:10 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2017-01-08 00:02:30 -0300 |
commit | 82e6bcf0e6f22eeca7eda7ea95aaf8378df6ddef (patch) | |
tree | 9aa5d95e11573d4a568a8cc44ab64a6240297000 /facebook/facebook.c | |
parent | e5e8c89a313637778ac730533c2d6b9c9254da75 (diff) | |
download | bitlbee-facebook-82e6bcf0e6f22eeca7eda7ea95aaf8378df6ddef.tar.gz bitlbee-facebook-82e6bcf0e6f22eeca7eda7ea95aaf8378df6ddef.tar.bz2 bitlbee-facebook-82e6bcf0e6f22eeca7eda7ea95aaf8378df6ddef.tar.xz |
Use FetchContactsDeltaQuery for contact sync
This has a number of benefits:
- Most of the time the contact sync reply will be empty
- We can do contact sync more frequently (It's 5 mins now, was 30)
- Figuring out what contacts were added or removed is much simpler and
less likely to get things wrong.
- Non-friends are no longer accidentally removed because there's no need
to compare contact lists
- On accounts with lots of friends this gets rid of one source of CPU
usage spikes
- Less load for facebook's servers (lol)
Diffstat (limited to 'facebook/facebook.c')
-rw-r--r-- | facebook/facebook.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/facebook/facebook.c b/facebook/facebook.c index 8c7d926..29a67e9 100644 --- a/facebook/facebook.c +++ b/facebook/facebook.c @@ -207,9 +207,9 @@ fb_sync_contacts_add_timeout(FbData *fata) sync = set_getint(&acct->set, "sync_interval"); - if (sync < 5) { - set_setint(&acct->set, "sync_interval", 5); - sync = 5; + if (sync < 1) { + set_setint(&acct->set, "sync_interval", 1); + sync = 1; } sync *= 60 * 1000; @@ -220,7 +220,6 @@ fb_sync_contacts_add_timeout(FbData *fata) static void fb_cb_api_contacts(FbApi *api, GSList *users, gboolean complete, gpointer data) { - bee_user_t *bu; FbApiUser *user; FbData *fata = data; FbId muid; @@ -247,35 +246,47 @@ fb_cb_api_contacts(FbApi *api, GSList *users, gboolean complete, gpointer data) imcb_add_buddy(ic, uid, NULL); imcb_buddy_nick_hint(ic, uid, user->name); imcb_rename_buddy(ic, uid, user->name); - - bu = imcb_buddy_by_handle(ic, uid); - FB_UTIL_PTRBIT_SET(bu->data, FB_PTRBIT_NEW_BUDDY, TRUE); } if (!complete) { return; } - l = ic->bee->users; + if (!(ic->flags & OPT_LOGGED_IN)) { + imcb_log(ic, "Connecting"); + fb_api_connect(api, FALSE); + } - while (l != NULL) { - bu = l->data; - l = l->next; + fb_sync_contacts_add_timeout(fata); +} - if (bu->ic != ic) { - continue; - } +static void +fb_cb_api_contacts_delta(FbApi *api, GSList *added, GSList *removed, gpointer data) +{ + bee_user_t *bu; + FbApiUser *user; + FbData *fata = data; + gchar uid[FB_ID_STRMAX]; + GSList *l; + struct im_connection *ic; - if (FB_UTIL_PTRBIT_GET(bu->data, FB_PTRBIT_NEW_BUDDY)) { - FB_UTIL_PTRBIT_SET(bu->data, FB_PTRBIT_NEW_BUDDY, FALSE); - } else { - imcb_remove_buddy(ic, bu->handle, NULL); - } + ic = fb_data_get_connection(fata); + + for (l = added; l != NULL; l = l->next) { + user = l->data; + FB_ID_TO_STR(user->uid, uid); + + imcb_add_buddy(ic, uid, NULL); + imcb_buddy_nick_hint(ic, uid, user->name); + imcb_rename_buddy(ic, uid, user->name); } - if (!(ic->flags & OPT_LOGGED_IN)) { - imcb_log(ic, "Connecting"); - fb_api_connect(api, FALSE); + for (l = removed; l != NULL; l = l->next) { + bu = imcb_buddy_by_handle(ic, l->data); + + if (bu) { + imcb_remove_buddy(ic, bu->handle, NULL); + } } fb_sync_contacts_add_timeout(fata); @@ -722,7 +733,7 @@ fb_init(account_t *acct) set_add(&acct->set, "mark_read", "false", fb_eval_mark_read, acct); set_add(&acct->set, "mark_read_reply", "false", set_eval_bool, acct); set_add(&acct->set, "show_unread", "false", set_eval_bool, acct); - set_add(&acct->set, "sync_interval", "30", set_eval_int, acct); + set_add(&acct->set, "sync_interval", "5", set_eval_int, acct); } static void @@ -754,6 +765,10 @@ fb_login(account_t *acc) G_CALLBACK(fb_cb_api_contacts), fata); g_signal_connect(api, + "contacts-delta", + G_CALLBACK(fb_cb_api_contacts_delta), + fata); + g_signal_connect(api, "error", G_CALLBACK(fb_cb_api_error), fata); |