/pidgin/main: 643d7b0aadbd: facebook: preserve the timestamp on ...

James Geboski jgeboski at gmail.com
Sat Dec 26 18:01:09 EST 2015


Changeset: 643d7b0aadbdd1ae27a8daee1e65ba93a3d2abda
Author:	 James Geboski <jgeboski at gmail.com>
Date:	 2015-12-26 18:01 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/643d7b0aadbd

Description:

facebook: preserve the timestamp on incoming messages

diffstat:

 libpurple/protocols/facebook/api.c      |  8 ++++++++
 libpurple/protocols/facebook/api.h      |  2 ++
 libpurple/protocols/facebook/facebook.c |  6 ++++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diffs (95 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
@@ -1441,6 +1441,8 @@ fb_api_cb_publish_ms(FbApi *api, GByteAr
 	fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE,
 	                   "$.deltaNewMessage.messageMetadata"
 	                    ".threadKey.threadFbId");
+	fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE,
+	                   "$.deltaNewMessage.messageMetadata.timestamp");
 	fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE,
 	                   "$.deltaNewMessage.body");
 	fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE,
@@ -1460,6 +1462,7 @@ fb_api_cb_publish_ms(FbApi *api, GByteAr
 		msg.uid = fb_json_values_next_int(values, 0);
 		oid = fb_json_values_next_int(values, 0);
 		msg.tid = fb_json_values_next_int(values, 0);
+		msg.tstamp = fb_json_values_next_int(values, 0);
 
 		if (msg.uid == priv->uid) {
 			msg.flags |= FB_API_MESSAGE_FLAG_SELF;
@@ -2258,6 +2261,8 @@ fb_api_cb_unread_msgs(PurpleHttpConnecti
 	fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE,
 	                   "$.message_sender.messaging_actor.id");
 	fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.message.text");
+	fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE,
+	                   "$.timestamp_precise");
 	fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.sticker.id");
 	fb_json_values_add(values, FB_JSON_TYPE_STR, TRUE, "$.message_id");
 	fb_json_values_set_array(values, FALSE, "$.messages.nodes");
@@ -2274,6 +2279,9 @@ fb_api_cb_unread_msgs(PurpleHttpConnecti
 		msg.uid = FB_ID_FROM_STR(str);
 		msg.tid = tid;
 
+		str = fb_json_values_next_str(values, "0");
+		msg.tstamp = g_ascii_strtoll(str, NULL, 10);
+
 		if (body != NULL) {
 			dmsg = fb_api_message_dup(&msg, FALSE);
 			dmsg->text = g_strdup(body);
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
@@ -335,6 +335,7 @@ struct _FbApiEvent
  * @flags: The #FbApiMessageFlags.
  * @uid: The user #FbId.
  * @tid: The thread #FbId.
+ * @tstamp: The timestamp in milliseconds (UTC).
  * @text: The message text.
  *
  * Represents a Facebook user message.
@@ -344,6 +345,7 @@ struct _FbApiMessage
 	FbApiMessageFlags flags;
 	FbId uid;
 	FbId tid;
+	gint64 tstamp;
 	gchar *text;
 };
 
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
@@ -469,6 +469,7 @@ fb_cb_api_messages(FbApi *api, GSList *m
 	gchar tid[FB_ID_STRMAX];
 	gchar uid[FB_ID_STRMAX];
 	gint id;
+	gint64 tstamp;
 	GSList *l;
 	PurpleAccount *acct;
 	PurpleChatConversation *chat;
@@ -493,6 +494,7 @@ fb_cb_api_messages(FbApi *api, GSList *m
 
 		self = (msg->flags & FB_API_MESSAGE_FLAG_SELF) != 0;
 		flags = self ? PURPLE_MESSAGE_SEND : PURPLE_MESSAGE_RECV;
+		tstamp = msg->tstamp / 1000;
 
 		if (msg->flags & FB_API_MESSAGE_FLAG_IMAGE) {
 			if (!(msg->flags & FB_API_MESSAGE_FLAG_DONE)) {
@@ -517,7 +519,7 @@ fb_cb_api_messages(FbApi *api, GSList *m
 				fb_data_set_unread(fata, msg->uid, TRUE);
 			}
 
-			fb_util_serv_got_im(gc, uid, text, flags, time(NULL));
+			fb_util_serv_got_im(gc, uid, text, flags, tstamp);
 			g_free(html);
 			continue;
 		}
@@ -542,7 +544,7 @@ fb_cb_api_messages(FbApi *api, GSList *m
 			fb_data_set_unread(fata, msg->tid, TRUE);
 		}
 
-		fb_util_serv_got_chat_in(gc, id, uid, text, flags, time(NULL));
+		fb_util_serv_got_chat_in(gc, id, uid, text, flags, tstamp);
 		g_free(html);
 	}
 }



More information about the Commits mailing list