/soc/2015/jgeboski/facebook: c4f2fd45ffba: facebook: refactored ...

James Geboski <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: c4f2fd45ffbaccf2d94e49be111c5b20b35d8fc2
Author:	 James Geboski <[email protected]>
Date:	 2015-08-09 21:52 -0400
Branch:	 facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/c4f2fd45ffba

Description:

facebook: refactored internal API naming

This removes class names from HTTP requests, they are not needed.

diffstat:

 libpurple/protocols/facebook/api.c      |  418 ++++++++++++++-----------------
 libpurple/protocols/facebook/api.h      |   34 +-
 libpurple/protocols/facebook/facebook.c |   68 ++--
 3 files changed, 230 insertions(+), 290 deletions(-)

diffs (truncated from 884 to 300 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
@@ -240,7 +240,7 @@ fb_api_class_init(FbApiClass *klass)
 	             fb_marshal_VOID__OBJECT,
 	             G_TYPE_NONE,
 	             1, G_TYPE_ERROR);
-	g_signal_new("message",
+	g_signal_new("messages",
 	             G_TYPE_FROM_CLASS(klass),
 	             G_SIGNAL_ACTION,
 	             0,
@@ -248,7 +248,15 @@ fb_api_class_init(FbApiClass *klass)
 	             fb_marshal_VOID__POINTER,
 	             G_TYPE_NONE,
 	             1, G_TYPE_POINTER);
-	g_signal_new("presence",
+	g_signal_new("presences",
+	             G_TYPE_FROM_CLASS(klass),
+	             G_SIGNAL_ACTION,
+	             0,
+	             NULL, NULL,
+	             fb_marshal_VOID__POINTER,
+	             G_TYPE_NONE,
+	             1, G_TYPE_POINTER);
+	g_signal_new("thread",
 	             G_TYPE_FROM_CLASS(klass),
 	             G_SIGNAL_ACTION,
 	             0,
@@ -264,15 +272,7 @@ fb_api_class_init(FbApiClass *klass)
 	             fb_marshal_VOID__INT64,
 	             G_TYPE_NONE,
 	             1, FB_TYPE_ID);
-	g_signal_new("thread-info",
-	             G_TYPE_FROM_CLASS(klass),
-	             G_SIGNAL_ACTION,
-	             0,
-	             NULL, NULL,
-	             fb_marshal_VOID__POINTER,
-	             G_TYPE_NONE,
-	             1, G_TYPE_POINTER);
-	g_signal_new("thread-list",
+	g_signal_new("threads",
 	             G_TYPE_FROM_CLASS(klass),
 	             G_SIGNAL_ACTION,
 	             0,
@@ -464,8 +464,9 @@ fb_api_http_chk(FbApi *api, PurpleHttpCo
 }
 
 static PurpleHttpConnection *
-fb_api_http_req(FbApi *api, const FbApiHttpInfo *info,
-                FbHttpParams *params, const gchar *url)
+fb_api_http_req(FbApi *api, const gchar *url, const gchar *name,
+                const gchar *method, FbHttpParams *params,
+		PurpleHttpCallback callback)
 {
 	FbApiPrivate *priv = api->priv;
 	gchar *data;
@@ -479,10 +480,9 @@ fb_api_http_req(FbApi *api, const FbApiH
 
 	fb_http_params_set_str(params, "api_key", FB_API_KEY);
 	fb_http_params_set_str(params, "device_id", priv->did);
-	fb_http_params_set_str(params, "fb_api_caller_class", info->klass);
-	fb_http_params_set_str(params, "fb_api_req_friendly_name", info->name);
+	fb_http_params_set_str(params, "fb_api_req_friendly_name", name);
 	fb_http_params_set_str(params, "format", "json");
-	fb_http_params_set_str(params, "method", info->method);
+	fb_http_params_set_str(params, "method", method);
 
 	val = fb_util_locale_str();
 	fb_http_params_set_str(params, "locale", val);
@@ -521,7 +521,7 @@ fb_api_http_req(FbApi *api, const FbApiH
 
 	data = fb_http_params_close(params, NULL);
 	purple_http_request_set_contents(req, data, -1);
-	ret = purple_http_request(priv->gc, req, info->callback, api);
+	ret = purple_http_request(priv->gc, req, callback, api);
 	purple_http_request_unref(req);
 
 	fb_util_debug(FB_UTIL_DEBUG_INFO, "HTTP Request (%p):", ret);
@@ -533,18 +533,40 @@ fb_api_http_req(FbApi *api, const FbApiH
 }
 
 static void
-fb_api_http_graph(FbApi *api, const FbApiHttpInfo *info, JsonBuilder *builder,
-                  const gchar *qid)
+fb_api_http_query(FbApi *api, gint64 query, JsonBuilder *builder,
+                  PurpleHttpCallback callback)
 {
+	const gchar *name;
 	FbHttpParams *prms;
 	gchar *json;
 
+	switch (query) {
+	case FB_API_QUERY_CONTACTS:
+		name = "FetchContactsFullQuery";
+		break;
+	case FB_API_QUERY_CONTACTS_AFTER:
+		name = "FetchContactsFullWithAfterQuery";
+		break;
+	case FB_API_QUERY_THREAD:
+		name = "ThreadQuery";
+		break;
+	case FB_API_QUERY_THREADS:
+		name = "ThreadListQuery";
+		break;
+	case FB_API_QUERY_XMA:
+		name = "XMAQuery";
+		break;
+	default:
+		g_return_if_reached();
+		return;
+	}
+
 	prms = fb_http_params_new();
 	json = fb_json_bldr_close(builder, JSON_NODE_OBJECT, NULL);
 
-	fb_http_params_set_str(prms, "query_id", qid);
+	fb_http_params_set_strf(prms, "query_id", "%" G_GINT64_FORMAT, query);
 	fb_http_params_set_str(prms, "query_params", json);
-	fb_api_http_req(api, info, prms, FB_API_URL_GQL);
+	fb_api_http_req(api, FB_API_URL_GQL, name, "get", prms, callback);
 
 	g_free(json);
 }
@@ -701,11 +723,12 @@ fb_api_connect_queue(FbApi *api)
 		fb_json_bldr_add_str(bldr, "buzz_on_deltas_enabled", "false");
 
 		fb_json_bldr_obj_begin(bldr, "graphql_query_hashes");
-		fb_json_bldr_add_str(bldr, "xma_query_id", FB_API_QRYID_XMA);
+		fb_json_bldr_add_str(bldr, "xma_query_id",
+		                     G_STRINGIFY(FB_API_QUERY_XMA));
 		fb_json_bldr_obj_end(bldr);
 
 		fb_json_bldr_obj_begin(bldr, "graphql_query_params");
-		fb_json_bldr_obj_begin(bldr, FB_API_QRYID_XMA);
+		fb_json_bldr_obj_begin(bldr, G_STRINGIFY(FB_API_QUERY_XMA));
 		fb_json_bldr_add_str(bldr, "xma_id", "<ID>");
 		fb_json_bldr_add_str(bldr, "small_preview_size", "9001");
 		fb_json_bldr_add_str(bldr, "large_preview_size", "9001");
@@ -775,13 +798,6 @@ fb_api_cb_mqtt_connect(FbMqtt *mqtt, gpo
 	gchar *json;
 	JsonBuilder *bldr;
 
-	static const FbApiHttpInfo info = {
-		fb_api_cb_seqid,
-		"com.facebook.orca.e.y",
-		"ThreadListQuery",
-		"get"
-	};
-
 	bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
 	fb_json_bldr_add_bool(bldr, "foreground", TRUE);
 	fb_json_bldr_add_int(bldr, "keepalive_timeout", FB_MQTT_KA);
@@ -812,7 +828,8 @@ fb_api_cb_mqtt_connect(FbMqtt *mqtt, gpo
 		/* See fb_api_thread_list() for key mapping */
 		bldr = fb_json_bldr_new(JSON_NODE_OBJECT);
 		fb_json_bldr_add_str(bldr, "1", "0");
-		fb_api_http_graph(api, &info, bldr, FB_API_QRYID_THREAD_LIST);
+		fb_api_http_query(api, FB_API_QUERY_THREADS, bldr,
+		                  fb_api_cb_seqid);
 	} else {
 		fb_api_connect_queue(api);
 	}
@@ -1146,7 +1163,7 @@ fb_api_cb_publish_ms(FbApi *api, GByteAr
 
 	if (G_LIKELY(err == NULL)) {
 		msgs = g_slist_reverse(msgs);
-		g_signal_emit_by_name(api, "message", msgs);
+		g_signal_emit_by_name(api, "messages", msgs);
 	} else {
 		fb_api_error_emit(api, err);
 	}
@@ -1238,7 +1255,7 @@ fb_api_cb_publish_p(FbApi *api, GByteArr
 	g_object_unref(thft);
 
 	press = g_slist_reverse(press);
-	g_signal_emit_by_name(api, "presence", press);
+	g_signal_emit_by_name(api, "presences", press);
 	g_slist_free_full(press, (GDestroyNotify) fb_api_presence_free);
 }
 
@@ -1424,17 +1441,11 @@ fb_api_auth(FbApi *api, const gchar *use
 {
 	FbHttpParams *prms;
 
-	static const FbApiHttpInfo info = {
-		fb_api_cb_auth,
-		"com.facebook.auth.protocol.d",
-		"authenticate",
-		"auth.login"
-	};
-
 	prms = fb_http_params_new();
 	fb_http_params_set_str(prms, "email", user);
 	fb_http_params_set_str(prms, "password", pass);
-	fb_api_http_req(api, &info, prms, FB_API_URL_AUTH);
+	fb_api_http_req(api, FB_API_URL_AUTH, "authenticate", "auth.login",
+	                prms, fb_api_cb_auth);
 }
 
 static void
@@ -1522,13 +1533,6 @@ fb_api_contacts(FbApi *api)
 {
 	JsonBuilder *bldr;
 
-	static const FbApiHttpInfo info = {
-		fb_api_cb_contacts,
-		"com.facebook.contacts.service.c",
-		"FetchContactsFullQuery",
-		"get"
-	};
-
 	/* Object key mapping:
 	 *   0: profile_types
 	 *   1: limit
@@ -1545,7 +1549,8 @@ fb_api_contacts(FbApi *api)
 	fb_json_bldr_arr_end(bldr);
 
 	fb_json_bldr_add_str(bldr, "1", G_STRINGIFY(FB_API_CONTACTS_COUNT));
-	fb_api_http_graph(api, &info, bldr, FB_API_QRYID_CONTACTS);
+	fb_api_http_query(api, FB_API_QUERY_CONTACTS, bldr,
+	                  fb_api_cb_contacts);
 }
 
 static void
@@ -1553,13 +1558,6 @@ fb_api_contacts_after(FbApi *api, const 
 {
 	JsonBuilder *bldr;
 
-	static const FbApiHttpInfo info = {
-		fb_api_cb_contacts,
-		"com.facebook.contacts.service.c",
-		"FetchContactsFullWithAfterQuery",
-		"get"
-	};
-
 	/* Object key mapping:
 	 *   0: profile_types
 	 *   1: after
@@ -1582,7 +1580,8 @@ fb_api_contacts_after(FbApi *api, const 
 
 	fb_json_bldr_add_str(bldr, "1", writeid);
 	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);
+	fb_api_http_query(api, FB_API_QUERY_CONTACTS_AFTER, bldr,
+	                  fb_api_cb_contacts);
 }
 
 void
@@ -1848,7 +1847,7 @@ fb_api_cb_unread_msgs(PurpleHttpConnecti
 
 	if (G_UNLIKELY(err == NULL)) {
 		msgs = g_slist_reverse(msgs);
-		g_signal_emit_by_name(api, "message", msgs);
+		g_signal_emit_by_name(api, "messages", msgs);
 	} else {
 		fb_api_error_emit(api, err);
 	}
@@ -1870,13 +1869,6 @@ fb_api_cb_unread(PurpleHttpConnection *c
 	JsonBuilder *bldr;
 	JsonNode *root;
 
-	static const FbApiHttpInfo info = {
-		fb_api_cb_unread_msgs,
-		"com.facebook.orca.e.m",
-		"ThreadQuery",
-		"get"
-	};
-
 	if (!fb_api_http_chk(api, con, res, &root)) {
 		return;
 	}
@@ -1911,7 +1903,8 @@ fb_api_cb_unread(PurpleHttpConnection *c
 		fb_json_bldr_add_str(bldr, "11", "true");
 		fb_json_bldr_add_int(bldr, "12", count);
 		fb_json_bldr_add_str(bldr, "13", "false");
-		fb_api_http_graph(api, &info, bldr, FB_API_QRYID_THREAD_INFO);
+		fb_api_http_query(api, FB_API_QUERY_THREAD, bldr,
+		                  fb_api_cb_unread_msgs);
 	}
 
 	if (G_UNLIKELY(err != NULL)) {
@@ -1928,13 +1921,6 @@ fb_api_unread(FbApi *api)
 	FbApiPrivate *priv;
 	JsonBuilder *bldr;
 
-	static const FbApiHttpInfo info = {
-		fb_api_cb_unread,
-		"com.facebook.orca.e.y",
-		"ThreadListQuery",
-		"get"
-	};
-
 	g_return_if_fail(FB_IS_API(api));
 	priv = api->priv;
 
@@ -1948,82 +1934,8 @@ fb_api_unread(FbApi *api)
 	fb_json_bldr_add_int(bldr, "1", priv->unread);
 	fb_json_bldr_add_str(bldr, "12", "true");

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.