]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-chat.c
Merge branch 'master' into tp-tube
[empathy.git] / libempathy / empathy-tp-chat.c
index 3ecc3dc6dd2c2a8e4477f3b1f5338d6148de4d1a..54e08d07139cebb04b921338a88dd5ab936349e5 100644 (file)
@@ -97,13 +97,8 @@ tp_chat_invalidated_cb (TpProxy       *proxy,
                        gchar         *message,
                        EmpathyTpChat *chat)
 {
-       EmpathyTpChatPriv *priv = GET_PRIV (chat);
-
        DEBUG ("Channel invalidated: %s", message);
        g_signal_emit (chat, signals[DESTROY], 0);
-
-       g_object_unref (priv->channel);
-       priv->channel = NULL;
 }
 
 static void
@@ -211,11 +206,21 @@ tp_chat_emit_queued_messages (EmpathyTpChat *chat)
 
 static void
 tp_chat_got_sender_cb (EmpathyTpContactFactory *factory,
-                      GList                   *contacts,
+                      EmpathyContact          *contact,
+                      const GError            *error,
                       gpointer                 message,
                       GObject                 *chat)
 {
-       empathy_message_set_sender (message, contacts->data);
+       EmpathyTpChatPriv *priv = GET_PRIV (chat);
+
+       if (error) {
+               DEBUG ("Error: %s", error->message);
+               /* Do not block the message queue, just drop this message */
+               g_queue_remove (priv->messages_queue, message);
+       } else {
+               empathy_message_set_sender (message, contact);
+       }
+
        tp_chat_emit_queued_messages (EMPATHY_TP_CHAT (chat));
 }
 
@@ -243,8 +248,8 @@ tp_chat_build_message (EmpathyTpChat *chat,
                empathy_message_set_sender (message, priv->user);
                tp_chat_emit_queued_messages (chat);
        } else {
-               empathy_tp_contact_factory_get_from_handles (priv->factory,
-                       1, &from_handle,
+               empathy_tp_contact_factory_get_from_handle (priv->factory,
+                       from_handle,
                        tp_chat_got_sender_cb,
                        message, NULL, G_OBJECT (chat));
        }
@@ -365,13 +370,18 @@ typedef struct {
 
 static void
 tp_chat_state_changed_got_contact_cb (EmpathyTpContactFactory *factory,
-                                     GList                   *contacts,
+                                     EmpathyContact          *contact,
+                                     const GError            *error,
                                      gpointer                 user_data,
                                      GObject                 *chat)
 {
-       EmpathyContact *contact = contacts->data;
        TpChannelChatState state;
 
+       if (error) {
+               DEBUG ("Error: %s", error->message);
+               return;
+       }
+
        state = GPOINTER_TO_UINT (user_data);
        DEBUG ("Chat state changed for %s (%d): %d",
                empathy_contact_get_name (contact),
@@ -389,7 +399,7 @@ tp_chat_state_changed_cb (TpChannel *channel,
 {
        EmpathyTpChatPriv *priv = GET_PRIV (chat);
 
-       empathy_tp_contact_factory_get_from_handles (priv->factory, 1, &handle,
+       empathy_tp_contact_factory_get_from_handle (priv->factory, handle,
                tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
                NULL, chat);
 }
@@ -828,19 +838,28 @@ tp_chat_update_remote_contact (EmpathyTpChat *chat)
 
 static void
 tp_chat_got_added_contacts_cb (EmpathyTpContactFactory *factory,
-                              GList                   *contacts,
+                              guint                    n_contacts,
+                              EmpathyContact * const * contacts,
+                              guint                    n_failed,
+                              const TpHandle          *failed,
+                              const GError            *error,
                               gpointer                 user_data,
                               GObject                 *chat)
 {
        EmpathyTpChatPriv *priv = GET_PRIV (chat);
-       GList *l;
+       guint i;
        const TpIntSet *members;
        TpHandle handle;
        EmpathyContact *contact;
 
+       if (error) {
+               DEBUG ("Error: %s", error->message);
+               return;
+       }
+
        members = tp_channel_group_get_members (priv->channel);
-       for (l = contacts; l; l = l->next) {
-               contact = l->data;
+       for (i = 0; i < n_contacts; i++) {
+               contact = contacts[i];
                handle = empathy_contact_get_handle (contact);
 
                /* Make sure the contact is still member */
@@ -881,7 +900,7 @@ tp_chat_group_members_changed_cb (TpChannel     *self,
                        if (handle == g_array_index (removed, TpHandle, i)) {
                                priv->members = g_list_delete_link (priv->members, l);
                                g_signal_emit_by_name (chat, "members-changed",
-                                                      contact, actor, reason,
+                                                      contact, NULL, reason,
                                                       message, FALSE);
                                g_object_unref (contact);
                                break;
@@ -902,13 +921,20 @@ tp_chat_group_members_changed_cb (TpChannel     *self,
 
 static void
 tp_chat_got_remote_contact_cb (EmpathyTpContactFactory *factory,
-                              GList *contacts,
-                              gpointer user_data,
-                              GObject *chat)
+                              EmpathyContact          *contact,
+                              const GError            *error,
+                              gpointer                 user_data,
+                              GObject                 *chat)
 {
        EmpathyTpChatPriv *priv = GET_PRIV (chat);
 
-       priv->remote_contact = g_object_ref (contacts->data);
+       if (error) {
+               DEBUG ("Error: %s", error->message);
+               empathy_tp_chat_close (EMPATHY_TP_CHAT (chat));
+               return;
+       }
+
+       priv->remote_contact = g_object_ref (contact);
        g_object_notify (chat, "remote-contact");
 
        tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
@@ -916,37 +942,22 @@ tp_chat_got_remote_contact_cb (EmpathyTpContactFactory *factory,
 
 static void
 tp_chat_got_self_contact_cb (EmpathyTpContactFactory *factory,
-                            GList                   *contacts,
+                            EmpathyContact          *contact,
+                            const GError            *error,
                             gpointer                 user_data,
                             GObject                 *chat)
 {
        EmpathyTpChatPriv *priv = GET_PRIV (chat);
 
-       priv->user = g_object_ref (contacts->data);
-       empathy_contact_set_is_user (priv->user, TRUE);
-       tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
-}
-
-static void
-tp_chat_get_self_handle_cb (TpConnection *connection,
-                           TpHandle self_handle,
-                           const GError *error,
-                           gpointer user_data,
-                           GObject *chat)
-{
-       EmpathyTpChatPriv *priv = GET_PRIV (chat);
-
        if (error) {
                DEBUG ("Error: %s", error->message);
-               tp_cli_channel_call_close (priv->channel, -1,
-                                          NULL, NULL, NULL, NULL);
+               empathy_tp_chat_close (EMPATHY_TP_CHAT (chat));
                return;
        }
 
-       empathy_tp_contact_factory_get_from_handles (priv->factory,
-               1, &self_handle,
-               tp_chat_got_self_contact_cb,
-               NULL, NULL, chat);
+       priv->user = g_object_ref (contact);
+       empathy_contact_set_is_user (priv->user, TRUE);
+       tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
 }
 
 static GObject *
@@ -976,9 +987,8 @@ tp_chat_constructor (GType                  type,
 
                /* Get self contact from the group's self handle */
                handle = tp_channel_group_get_self_handle (priv->channel);
-               empathy_tp_contact_factory_get_from_handles (priv->factory,
-                       1, &handle,
-                       tp_chat_got_self_contact_cb,
+               empathy_tp_contact_factory_get_from_handle (priv->factory,
+                       handle, tp_chat_got_self_contact_cb,
                        NULL, NULL, chat);
 
                /* Get initial member contacts */
@@ -988,17 +998,19 @@ tp_chat_constructor (GType                  type,
                        handles->len, (TpHandle*) handles->data,
                        tp_chat_got_added_contacts_cb, NULL, NULL, chat);
 
-               g_signal_connect_swapped (priv->channel, "group-members-changed",
+               g_signal_connect (priv->channel, "group-members-changed",
                        G_CALLBACK (tp_chat_group_members_changed_cb), chat);
        } else {
                /* Get the self contact from the connection's self handle */
-               tp_cli_connection_call_get_self_handle (connection, -1,
-                       tp_chat_get_self_handle_cb, NULL, NULL, chat);
+               handle = tp_connection_get_self_handle (connection);
+               empathy_tp_contact_factory_get_from_handle (priv->factory,
+                       handle, tp_chat_got_self_contact_cb,
+                       NULL, NULL, chat);
 
                /* Get the remote contact */
                handle = tp_channel_get_handle (priv->channel, NULL);
-               empathy_tp_contact_factory_get_from_handles (priv->factory,
-                       1, &handle, tp_chat_got_remote_contact_cb,
+               empathy_tp_contact_factory_get_from_handle (priv->factory,
+                       handle, tp_chat_got_remote_contact_cb,
                        NULL, NULL, chat);
        }
 
@@ -1187,17 +1199,9 @@ empathy_tp_chat_close (EmpathyTpChat *chat) {
        EmpathyTpChatPriv *priv = GET_PRIV (chat);
 
        /* If there are still messages left, it'll come back..
-          We loose the ordering of sent messages though */
-       g_signal_handlers_disconnect_by_func (priv->channel,
-               tp_chat_invalidated_cb, chat);
-
+        * We loose the ordering of sent messages though */
        tp_cli_channel_call_close (priv->channel, -1, tp_chat_async_cb,
                "closing channel", NULL, NULL);
-
-       g_object_unref (priv->channel);
-       priv->channel = NULL;
-
-       g_signal_emit (chat, signals[DESTROY], 0);
 }
 
 const gchar *
@@ -1231,6 +1235,16 @@ empathy_tp_chat_get_channel (EmpathyTpChat *chat)
        return priv->channel;
 }
 
+TpConnection *
+empathy_tp_chat_get_connection (EmpathyTpChat *chat)
+{
+       EmpathyTpChatPriv *priv = GET_PRIV (chat);
+
+       g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
+
+       return tp_channel_borrow_connection (priv->channel);
+}
+
 gboolean
 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
 {