]> git.0d.be Git - empathy.git/commitdiff
Make sure we don't assume Text channel's handle_type is != NONE.
authorXavier Claessens <xclaesse@src.gnome.org>
Wed, 23 Apr 2008 13:58:10 +0000 (13:58 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Wed, 23 Apr 2008 13:58:10 +0000 (13:58 +0000)
svn path=/trunk/; revision=1032

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

index 85956c8121fc221626e9055593df764838c3749a..10bffdfc17015c59a69ed1399cde431d105f0966 100644 (file)
@@ -191,7 +191,7 @@ chat_status_changed_cb (MissionControl           *mc,
 
        if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
            empathy_account_equal (account, priv->account) &&
-           priv->handle_type != 0) {
+           priv->handle_type != TP_HANDLE_TYPE_NONE) {
                empathy_debug (DEBUG_DOMAIN,
                               "Account reconnected, request a new Text channel");
                mission_control_request_channel_with_string_handle (mc,
@@ -529,10 +529,14 @@ chat_message_received_cb (EmpathyTpChat  *tp_chat,
                       empathy_contact_get_name (sender),
                       empathy_contact_get_handle (sender));
 
-       empathy_log_manager_add_message (priv->log_manager,
-                                        empathy_chat_get_id (chat),
-                                        FALSE,
-                                        message);
+       if (priv->id) {
+               gboolean is_chatroom;
+
+               is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
+               empathy_log_manager_add_message (priv->log_manager,
+                                                priv->id, is_chatroom,
+                                                message);
+       }
 
        empathy_chat_view_append_message (chat->view, message);
 
@@ -1168,21 +1172,25 @@ chat_text_populate_popup_cb (GtkTextView *view,
 static void
 chat_add_logs (EmpathyChat *chat)
 {
-       EmpathyChatPriv *priv;
-       GList          *messages, *l;
-       guint           num_messages;
-       guint           i;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       gboolean         is_chatroom;
+       GList           *messages, *l;
+       guint            num_messages;
+       guint            i;
 
-       priv = GET_PRIV (chat);
+       if (!priv->id) {
+               return;
+       }
 
        /* Turn off scrolling temporarily */
        empathy_chat_view_scroll (chat->view, FALSE);
 
        /* Add messages from last conversation */
+       is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
        messages = empathy_log_manager_get_last_messages (priv->log_manager,
                                                          priv->account,
-                                                         empathy_chat_get_id (chat),
-                                                         FALSE);
+                                                         priv->id,
+                                                         is_chatroom);
        num_messages  = g_list_length (messages);
 
        /* Only keep the 10 last messages */
@@ -1319,11 +1327,23 @@ chat_remote_contact_changed_cb (EmpathyChat *chat)
        priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
        if (priv->remote_contact) {
                g_object_ref (priv->remote_contact);
+               priv->handle_type = TP_HANDLE_TYPE_CONTACT;
+               g_free (priv->id);
+               priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
+       }
+       else if (priv->tp_chat) {
+               TpChannel *channel;
+
+               channel = empathy_tp_chat_get_channel (priv->tp_chat);
+               g_object_get (channel, "handle-type", &priv->handle_type, NULL);
+               g_free (priv->id);
+               priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
        }
 
        chat_set_show_contacts (chat, priv->remote_contact == NULL);
 
        g_object_notify (G_OBJECT (chat), "remote-contact");
+       g_object_notify (G_OBJECT (chat), "id");
 }
 
 static void
@@ -1678,10 +1698,8 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
        if (priv->account) {
                g_object_unref (priv->account);
        }
-       g_free (priv->id);
 
        priv->tp_chat = g_object_ref (tp_chat);
-       priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
        priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
 
        g_signal_connect (tp_chat, "message-received",
index 7e26e34a70f730463d73546a5e7c58003f215263..c53bd1b7267a2bfda5ad65e1763a03c6fc853ca0 100644 (file)
@@ -1119,6 +1119,16 @@ empathy_tp_chat_get_account (EmpathyTpChat *chat)
        return priv->account;
 }
 
+TpChannel *
+empathy_tp_chat_get_channel (EmpathyTpChat *chat)
+{
+       EmpathyTpChatPriv *priv = GET_PRIV (chat);
+
+       g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
+
+       return priv->channel;
+}
+
 gboolean
 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
 {
index a6ac3598b49ece28bc9525b4d8ab55dd94753ba7..12cd5cf92fac89464e9c306a20adb463ecdd600b 100644 (file)
@@ -58,6 +58,7 @@ EmpathyTpChat *empathy_tp_chat_new                  (TpChannel          *channel
 const gchar *  empathy_tp_chat_get_id               (EmpathyTpChat      *chat);
 EmpathyContact*empathy_tp_chat_get_remote_contact   (EmpathyTpChat      *chat);
 McAccount *    empathy_tp_chat_get_account          (EmpathyTpChat      *chat);
+TpChannel *    empathy_tp_chat_get_channel          (EmpathyTpChat      *chat);
 gboolean       empathy_tp_chat_is_ready             (EmpathyTpChat      *chat);
 guint          empathy_tp_chat_get_members_count    (EmpathyTpChat      *chat);
 void           empathy_tp_chat_set_acknowledge      (EmpathyTpChat      *chat,
index 09a0e4589bceb70838ca61b4e38131632ad011c0..4125f9743d48f3d91bbbaa8e27dba3485ae62003 100644 (file)
@@ -34,6 +34,7 @@
 #include <glade/glade.h>
 #include <glib/gi18n.h>
 
+#include <telepathy-glib/util.h>
 #include <libmissioncontrol/mission-control.h>
 
 #include <libempathy/empathy-contact-factory.h>
@@ -470,17 +471,18 @@ chat_window_clear_activate_cb (GtkWidget        *menuitem,
 static const gchar *
 chat_get_window_id_for_geometry (EmpathyChat *chat)
 {
-       gboolean separate_windows;
+       const gchar *res = NULL;
+       gboolean     separate_windows;
 
        empathy_conf_get_bool (empathy_conf_get (),
                               EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
                               &separate_windows);
 
        if (separate_windows) {
-               return empathy_chat_get_id (chat);
-       } else {
-               return "chat-window";
+               res = empathy_chat_get_id (chat);
        }
+
+       return res ? res : "chat-window";
 }
 
 static gboolean
@@ -1455,7 +1457,7 @@ empathy_chat_window_find_chat (McAccount   *account,
                        chat = ll->data;
 
                        if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
-                           strcmp (id, empathy_chat_get_id (chat)) == 0) {
+                           !tp_strdiff (id, empathy_chat_get_id (chat))) {
                                return chat;
                        }
                }
index 0b2999b4ebac111e6be1168c7e1da3b9839a4b65..d32a9dfe172dfe03370827c76f6d11715a118567 100644 (file)
@@ -183,13 +183,25 @@ filter_chat_dispatch (EmpathyFilter *filter,
                      gpointer       user_data)
 {
        EmpathyTpChat *tp_chat = EMPATHY_TP_CHAT (user_data);
-       McAccount     *account;
-       EmpathyChat   *chat;
+       EmpathyChat   *chat = NULL;
        const gchar   *id;
 
        id = empathy_tp_chat_get_id (tp_chat);
-       account = empathy_tp_chat_get_account (tp_chat);
-       chat = empathy_chat_window_find_chat (account, id);
+       if (!id) {
+               EmpathyContact *contact;
+
+               contact = empathy_tp_chat_get_remote_contact (tp_chat);
+               if (contact) {
+                       id = empathy_contact_get_id (contact);
+               }
+       }
+
+       if (id) {
+               McAccount *account;
+
+               account = empathy_tp_chat_get_account (tp_chat);
+               chat = empathy_chat_window_find_chat (account, id);
+       }
 
        if (chat) {
                empathy_chat_set_tp_chat (chat, tp_chat);
@@ -235,6 +247,7 @@ filter_chat_handle_channel (EmpathyFilter *filter,
                       channel);
 
        tp_chat = empathy_tp_chat_new (channel, FALSE);
+       empathy_run_until_ready (tp_chat);
        if (is_incoming) {
                filter_chat_dispatch (filter, tp_chat);
        } else {