aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-chat.c
diff options
context:
space:
mode:
authorJonny Lamb <jonnylamb@gnome.org>2011-05-12 23:47:59 +0800
committerJonny Lamb <jonnylamb@gnome.org>2011-05-13 06:25:52 +0800
commitd36a313b26e957452fde60cac897791b0f6e4990 (patch)
treefd50c61aca096dd42bfc9ba8610b7e27624d6900 /libempathy-gtk/empathy-chat.c
parent7412b7e93ee7106dc139365fb391e2f613c294ef (diff)
downloadgsoc2013-empathy-d36a313b26e957452fde60cac897791b0f6e4990.tar
gsoc2013-empathy-d36a313b26e957452fde60cac897791b0f6e4990.tar.gz
gsoc2013-empathy-d36a313b26e957452fde60cac897791b0f6e4990.tar.bz2
gsoc2013-empathy-d36a313b26e957452fde60cac897791b0f6e4990.tar.lz
gsoc2013-empathy-d36a313b26e957452fde60cac897791b0f6e4990.tar.xz
gsoc2013-empathy-d36a313b26e957452fde60cac897791b0f6e4990.tar.zst
gsoc2013-empathy-d36a313b26e957452fde60cac897791b0f6e4990.zip
chat: make nb_unread_messages incoming only
and add a property so it can have change notification. Signed-off-by: Jonny Lamb <jonnylamb@gnome.org>
Diffstat (limited to 'libempathy-gtk/empathy-chat.c')
-rw-r--r--libempathy-gtk/empathy-chat.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index b580812ac..019064a16 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -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);
}
@@ -1284,6 +1292,16 @@ chat_message_received_cb (EmpathyTpChat *tp_chat,
}
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,
TpChannelTextSendError error_code,
@@ -2872,6 +2890,8 @@ chat_finalize (GObject *object)
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,
chat_state_changed_cb, 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);
}