]> git.0d.be Git - empathy.git/commitdiff
Don't unhighlight chat tabs when more messages are received
authorWill Thompson <will.thompson@collabora.co.uk>
Fri, 10 Feb 2012 17:47:47 +0000 (17:47 +0000)
committerWill Thompson <will.thompson@collabora.co.uk>
Fri, 10 Feb 2012 17:52:53 +0000 (17:52 +0000)
Travis noticed that if you receive a message in which you are not
mentioned after one in which you are, the highlight on the chat tab is
cleared. This turned out to be because the text of the chat tab label
was set in two different places in empathy-chat-window.c: one which
takes should_highlight into account, and one which does not.

This patch makes EmpathyChat keep track of whether it should be
highlighted (reusing empathy_chat_messages_read(), which is called to
acknowledge messages as having been seen by the user, to clear the
flag), and then uses that from one of the label-updating code paths and
deletes the other.

https://bugzilla.gnome.org/show_bug.cgi?id=669823

libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-chat.h
src/empathy-chat-window.c

index 5dda2ce6b33d34514b0e558977cc3f60e29d44e4..358b1b98219455295b45dd240d923a4bcb74bb4a 100644 (file)
@@ -160,6 +160,10 @@ struct _EmpathyChatPriv {
        /* A regex matching our own current nickname in the room, or %NULL if
         * !empathy_chat_is_room (). */
        GRegex            *highlight_regex;
+
+       /* TRUE if empathy_chat_is_room() and there are unread highlighted messages.
+        * Cleared by empathy_chat_messages_read(). */
+       gboolean           highlighted;
 };
 
 typedef struct {
@@ -1484,6 +1488,11 @@ chat_message_received (EmpathyChat *chat,
                empathy_chat_view_edit_message (chat->view, message);
        } else {
                gboolean should_highlight = chat_should_highlight (chat, message);
+
+               if (should_highlight) {
+                       priv->highlighted = TRUE;
+               }
+
                DEBUG ("Appending new message '%s' from %s (%d)",
                        empathy_message_get_token (message),
                        empathy_contact_get_alias (sender),
@@ -4308,6 +4317,16 @@ empathy_chat_is_room (EmpathyChat *chat)
        return (priv->handle_type == TP_HANDLE_TYPE_ROOM);
 }
 
+gboolean
+empathy_chat_is_highlighted (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
+
+       return priv->highlighted;
+}
+
 guint
 empathy_chat_get_nb_unread_messages (EmpathyChat *self)
 {
@@ -4336,6 +4355,8 @@ empathy_chat_messages_read (EmpathyChat *self)
                        TP_TEXT_CHANNEL (priv->tp_chat), NULL, NULL);
        }
 
+       priv->highlighted = FALSE;
+
        if (priv->unread_messages_when_offline > 0) {
                /* We can't ack those as the connection has gone away so just consider
                * them as read. */
index 0031410d65006a931f33dbe8f4af8b9f694b7456..00da3d64156241c66bec69e2cf366125560670e9 100644 (file)
@@ -89,7 +89,7 @@ gboolean           empathy_chat_is_room              (EmpathyChat   *chat);
 void               empathy_chat_set_show_contacts    (EmpathyChat *chat,
                                                       gboolean     show);
 guint              empathy_chat_get_nb_unread_messages (EmpathyChat   *chat);
-
+gboolean           empathy_chat_is_highlighted (EmpathyChat *chat);
 void               empathy_chat_messages_read        (EmpathyChat *self);
 
 gboolean           empathy_chat_is_composing (EmpathyChat *chat);
index 634968593d9b6826a003bb17bbde695503e2184e..4e3f0480788547ba258fd5d80a05066cf2bd19e4 100644 (file)
@@ -928,10 +928,19 @@ chat_window_update_chat_tab_full (EmpathyChat *chat,
        g_free (markup);
 
        /* Update tab and menu label */
+       if (empathy_chat_is_highlighted (chat)) {
+               markup = g_markup_printf_escaped (
+                       "<span color=\"red\" weight=\"bold\">%s</span>",
+                       name);
+       } else {
+               markup = g_markup_escape_text (name, -1);
+       }
+
        widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
-       gtk_label_set_text (GTK_LABEL (widget), name);
+       gtk_label_set_markup (GTK_LABEL (widget), markup);
        widget = g_object_get_data (G_OBJECT (chat), "chat-window-menu-label");
-       gtk_label_set_text (GTK_LABEL (widget), name);
+       gtk_label_set_markup (GTK_LABEL (widget), markup);
+       g_free (markup);
 
        /* Update the window if it's the current chat */
        if (priv->current_chat == chat) {
@@ -1560,30 +1569,6 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
        g_free (escaped);
 }
 
-static void
-chat_window_set_highlight_room_labels (EmpathyChat *chat)
-{
-       gchar *markup, *name;
-       GtkWidget *widget;
-
-       if (!empathy_chat_is_room (chat))
-               return;
-
-       name = empathy_chat_dup_name (chat);
-       markup = g_markup_printf_escaped (
-               "<span color=\"red\" weight=\"bold\">%s</span>",
-               name);
-
-       widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
-       gtk_label_set_markup (GTK_LABEL (widget), markup);
-
-       widget = g_object_get_data (G_OBJECT (chat), "chat-window-menu-label");
-       gtk_label_set_markup (GTK_LABEL (widget), markup);
-
-       g_free (name);
-       g_free (markup);
-}
-
 static gboolean
 empathy_chat_window_has_focus (EmpathyChatWindow *window)
 {
@@ -1670,8 +1655,6 @@ chat_window_new_message_cb (EmpathyChat       *chat,
        }
 
        if (needs_urgency) {
-               chat_window_set_highlight_room_labels (chat);
-
                if (!has_focus) {
                        chat_window_set_urgency_hint (window, TRUE);
                }