From 1952710b5c31c9e6a4c5f2e431e75db9ca5f9f0d Mon Sep 17 00:00:00 2001 From: jgeboski Date: Thu, 7 Jan 2016 14:06:04 -0500 Subject: facebook-api: ignore messages which are sequentially duplicated Sometimes Facebook will sent a batch of duplicated messages over the MQTT stream. There are occasions where Facebook will send duplicated messages which are not sequential, however, it does not occur at the rete of the sequential duplication. This is likely due to the fact that the plugin is using an older revision of the Messenger protocol. For now, we should attempt to ignore sequential duplicates from being from being display. This fix is not bullet proof, but it is simple, and should cut down on the duplicated message spam. The proper fix is likely going to be to update the plugin to use a more recent Messenger protocol revision. --- facebook/facebook-api.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'facebook/facebook-api.c') diff --git a/facebook/facebook-api.c b/facebook/facebook-api.c index dc22bea..4344cf8 100644 --- a/facebook/facebook-api.c +++ b/facebook/facebook-api.c @@ -60,7 +60,7 @@ struct _FbApiPrivate GQueue *msgs; gboolean invisible; guint unread; - + FbId lastmid; }; struct _FbApiData @@ -1438,6 +1438,8 @@ fb_api_cb_publish_ms(FbApi *api, GByteArray *pload) } values = fb_json_values_new(root); + fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE, + "$.deltaNewMessage.messageMetadata.offlineThreadingId"); fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE, "$.deltaNewMessage.messageMetadata.actorFbId"); fb_json_values_add(values, FB_JSON_TYPE_INT, FALSE, @@ -1457,6 +1459,20 @@ fb_api_cb_publish_ms(FbApi *api, GByteArray *pload) fb_json_values_set_array(values, TRUE, "$.deltas"); while (fb_json_values_update(values, &err)) { + id = fb_json_values_next_int(values, 0); + + /* Ignore everything but new messages */ + if (id == 0) { + continue; + } + + /* Ignore sequential duplicates */ + if (id == priv->lastmid) { + fb_util_debug_info("Ignoring duplicate %" FB_ID_FORMAT, id); + continue; + } + + priv->lastmid = id; fb_api_message_reset(&msg, FALSE); msg.uid = fb_json_values_next_int(values, 0); oid = fb_json_values_next_int(values, 0); @@ -1471,10 +1487,6 @@ fb_api_cb_publish_ms(FbApi *api, GByteArray *pload) } } - if (msg.uid == 0) { - continue; - } - body = fb_json_values_next_str(values, NULL); if (body != NULL) { -- cgit v1.2.3