]> git.0d.be Git - empathy.git/commitdiff
Block events messages when the chat is connecting to a new Text channel. Fixes bug...
authorXavier Claessens <xclaesse@src.gnome.org>
Sat, 16 Feb 2008 09:22:52 +0000 (09:22 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Sat, 16 Feb 2008 09:22:52 +0000 (09:22 +0000)
svn path=/trunk/; revision=641

libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-chat.h
libempathy-gtk/empathy-group-chat.c
libempathy-gtk/empathy-private-chat.c

index f7c013820c18b6e43a26493a9bef532101d2ad0b..a568db03bf84f9de6de1e877f50f9c94a849f71c 100644 (file)
@@ -80,6 +80,7 @@ struct _EmpathyChatPriv {
        gboolean               first_tp_chat;
        time_t                 last_log_timestamp;
        gboolean               is_first_char;
+       guint                  block_events_timeout_id;
        /* Used to automatically shrink a window that has temporarily
         * grown due to long input. 
         */
@@ -414,6 +415,10 @@ chat_finalize (GObject *object)
                g_source_remove (priv->scroll_idle_id);
        }
 
+       if (priv->block_events_timeout_id) {
+               g_source_remove (priv->block_events_timeout_id);
+       }
+
        g_free (priv->id);
 
        G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
@@ -1439,6 +1444,18 @@ empathy_chat_load_geometry (EmpathyChat *chat,
        empathy_geometry_load (empathy_chat_get_id (chat), x, y, w, h);
 }
 
+static gboolean
+chat_block_events_timeout_cb (gpointer data)
+{
+       EmpathyChat     *chat = EMPATHY_CHAT (data);
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       chat->block_events = FALSE;
+       priv->block_events_timeout_id = 0;
+
+       return FALSE;
+}
+
 void
 empathy_chat_set_tp_chat (EmpathyChat   *chat,
                          EmpathyTpChat *tp_chat)
@@ -1455,6 +1472,15 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
                return;
        }
 
+       /* Block events for some time to avoid having "has come online" or
+        * "joined" messages. */
+       chat->block_events = TRUE;
+       if (priv->block_events_timeout_id != 0) {
+               g_source_remove (priv->block_events_timeout_id);
+       }
+       priv->block_events_timeout_id =
+               g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
+
        if (priv->tp_chat) {
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                                                      chat_message_received_cb,
index 5bf456e48d24a62d63a33db38a254a1eb65124d6..bcf382e535200c6bbb584cc42d98e3cebe0b03af 100644 (file)
@@ -58,6 +58,7 @@ struct _EmpathyChat {
        /* Protected */
        EmpathyChatView *view;
        GtkWidget       *input_text_view;
+       gboolean         block_events;
 };
 
 struct _EmpathyChatClass {
index 4f86ef2bab2c2e88a868464184422389aff8dca8..a51b25228d3d5c68a78dc6e00b767a280da1940f 100644 (file)
@@ -355,20 +355,18 @@ group_chat_members_changed_cb (EmpathyTpChatroom *tp_chat,
                               gboolean            is_member,
                               EmpathyGroupChat   *chat)
 {
-       EmpathyGroupChatPriv *priv;
-       gchar                *str;
-
-       priv = GET_PRIV (chat);
-
-       if (is_member) {
-               str = g_strdup_printf (_("%s has joined the room"),
-                                      empathy_contact_get_name (contact));
-       } else {
-               str = g_strdup_printf (_("%s has left the room"),
-                                      empathy_contact_get_name (contact));
+       if (!EMPATHY_CHAT (chat)->block_events) {
+               gchar *str;
+               if (is_member) {
+                       str = g_strdup_printf (_("%s has joined the room"),
+                                              empathy_contact_get_name (contact));
+               } else {
+                       str = g_strdup_printf (_("%s has left the room"),
+                                              empathy_contact_get_name (contact));
+               }
+               empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
+               g_free (str);
        }
-       empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
-       g_free (str);
 }
 
 static void
@@ -571,13 +569,15 @@ group_chat_subject_notify_cb (EmpathyTpChat   *tp_chat,
        priv->topic = str;
        gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->topic);
 
-       if (!G_STR_EMPTY (priv->topic)) {
-               str = g_strdup_printf (_("Topic set to: %s"), priv->topic);
-       } else {
-               str = g_strdup (_("No topic defined"));
+       if (!EMPATHY_CHAT (chat)->block_events) {
+               if (!G_STR_EMPTY (priv->topic)) {
+                       str = g_strdup_printf (_("Topic set to: %s"), priv->topic);
+               } else {
+                       str = g_strdup (_("No topic defined"));
+               }
+               empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
+               g_free (str);
        }
-       empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
-       g_free (str);
 }
 
 static void
index 2dd1ba7554dc31bf68673d5f92ae966a28955a0c..0bcdd784494f21781306cd8a22b6d879350a3ca3 100644 (file)
@@ -223,7 +223,7 @@ private_chat_contact_presence_updated_cb (EmpathyContact     *contact,
                      empathy_contact_get_id (contact));
 
        if (!empathy_contact_is_online (contact)) {
-               if (priv->is_online) {
+               if (priv->is_online && !EMPATHY_CHAT (chat)->block_events) {
                        gchar *msg;
 
                        msg = g_strdup_printf (_("%s went offline"),
@@ -237,7 +237,7 @@ private_chat_contact_presence_updated_cb (EmpathyContact     *contact,
                g_signal_emit_by_name (chat, "composing", FALSE);
 
        } else {
-               if (!priv->is_online) {
+               if (!priv->is_online && !EMPATHY_CHAT (chat)->block_events) {
                        gchar *msg;
 
                        msg = g_strdup_printf (_("%s has come online"),