diff options
author | Marius Halden <marius.h@lden.org> | 2016-03-19 16:31:47 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2016-03-19 20:52:31 +0100 |
commit | 9cb750b37c5f849ca7627c135543debfb28d7a4c (patch) | |
tree | 33d1409b21fdb9e2deba9b1b677fe329383a7f26 /facebook/facebook.c | |
parent | 205d2edcfc2494dbff4bba1dde368b77a961eb86 (diff) | |
download | bitlbee-facebook-9cb750b37c5f849ca7627c135543debfb28d7a4c.tar.gz bitlbee-facebook-9cb750b37c5f849ca7627c135543debfb28d7a4c.tar.bz2 bitlbee-facebook-9cb750b37c5f849ca7627c135543debfb28d7a4c.tar.xz |
Keep track of last message received.show_unread
When changing to/from away duplicate messages can be fetched if
`show_unread` if `true` and `mark_read` is `false`. This commit solves
this by keeping track of the last message received from each buddy and
chat.
Diffstat (limited to 'facebook/facebook.c')
-rw-r--r-- | facebook/facebook.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/facebook/facebook.c b/facebook/facebook.c index 5982512..6b67e52 100644 --- a/facebook/facebook.c +++ b/facebook/facebook.c @@ -26,6 +26,11 @@ #define OPT_SELFMESSAGE 0 #endif +struct FbBuddyData { + gint flags; + FbApiMessage last_message; +}; + static void fb_cb_api_messages(FbApi *api, GSList *msgs, gpointer data); @@ -70,6 +75,8 @@ fb_groupchat_new(struct im_connection *ic, FbId tid, const gchar *name) gc = imcb_chat_new(ic, stid); fb_data_add_groupchat(fata, gc); + gc->data = g_new0(struct FbBuddyData, 1); + ch = gc->ui_data; ch->flags &= ~IRC_CHANNEL_CHAT_PICKME; @@ -204,6 +211,7 @@ fb_cb_api_contacts(FbApi *api, GSList *users, gboolean complete, gpointer data) GSList *l; GValue val = G_VALUE_INIT; struct im_connection *ic; + struct FbBuddyData *fbd; ic = fb_data_get_connection(fata); @@ -225,7 +233,8 @@ fb_cb_api_contacts(FbApi *api, GSList *users, gboolean complete, gpointer data) imcb_rename_buddy(ic, uid, user->name); bu = imcb_buddy_by_handle(ic, uid); - bu->data = GINT_TO_POINTER(TRUE); + fbd = bu->data; + fbd->flags = TRUE; } if (!complete) { @@ -242,8 +251,9 @@ fb_cb_api_contacts(FbApi *api, GSList *users, gboolean complete, gpointer data) continue; } - if (GPOINTER_TO_INT(bu->data)) { - bu->data = GINT_TO_POINTER(FALSE); + fbd = bu->data; + if (fbd->flags) { + fbd->flags = FALSE; } else { imcb_remove_buddy(ic, bu->handle, NULL); } @@ -364,6 +374,8 @@ fb_cb_api_messages(FbApi *api, GSList *msgs, gpointer data) guint32 flags; struct groupchat *gc; struct im_connection *ic; + bee_user_t *bu; + struct FbBuddyData *fbd; ic = fb_data_get_connection(fata); acct = ic->acc; @@ -403,7 +415,17 @@ fb_cb_api_messages(FbApi *api, GSList *msgs, gpointer data) fb_api_read(api, msg->uid, FALSE); } + bu = imcb_buddy_by_handle(ic, uid); + + fbd = bu->data; + if (msg->tstamp <= fbd->last_message.tstamp) { + continue; + } + imcb_buddy_msg(ic, uid, (gchar *) msg->text, flags, tstamp); + + fbd->last_message = *msg; + continue; } @@ -423,7 +445,16 @@ fb_cb_api_messages(FbApi *api, GSList *msgs, gpointer data) fb_api_read(api, msg->tid, TRUE); } + fbd = gc->data; + if (msg->tstamp < fbd->last_message.tstamp || + (msg->tstamp == fbd->last_message.tstamp && + msg->uid == fbd->last_message.uid)) { + continue; + } + imcb_chat_msg(gc, uid, (gchar *) msg->text, flags, tstamp); + + fbd->last_message = *msg; } } } @@ -820,6 +851,8 @@ fb_chat_leave(struct groupchat *gc) { FbData *fata = gc->ic->proto_data; + g_free(gc->data); + fb_data_remove_groupchat(fata, gc); imcb_chat_free(gc); } @@ -873,13 +906,13 @@ fb_away_states(struct im_connection *ic) static void fb_buddy_data_add(struct bee_user *bu) { - bu->data = GINT_TO_POINTER(FALSE); + bu->data = g_new0(struct FbBuddyData, 1); } static void fb_buddy_data_free(struct bee_user *bu) { - bu->data = NULL; + g_free(bu->data); } static account_t * |