]> git.0d.be Git - empathy.git/commitdiff
empathy-chat: acknowledge pending messages on empathy_chat_messages_read() (#608979)
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Thu, 4 Feb 2010 22:24:01 +0000 (09:24 +1100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 8 Feb 2010 19:41:13 +0000 (19:41 +0000)
Empathy displays this handy number of unread messages in the title bar, but
you can't replicate this behaviour using an Observer because Empathy
acknowledges the messages immediately. This patch makes it so that Empathy
only acknowledges the messages when it decrements the unread messages count.

N.B. EmpathyTpChat currently seems to assume that no other client is going to
acknowledge messages for channels, it is handling. This seems valid enough,
just pointing it out.

libempathy-gtk/empathy-chat.c

index 22225808226d47ff037ae68fa0fc1975f92f4145..bed7aa78e13b9d80d2e0e3ba9e9e35283314ddd8 100644 (file)
@@ -96,7 +96,7 @@ typedef struct {
        GtkWidget         *info_bar_vbox;
        GtkWidget         *search_bar;
 
-       guint              unread_messages;
+       GList             *pending_messages;
        /* TRUE if the pending messages can be displayed. This is to avoid to show
         * pending messages *before* messages from logs. (#603980) */
        gboolean           can_show_pending;
@@ -1116,7 +1116,9 @@ chat_message_received (EmpathyChat *chat, EmpathyMessage *message)
                               TP_CHANNEL_CHAT_STATE_ACTIVE,
                               chat);
 
-       priv->unread_messages++;
+       priv->pending_messages = g_list_prepend (priv->pending_messages,
+                       g_object_ref (message));
+
        g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
 }
 
@@ -1126,7 +1128,6 @@ chat_message_received_cb (EmpathyTpChat  *tp_chat,
                          EmpathyChat    *chat)
 {
        chat_message_received (chat, message);
-       empathy_tp_chat_acknowledge_message (tp_chat, message);
 }
 
 static void
@@ -2065,7 +2066,6 @@ show_pending_messages (EmpathyChat *chat) {
                EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
                chat_message_received (chat, message);
        }
-       empathy_tp_chat_acknowledge_messages (priv->tp_chat, messages);
 }
 
 static void
@@ -2936,7 +2936,7 @@ empathy_chat_get_nb_unread_messages (EmpathyChat *self)
 
        g_return_val_if_fail (EMPATHY_IS_CHAT (self), FALSE);
 
-       return priv->unread_messages;
+       return g_list_length (priv->pending_messages);
 }
 
 /* called when the messages have been read by user */
@@ -2947,5 +2947,12 @@ empathy_chat_messages_read (EmpathyChat *self)
 
        g_return_if_fail (EMPATHY_IS_CHAT (self));
 
-       priv->unread_messages = 0;
+       empathy_tp_chat_acknowledge_messages (priv->tp_chat,
+                       priv->pending_messages);
+
+       while (priv->pending_messages != NULL) {
+               g_object_unref (priv->pending_messages->data);
+               priv->pending_messages = g_list_delete_link (
+                       priv->pending_messages, priv->pending_messages);
+       }
 }