/soc/2015/jgeboski/facebook: 3953bf31338c: facebook: only attemp...
James Geboski
jgeboski at gmail.com
Sat Aug 8 23:07:03 EDT 2015
Changeset: 3953bf31338cc2589dfff65043b7eeedb0cabca5
Author: James Geboski <jgeboski at gmail.com>
Date: 2015-08-08 23:06 -0400
Branch: facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/3953bf31338c
Description:
facebook: only attempt to fetch more contacts if needed
diffstat:
libpurple/protocols/facebook/api.c | 15 ++++++++++-----
libpurple/protocols/facebook/api.h | 2 +-
2 files changed, 11 insertions(+), 6 deletions(-)
diffs (70 lines):
diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
--- a/libpurple/protocols/facebook/api.c
+++ b/libpurple/protocols/facebook/api.c
@@ -1447,10 +1447,12 @@ fb_api_cb_contacts(PurpleHttpConnection
FbApiUser user;
FbHttpParams *params;
FbJsonValues *values;
+ gboolean complete;
gchar *writeid = NULL;
GError *err = NULL;
gpointer mptr;
GSList *users = NULL;
+ guint count = 0;
JsonNode *root;
if (!fb_api_http_chk(api, con, res, &root)) {
@@ -1473,6 +1475,7 @@ fb_api_cb_contacts(PurpleHttpConnection
fb_api_user_reset(&user, FALSE);
str = fb_json_values_next_str(values, NULL);
user.uid = FB_ID_FROM_STR(str);
+ count++;
g_free(writeid);
writeid = fb_json_values_next_str_dup(values, NULL);
@@ -1496,10 +1499,12 @@ fb_api_cb_contacts(PurpleHttpConnection
users = g_slist_prepend(users, mptr);
}
+ complete = (writeid == NULL) || (count < FB_API_CONTACTS_COUNT);
+
if (G_UNLIKELY(err == NULL)) {
- g_signal_emit_by_name(api, "contacts", users, writeid == NULL);
-
- if (writeid != NULL) {
+ g_signal_emit_by_name(api, "contacts", users, complete);
+
+ if (!complete) {
fb_api_contacts_after(api, writeid);
}
} else {
@@ -1539,7 +1544,7 @@ fb_api_contacts(FbApi *api)
fb_json_bldr_add_str(bldr, NULL, "user");
fb_json_bldr_arr_end(bldr);
- fb_json_bldr_add_str(bldr, "1", FB_API_CONTACTS_COUNT);
+ fb_json_bldr_add_str(bldr, "1", G_STRINGIFY(FB_API_CONTACTS_COUNT));
fb_api_http_graph(api, &info, bldr, FB_API_QRYID_CONTACTS);
}
@@ -1576,7 +1581,7 @@ fb_api_contacts_after(FbApi *api, const
fb_json_bldr_arr_end(bldr);
fb_json_bldr_add_str(bldr, "1", writeid);
- fb_json_bldr_add_str(bldr, "2", FB_API_CONTACTS_COUNT);
+ fb_json_bldr_add_str(bldr, "2", G_STRINGIFY(FB_API_CONTACTS_COUNT));
fb_api_http_graph(api, &info, bldr, FB_API_QRYID_CONTACTS_AFTER);
}
diff --git a/libpurple/protocols/facebook/api.h b/libpurple/protocols/facebook/api.h
--- a/libpurple/protocols/facebook/api.h
+++ b/libpurple/protocols/facebook/api.h
@@ -40,7 +40,7 @@
#define FB_API_KEY "256002347743983"
#define FB_API_SECRET "374e60f8b9bb6b8cbb30f78030438895"
-#define FB_API_CONTACTS_COUNT "200"
+#define FB_API_CONTACTS_COUNT 200
#define FB_API_URL_AUTH FB_API_BHOST "/method/auth.login"
#define FB_API_URL_GQL FB_API_GHOST "/graphql"
More information about the Commits
mailing list