]> git.0d.be Git - empathy.git/commitdiff
chat: make nb_unread_messages incoming only
authorJonny Lamb <jonnylamb@gnome.org>
Thu, 12 May 2011 15:47:59 +0000 (16:47 +0100)
committerJonny Lamb <jonnylamb@gnome.org>
Thu, 12 May 2011 22:25:52 +0000 (23:25 +0100)
and add a property so it can have change notification.

Signed-off-by: Jonny Lamb <jonnylamb@gnome.org>
libempathy-gtk/empathy-chat.c

index b580812accfb14910af8ec9bae3fbce0646503cb..019064a161c65c766a9e94b1544b90cc54e0edfe 100644 (file)
@@ -173,6 +173,7 @@ enum {
        PROP_SHOW_CONTACTS,
        PROP_SMS_CHANNEL,
        PROP_N_MESSAGES_SENDING,
+       PROP_NB_UNREAD_MESSAGES,
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -219,6 +220,10 @@ chat_get_property (GObject    *object,
                g_value_set_uint (value,
                        empathy_chat_get_n_messages_sending (chat));
                break;
+       case PROP_NB_UNREAD_MESSAGES:
+               g_value_set_uint (value,
+                       empathy_chat_get_nb_unread_messages (chat));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -1271,7 +1276,10 @@ chat_message_received (EmpathyChat *chat,
                               TP_CHANNEL_CHAT_STATE_ACTIVE,
                               chat);
 
-       priv->unread_messages++;
+       if (empathy_message_is_incoming (message)) {
+               priv->unread_messages++;
+       }
+
        g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, pending);
 }
 
@@ -1283,6 +1291,16 @@ chat_message_received_cb (EmpathyTpChat  *tp_chat,
        chat_message_received (chat, message, FALSE);
 }
 
+static void
+chat_pending_message_removed_cb (EmpathyTpChat  *tp_chat,
+                                EmpathyChat    *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       priv->unread_messages--;
+       g_object_notify (G_OBJECT (chat), "nb-unread-messages");
+}
+
 static void
 chat_send_error_cb (EmpathyTpChat          *tp_chat,
                    const gchar            *message_body,
@@ -2871,6 +2889,8 @@ chat_finalize (GObject *object)
                        chat_destroy_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                        chat_message_received_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_pending_message_removed_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                        chat_send_error_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
@@ -3007,6 +3027,14 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                                                            0, G_MAXUINT, 0,
                                                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+       g_object_class_install_property (object_class,
+                                        PROP_NB_UNREAD_MESSAGES,
+                                        g_param_spec_uint ("nb-unread-messages",
+                                                           "Num Unread Messages",
+                                                           "The number of unread messages",
+                                                           0, G_MAXUINT, 0,
+                                                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
        signals[COMPOSING] =
                g_signal_new ("composing",
                              G_OBJECT_CLASS_TYPE (object_class),
@@ -3546,6 +3574,9 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
        g_signal_connect (tp_chat, "message-received",
                          G_CALLBACK (chat_message_received_cb),
                          chat);
+       g_signal_connect (tp_chat, "pending-message-removed",
+                         G_CALLBACK (chat_pending_message_removed_cb),
+                         chat);
        g_signal_connect (tp_chat, "send-error",
                          G_CALLBACK (chat_send_error_cb),
                          chat);
@@ -3876,7 +3907,6 @@ empathy_chat_messages_read (EmpathyChat *self)
        if (priv->tp_chat != NULL ) {
                empathy_tp_chat_acknowledge_all_messages (priv->tp_chat);
        }
-       priv->unread_messages = 0;
 
        empathy_chat_view_focus_toggled (self->view, TRUE);
 }