/soc/2015/jgeboski/facebook: 06ad6f6aa43a: facebook: implemented...

James Geboski jgeboski at gmail.com
Tue Aug 25 20:06:39 EDT 2015


Changeset: 06ad6f6aa43a606ddb732a41e8f8a9ec06beaf65
Author:	 James Geboski <jgeboski at gmail.com>
Date:	 2015-08-25 16:48 -0400
Branch:	 facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/06ad6f6aa43a

Description:

facebook: implemented group chat topic change events

diffstat:

 libpurple/protocols/facebook/api.c      |  59 +++++++++++++++++++++++++++++---
 libpurple/protocols/facebook/api.h      |  10 ++++-
 libpurple/protocols/facebook/facebook.c |  10 ++--
 3 files changed, 65 insertions(+), 14 deletions(-)

diffs (219 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
@@ -1113,6 +1113,37 @@ fb_api_event_parse(FbApi *api, FbApiEven
 		}
 	};
 
+	values = fb_json_values_new(root);
+	fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE,
+	                   "$.log_message_type");
+	fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.author");
+	fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE,
+	                   "$.log_message_data.name");
+	fb_json_values_update(values, &err);
+
+	if (G_UNLIKELY(err != NULL)) {
+		g_propagate_error(error, err);
+		g_object_unref(values);
+		return events;
+	}
+
+	str = fb_json_values_next_str(values, NULL);
+
+	if (g_strcmp0(str, "log:thread-name") == 0) {
+		str = fb_json_values_next_str(values, "");
+		str = strrchr(str, ':');
+
+		if (str != NULL) {
+			devent = fb_api_event_dup(event, FALSE);
+			devent->type = FB_API_EVENT_TYPE_THREAD_TOPIC;
+			devent->uid = FB_ID_FROM_STR(str + 1);
+			devent->text = fb_json_values_next_str_dup(values, NULL);
+			events = g_slist_prepend(events, devent);
+		}
+	}
+
+	g_object_unref(values);
+
 	for (i = 0; i < G_N_ELEMENTS(evtypes); i++) {
 		values = fb_json_values_new(root);
 		fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$");
@@ -1123,7 +1154,7 @@ fb_api_event_parse(FbApi *api, FbApiEven
 			str = strrchr(str, ':');
 
 			if (str != NULL) {
-				devent = fb_api_event_dup(event);
+				devent = fb_api_event_dup(event, FALSE);
 				devent->type = evtypes[i].type;
 				devent->uid = FB_ID_FROM_STR(str + 1);
 				events = g_slist_prepend(events, devent);
@@ -1142,7 +1173,7 @@ fb_api_event_parse(FbApi *api, FbApiEven
 }
 
 static void
-fb_api_cb_mercury(FbApi *api, GByteArray *pload)
+fb_api_cb_publish_mercury(FbApi *api, GByteArray *pload)
 {
 	const gchar *str;
 	FbApiEvent event;
@@ -1161,7 +1192,7 @@ fb_api_cb_mercury(FbApi *api, GByteArray
 	fb_json_values_set_array(values, FALSE, "$.actions");
 
 	while (fb_json_values_update(values, &err)) {
-		fb_api_event_reset(&event);
+		fb_api_event_reset(&event, FALSE);
 		str = fb_json_values_next_str(values, "0");
 		event.tid = FB_ID_FROM_STR(str);
 
@@ -1569,7 +1600,7 @@ fb_api_cb_mqtt_publish(FbMqtt *mqtt, con
 		void (*func) (FbApi *api, GByteArray *pload);
 	} parsers[] = {
 		{"/mark_thread_response", fb_api_cb_publish_mark},
-		{"/mercury", fb_api_cb_mercury},
+		{"/mercury", fb_api_cb_publish_mercury},
 		{"/orca_typing_notifications", fb_api_cb_publish_typing},
 		{"/t_ms", fb_api_cb_publish_ms},
 		{"/t_p", fb_api_cb_publish_p}
@@ -2851,19 +2882,32 @@ fb_api_typing(FbApi *api, FbId uid, gboo
 }
 
 FbApiEvent *
-fb_api_event_dup(const FbApiEvent *event)
+fb_api_event_dup(const FbApiEvent *event, gboolean deep)
 {
+	FbApiEvent *ret;
+
 	if (event == NULL) {
 		return g_new0(FbApiEvent, 1);
 	}
 
-	return g_memdup(event, sizeof *event);
+	ret = g_memdup(event, sizeof *event);
+
+	if (deep) {
+		ret->text = g_strdup(event->text);
+	}
+
+	return ret;
 }
 
 void
-fb_api_event_reset(FbApiEvent *event)
+fb_api_event_reset(FbApiEvent *event, gboolean deep)
 {
 	g_return_if_fail(event != NULL);
+
+	if (deep) {
+		g_free(event->text);
+	}
+
 	memset(event, 0, sizeof *event);
 }
 
@@ -2871,6 +2915,7 @@ void
 fb_api_event_free(FbApiEvent *event)
 {
 	if (G_LIKELY(event != NULL)) {
+		g_free(event->text);
 		g_free(event);
 	}
 }
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
@@ -262,6 +262,7 @@ typedef enum
 
 /**
  * FbApiEventType:
+ * @FB_API_EVENT_TYPE_THREAD_TOPIC: The thread topic was changed.
  * @FB_API_EVENT_TYPE_THREAD_USER_ADDED: A thread user was added.
  * @FB_API_EVENT_TYPE_THREAD_USER_REMOVED: A thread user was removed.
  *
@@ -269,6 +270,7 @@ typedef enum
  */
 typedef enum
 {
+	FB_API_EVENT_TYPE_THREAD_TOPIC,
 	FB_API_EVENT_TYPE_THREAD_USER_ADDED,
 	FB_API_EVENT_TYPE_THREAD_USER_REMOVED
 } FbApiEventType;
@@ -316,6 +318,7 @@ struct _FbApiClass
  * @type: The #FbApiEventType.
  * @uid: The user #FbId.
  * @tid: The thread #FbId.
+ * @text: The event text.
  *
  * Represents a Facebook update event.
  */
@@ -324,6 +327,7 @@ struct _FbApiEvent
 	FbApiEventType type;
 	FbId uid;
 	FbId tid;
+	gchar *text;
 };
 
 /**
@@ -651,6 +655,7 @@ fb_api_typing(FbApi *api, FbId uid, gboo
 /**
  * fb_api_event_dup:
  * @event: The #FbApiEvent or #NULL.
+ * @deep: #TRUE to duplicate allocated data, otherwise #FALSE.
  *
  * Duplicates an #FbApiEvent. If @event is #NULL, a new zero filled
  * #FbApiEvent is returned. The returned #FbApiEvent should be freed
@@ -659,16 +664,17 @@ fb_api_typing(FbApi *api, FbId uid, gboo
  * Returns: The new #FbApiEvent.
  */
 FbApiEvent *
-fb_api_event_dup(const FbApiEvent *event);
+fb_api_event_dup(const FbApiEvent *event, gboolean deep);
 
 /**
  * fb_api_event_reset:
  * @event: The #FbApiEvent.
+ * @deep: #TRUE to free allocated data, otherwise #FALSE.
  *
  * Resets an #FbApiEvent.
  */
 void
-fb_api_event_reset(FbApiEvent *event);
+fb_api_event_reset(FbApiEvent *event, gboolean deep);
 
 /**
  * fb_api_event_free:
diff --git a/libpurple/protocols/facebook/facebook.c b/libpurple/protocols/facebook/facebook.c
--- a/libpurple/protocols/facebook/facebook.c
+++ b/libpurple/protocols/facebook/facebook.c
@@ -386,6 +386,11 @@ fb_cb_api_events(FbApi *api, GSList *eve
 		FB_ID_TO_STR(event->uid, uid);
 
 		switch (event->type) {
+		case FB_API_EVENT_TYPE_THREAD_TOPIC:
+			purple_chat_conversation_set_topic(chat, uid,
+			                                   event->text);
+			break;
+
 		case FB_API_EVENT_TYPE_THREAD_USER_ADDED:
 			if (purple_blist_find_buddy(acct, uid) == NULL) {
 				g_hash_table_insert(fetch, &event->tid, event);
@@ -1247,19 +1252,14 @@ fb_chat_set_topic(PurpleConnection *gc, 
 	FbApi *api;
 	FbData *fata;
 	FbId tid;
-	PurpleAccount *acct;
 	PurpleChatConversation *chat;
 
-	acct = purple_connection_get_account(gc);
 	fata = purple_connection_get_protocol_data(gc);
 	api = fb_data_get_api(fata);
 	chat = purple_conversations_find_chat(gc, id);
 
 	name = purple_conversation_get_name(PURPLE_CONVERSATION(chat));
 	tid = FB_ID_FROM_STR(name);
-
-	name = purple_account_get_username(acct);
-	purple_chat_conversation_set_topic(chat, name, topic);
 	fb_api_thread_topic(api, tid, topic);
 }
 



More information about the Commits mailing list