aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy/empathy-chatroom.c5
-rw-r--r--libempathy/empathy-chatroom.h5
-rw-r--r--libempathy/empathy-tp-roomlist.c87
3 files changed, 53 insertions, 44 deletions
diff --git a/libempathy/empathy-chatroom.c b/libempathy/empathy-chatroom.c
index 17be191e5..91f86d04e 100644
--- a/libempathy/empathy-chatroom.c
+++ b/libempathy/empathy-chatroom.c
@@ -188,15 +188,12 @@ chatroom_set_property (GObject *object,
}
EmpathyChatroom *
-empathy_chatroom_new (McAccount *account,
- const gchar *room)
+empathy_chatroom_new (McAccount *account)
{
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
- g_return_val_if_fail (room != NULL, NULL);
return g_object_new (EMPATHY_TYPE_CHATROOM,
"account", account,
- "room", room,
NULL);
}
diff --git a/libempathy/empathy-chatroom.h b/libempathy/empathy-chatroom.h
index 58e2e53d7..a4eecc04a 100644
--- a/libempathy/empathy-chatroom.h
+++ b/libempathy/empathy-chatroom.h
@@ -50,9 +50,8 @@ struct _EmpathyChatroomClass {
};
GType empathy_chatroom_get_type (void) G_GNUC_CONST;
-EmpathyChatroom *empathy_chatroom_new (McAccount *account,
- const gchar *room);
-EmpathyChatroom *empathy_chatroom_new_full (McAccount *account,
+EmpathyChatroom *empathy_chatroom_new (McAccount *account);
+EmpathyChatroom *empathy_chatroom_new_full (McAccount *account,
const gchar *room,
const gchar *name,
gboolean auto_connect);
diff --git a/libempathy/empathy-tp-roomlist.c b/libempathy/empathy-tp-roomlist.c
index 04984096d..b54aec824 100644
--- a/libempathy/empathy-tp-roomlist.c
+++ b/libempathy/empathy-tp-roomlist.c
@@ -74,6 +74,35 @@ tp_roomlist_listing_cb (TpChannel *channel,
}
static void
+tp_roomlist_chatrooms_free (gpointer data)
+{
+ GSList *chatrooms = data;
+
+ g_slist_foreach (chatrooms, (GFunc) g_object_unref, NULL);
+ g_slist_free (chatrooms);
+}
+
+static void
+tp_roomlist_inspect_handles_cb (TpConnection *connection,
+ const gchar **names,
+ const GError *error,
+ gpointer user_data,
+ GObject *list)
+{
+ GSList *chatrooms = user_data;
+
+ while (*names) {
+ EmpathyChatroom *chatroom = chatrooms->data;
+
+ empathy_chatroom_set_room (chatroom, *names);
+ g_signal_emit (list, signals[NEW_ROOM], 0, chatroom);
+
+ names++;
+ chatrooms = chatrooms->next;
+ }
+}
+
+static void
tp_roomlist_got_rooms_cb (TpChannel *channel,
const GPtrArray *rooms,
gpointer user_data,
@@ -82,10 +111,8 @@ tp_roomlist_got_rooms_cb (TpChannel *channel,
EmpathyTpRoomlistPriv *priv = GET_PRIV (list);
EmpathyChatroom *chatroom;
guint i;
- gchar **room_ids;
GArray *handles = NULL;
- GSList *chatrooms = NULL, *l;
- const gchar *str;
+ GSList *chatrooms = NULL;
for (i = 0; i < rooms->len; i++) {
const GValue *room_name_value;
@@ -107,25 +134,24 @@ tp_roomlist_got_rooms_cb (TpChannel *channel,
continue;
}
- chatroom = g_object_new (EMPATHY_TYPE_CHATROOM,
- "account", priv->account,
- NULL);
+ chatroom = empathy_chatroom_new (priv->account);
- if (room_name_value) {
- str = g_value_get_string (room_name_value);
- empathy_chatroom_set_name (chatroom, str);
+ if (room_name_value != NULL) {
+ empathy_chatroom_set_name (chatroom,
+ g_value_get_string (room_name_value));
}
- if (handle_name_value) {
- str = g_value_get_string (handle_name_value);
- empathy_chatroom_set_room (chatroom, str);
+ if (handle_name_value != NULL) {
+ empathy_chatroom_set_room (chatroom,
+ g_value_get_string (handle_name_value));
- /* Room is ready, emit it */
+ /* We have the room ID, we can directly emit it */
g_signal_emit (list, signals[NEW_ROOM], 0, chatroom);
g_object_unref (chatroom);
} else {
- /* We first need to inspect the handle */
- if (!handles) {
+ /* We don't have the room ID, we'll inspect all handles
+ * at once and then emit rooms */
+ if (handles == NULL) {
handles = g_array_new (FALSE, FALSE, sizeof (guint));
}
@@ -134,31 +160,18 @@ tp_roomlist_got_rooms_cb (TpChannel *channel,
}
}
- if (!handles) {
- /* All rooms were ready, we are done */
- return;
+ if (handles != NULL) {
+ chatrooms = g_slist_reverse (chatrooms);
+ tp_cli_connection_call_inspect_handles (priv->connection, -1,
+ TP_HANDLE_TYPE_ROOM,
+ handles,
+ tp_roomlist_inspect_handles_cb,
+ chatrooms,
+ tp_roomlist_chatrooms_free,
+ list);
}
- tp_cli_connection_run_inspect_handles (priv->connection, -1,
- TP_HANDLE_TYPE_ROOM,
- handles,
- &room_ids,
- NULL, NULL);
-
- l = chatrooms = g_slist_reverse (chatrooms);
- for (i = 0; i < handles->len; i++) {
- EmpathyChatroom *chatroom = l->data;
-
- empathy_chatroom_set_room (chatroom, room_ids[i]);
- g_signal_emit (list, signals[NEW_ROOM], 0, chatroom);
-
- g_object_unref (chatroom);
- g_free (room_ids[i]);
- }
-
- g_free (room_ids);
g_array_free (handles, TRUE);
- g_slist_free (chatrooms);
}
static void