]> git.0d.be Git - empathy.git/blobdiff - src/empathy-event-manager.c
event_manager_approve_channel_cb: empathy_tp_chat_get_account doesn't ref the object
[empathy.git] / src / empathy-event-manager.c
index 76b9e348afdde3005c58a131015f9317869111bc..ef9248647d6fd3bb234c094c3a4625446c77f211 100644 (file)
@@ -639,8 +639,8 @@ invite_dialog_response_cb (GtkDialog *dialog,
 {
   EmpathyTpChat *tp_chat;
   TpChannel *channel;
-  EmpathyTpGroup *group;
-  EmpathyContact *self_contact;
+  TpHandle self_handle;
+  GArray *members;
 
   gtk_widget_destroy (GTK_WIDGET (approval->dialog));
   approval->dialog = NULL;
@@ -664,16 +664,16 @@ invite_dialog_response_cb (GtkDialog *dialog,
   /* join the room */
   channel = empathy_tp_chat_get_channel (tp_chat);
 
-  group = empathy_tp_group_new (channel);
-  empathy_run_until_ready (group);
+  self_handle = tp_channel_group_get_self_handle (channel);
+  members = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
+  g_array_append_val (members, self_handle);
 
-  self_contact = empathy_tp_group_get_self_contact (group);
-  empathy_tp_group_add_member (group, self_contact, NULL);
+  tp_cli_channel_interface_group_call_add_members (channel, -1, members,
+      "", NULL, NULL, NULL, NULL);
 
   empathy_dispatch_operation_approve (approval->operation);
 
-  g_object_unref (group);
-  g_object_unref (self_contact);
+  g_array_free (members, TRUE);
 }
 
 static void
@@ -719,6 +719,36 @@ event_room_channel_process_func (EventPriv *event)
   event->approval->dialog = dialog;
 }
 
+static void
+event_manager_muc_invite_got_contact_name_cb (EmpathyContact *contact,
+                                              const GError *error,
+                                              gpointer user_data,
+                                              GObject *object)
+{
+  EventManagerApproval *approval = (EventManagerApproval *) user_data;
+  TpChannel *channel;
+  const gchar *invite_msg;
+  gchar *msg;
+  TpHandle self_handle;
+
+  channel = empathy_dispatch_operation_get_channel (approval->operation);
+
+  self_handle = tp_channel_group_get_self_handle (channel);
+  tp_channel_group_get_local_pending_info (channel, self_handle, NULL, NULL,
+      &invite_msg);
+
+  msg = g_strdup_printf (_("%s invited you to join %s"),
+      empathy_contact_get_name (approval->contact),
+      tp_channel_get_identifier (channel));
+
+  event_manager_add (approval->manager,
+    approval->contact, EMPATHY_IMAGE_GROUP_MESSAGE, msg, invite_msg,
+    approval, event_room_channel_process_func, NULL);
+
+  empathy_sound_play (empathy_main_window_get (),
+    EMPATHY_SOUND_CONVERSATION_NEW);
+}
+
 static void
 event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher,
   EmpathyDispatchOperation  *operation, EmpathyEventManager *manager)
@@ -760,8 +790,6 @@ event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher,
         }
       else if (handle_type == TP_HANDLE_TYPE_ROOM)
         {
-          gchar *msg;
-          const gchar *invite_msg;
           TpHandle self_handle, inviter;
           EmpathyContactFactory *contact_factory;
           McAccount *account;
@@ -769,7 +797,7 @@ event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher,
           self_handle = tp_channel_group_get_self_handle (channel);
 
           if (self_handle == 0 || !tp_channel_group_get_local_pending_info (
-                channel, self_handle, &inviter, NULL, &invite_msg))
+                channel, self_handle, &inviter, NULL, NULL))
             {
               DEBUG ("can't handle a incoming muc to which we have not been "
                   "invited");
@@ -779,26 +807,19 @@ event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher,
               return;
             }
 
+          /* We are invited to a room */
           account = empathy_tp_chat_get_account (tp_chat);
           contact_factory = empathy_contact_factory_dup_singleton ();
 
           approval->contact = empathy_contact_factory_get_from_handle (
               contact_factory, account, inviter);
 
-          /* We are invited to a room */
-          msg = g_strdup_printf ("%s invited you to join %s",
-              empathy_contact_get_name (approval->contact),
-              tp_channel_get_identifier (channel));
-
-          event_manager_add (approval->manager,
-            approval->contact, EMPATHY_IMAGE_GROUP_MESSAGE, msg, invite_msg,
-            approval, event_room_channel_process_func, NULL);
-
-          empathy_sound_play (empathy_main_window_get (),
-            EMPATHY_SOUND_CONVERSATION_NEW);
+          empathy_contact_call_when_ready (approval->contact,
+            EMPATHY_CONTACT_READY_NAME,
+            event_manager_muc_invite_got_contact_name_cb, approval, NULL,
+            G_OBJECT (manager));
 
           g_object_unref (contact_factory);
-          g_object_unref (account);
         }
     }
   else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA))