]> www.infradead.org Git - pidgin-chime.git/commitdiff
Fix fetching of room messages
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 6 Sep 2017 14:00:54 +0000 (15:00 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 6 Sep 2017 14:00:54 +0000 (15:00 +0100)
We can't rely on having a current LastSent for Rooms, so always fetch
from our last known message, just in case.

It would be nice if Chime always sent us a 'PreviousMessageId' with
each message, which would allow us to ditch this when we're opening
the room due to a mention. And would help in a few other cases too.

messages.c

index 83544c1451c746ae43cb4b0c550fcf05b99b1320..032a7d9fc109135293160927dfbbf5ad86365444 100644 (file)
@@ -211,33 +211,41 @@ void init_msgs(PurpleConnection *conn, struct chime_msgs *msgs, ChimeObject *obj
        msgs->cb = cb;
        msgs->seen_msgs = g_queue_new();
 
+       const gchar *last_seen;
+       gchar *last_id = NULL;
+       if (!chime_read_last_msg(conn, obj, &last_seen, &last_id))
+               last_seen = "1970-01-01T00:00:00.000Z";
+       msgs->last_seen = g_strdup(last_seen);
+
+       if (last_id) {
+               mark_msg_seen(msgs->seen_msgs, last_id);
+               g_free(last_id);
+       }
+
        g_signal_connect(obj, "notify::last-sent", G_CALLBACK(on_last_sent_updated), msgs);
        g_signal_connect(obj, "message", G_CALLBACK(on_message_received), msgs);
-       if (CHIME_IS_ROOM(obj))
+
+       if (CHIME_IS_ROOM(obj)) {
                g_signal_connect(obj, "members-done", G_CALLBACK(on_room_members_done), msgs);
-       else
+               /* Always fetch messages for rooms since we won't have been told of any
+                * updates to LastSent anyway. */
+       } else {
                msgs->members_done = TRUE;
 
-       /* Do we need to fetch new messages? */
-       gchar *last_sent, *last_id = NULL;
-       g_object_get(obj, "last-sent", &last_sent, NULL);
+               /* Do we need to fetch new messages? */
+               gchar *last_sent;
+               g_object_get(obj, "last-sent", &last_sent, NULL);
 
-       const gchar *last_seen;
-       if (!chime_read_last_msg(conn, obj, &last_seen, &last_id))
-               last_seen = "1970-01-01T00:00:00.000Z";
-       msgs->last_seen = g_strdup(last_seen);
+               if (!last_sent || ! strcmp(last_seen, last_sent)) {
+                       printf("No fetch; %s %s\n", last_sent, last_seen);
+                       msgs->msgs_done = TRUE;
+               }
+               g_free(last_sent);
+       }
 
-       if (last_sent && strcmp(last_seen, last_sent)) {
+       if (!msgs->msgs_done) {
                purple_debug(PURPLE_DEBUG_INFO, "chime", "Fetch messages for %s\n", name);
-
                chime_connection_fetch_messages_async(PURPLE_CHIME_CXN(conn), obj, NULL, last_seen, NULL, fetch_msgs_cb, msgs);
-       } else
-               msgs->msgs_done = TRUE;
-       g_free(last_sent);
-
-       if (last_id) {
-               mark_msg_seen(msgs->seen_msgs, last_id);
-               g_free(last_id);
        }
 
        if (!msgs->msgs_done || !msgs->members_done)