/pidgin/main: 7391a9c98a1d: Remove _PurpleChatConversationPrivat...

Tomasz Wasilczyk twasilczyk at pidgin.im
Tue Mar 18 08:46:01 EDT 2014


Changeset: 7391a9c98a1dcb07549f45ed0bff9019bbbadbdd
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-03-18 13:45 +0100
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/7391a9c98a1d

Description:

Remove _PurpleChatConversationPrivate->in_room

diffstat:

 libpurple/conversationtypes.c                 |  60 +++++++++------------------
 libpurple/conversationtypes.h                 |   3 +-
 libpurple/plugins/perl/common/Conversation.xs |   6 +-
 libpurple/protocols/yahoo/libymsg.c           |  11 +++-
 libpurple/protocols/yahoo/yahoochat.c         |  31 +++++++++----
 pidgin/gtkconv.c                              |  11 +++-
 6 files changed, 61 insertions(+), 61 deletions(-)

diffs (truncated from 303 to 300 lines):

diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -48,8 +48,6 @@ typedef struct _PurpleChatUserPrivate  P
  */
 struct _PurpleChatConversationPrivate
 {
-	GList *in_room;     /* The users in the room.
-	                       Deprecated: Will be removed in 3.0.0 TODO */
 	GList *ignored;     /* Ignored users.                            */
 	char  *who;         /* The person who set the topic.             */
 	char  *topic;       /* The topic.                                */
@@ -617,7 +615,7 @@ purple_chat_conversation_get_users(const
 
 	g_return_val_if_fail(priv != NULL, NULL);
 
-	return priv->in_room;
+	return g_hash_table_get_values(priv->users);
 }
 
 guint
@@ -925,9 +923,9 @@ purple_chat_conversation_add_users(Purpl
 
 		chatuser = purple_chat_user_new(chat, user, alias, flag);
 
-		priv->in_room = g_list_prepend(priv->in_room, chatuser);
 		g_hash_table_replace(priv->users,
-				g_strdup(purple_chat_user_get_name(chatuser)), chatuser);
+			g_strdup(purple_chat_user_get_name(chatuser)),
+			chatuser);
 
 		cbuddies = g_list_prepend(cbuddies, chatuser);
 
@@ -1024,20 +1022,16 @@ purple_chat_conversation_rename_user(Pur
 	flags = purple_chat_user_get_flags(purple_chat_conversation_find_user(chat, old_user));
 	cb = purple_chat_user_new(chat, new_user, new_alias, flags);
 
-	priv->in_room = g_list_prepend(priv->in_room, cb);
 	g_hash_table_replace(priv->users,
-			g_strdup(purple_chat_user_get_name(cb)), cb);
+		g_strdup(purple_chat_user_get_name(cb)), cb);
 
 	if (ops != NULL && ops->chat_rename_user != NULL)
 		ops->chat_rename_user(chat, old_user, new_user, new_alias);
 
 	cb = purple_chat_conversation_find_user(chat, old_user);
 
-	if (cb) {
-		priv->in_room = g_list_remove(priv->in_room, cb);
+	if (cb)
 		g_hash_table_remove(priv->users, purple_chat_user_get_name(cb));
-		g_object_unref(cb);
-	}
 
 	if (purple_chat_conversation_is_ignored_user(chat, old_user)) {
 		purple_chat_conversation_unignore(chat, old_user);
@@ -1131,9 +1125,8 @@ purple_chat_conversation_remove_users(Pu
 		cb = purple_chat_conversation_find_user(chat, user);
 
 		if (cb) {
-			priv->in_room = g_list_remove(priv->in_room, cb);
-			g_hash_table_remove(priv->users, purple_chat_user_get_name(cb));
-			g_object_unref(cb);
+			g_hash_table_remove(priv->users,
+				purple_chat_user_get_name(cb));
 		}
 
 		/* NOTE: Don't remove them from ignored in case they re-enter. */
@@ -1180,43 +1173,34 @@ void
 purple_chat_conversation_clear_users(PurpleChatConversation *chat)
 {
 	PurpleConversationUiOps *ops;
-	GList *users;
-	GList *l;
-	GList *names = NULL;
+	GHashTableIter it;
 	PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(chat);
+	gchar *name;
 
 	g_return_if_fail(priv != NULL);
 
-	ops   = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(chat));
-	users = priv->in_room;
+	ops = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(chat));
 
 	if (ops != NULL && ops->chat_remove_users != NULL) {
-		for (l = users; l; l = l->next) {
-			PurpleChatUser *cb = l->data;
-			names = g_list_prepend(names,
-					(gchar *) purple_chat_user_get_name(cb));
-		}
+		GList *names = NULL;
+
+		g_hash_table_iter_init(&it, priv->users);
+		while (g_hash_table_iter_next(&it, (gpointer*)&name, NULL))
+			names = g_list_prepend(names, name);
+
 		ops->chat_remove_users(chat, names);
 		g_list_free(names);
 	}
 
-	for (l = users; l; l = l->next)
-	{
-		PurpleChatUser *cb = l->data;
-		const char *name = purple_chat_user_get_name(cb);
-
+	g_hash_table_iter_init(&it, priv->users);
+	while (g_hash_table_iter_next(&it, (gpointer*)&name, NULL)) {
 		purple_signal_emit(purple_conversations_get_handle(),
 						 "chat-user-leaving", chat, name, NULL);
 		purple_signal_emit(purple_conversations_get_handle(),
 						 "chat-user-left", chat, name, NULL);
-
-		g_object_unref(cb);
 	}
 
 	g_hash_table_remove_all(priv->users);
-
-	g_list_free(users);
-	priv->in_room = NULL;
 }
 
 void purple_chat_conversation_set_nick(PurpleChatConversation *chat, const char *nick) {
@@ -1443,7 +1427,7 @@ static void purple_chat_conversation_ini
 			PurpleChatConversation);
 
 	priv->users = g_hash_table_new_full(_purple_conversation_user_hash,
-			_purple_conversation_user_equal, g_free, NULL);
+		_purple_conversation_user_equal, g_free, g_object_unref);
 }
 
 /* Called when done constructing */
@@ -1477,11 +1461,7 @@ purple_chat_conversation_dispose(GObject
 	PurpleChatConversationPrivate *priv =
 			PURPLE_CHAT_CONVERSATION_GET_PRIVATE(object);
 
-	if (priv->in_room) {
-		g_list_foreach(priv->in_room, (GFunc)g_object_unref, NULL);
-		g_list_free(priv->in_room);
-		priv->in_room = NULL;
-	}
+	g_hash_table_remove_all(priv->users);
 
 	G_OBJECT_CLASS(parent_class)->dispose(object);
 }
diff --git a/libpurple/conversationtypes.h b/libpurple/conversationtypes.h
--- a/libpurple/conversationtypes.h
+++ b/libpurple/conversationtypes.h
@@ -380,7 +380,8 @@ PurpleChatConversation *purple_chat_conv
  * Returns a list of users in the chat room.  The members of the list
  * are PurpleChatUser objects.
  *
- * Returns: (transfer none): The list of users.
+ * Returns: (transfer container): The list of users. Use g_list_free() when done
+ *          using the list.
  */
 GList *purple_chat_conversation_get_users(const PurpleChatConversation *chat);
 
diff --git a/libpurple/plugins/perl/common/Conversation.xs b/libpurple/plugins/perl/common/Conversation.xs
--- a/libpurple/plugins/perl/common/Conversation.xs
+++ b/libpurple/plugins/perl/common/Conversation.xs
@@ -331,11 +331,13 @@ void
 purple_chat_conversation_get_users(chat)
 	Purple::ChatConversation chat
 PREINIT:
-	GList *l;
+	GList *l, *users;
 PPCODE:
-	for (l = purple_chat_conversation_get_users(chat); l != NULL; l = l->next) {
+	users = purple_chat_conversation_get_users(chat);
+	for (l = users; l != NULL; l = l->next) {
 		XPUSHs(sv_2mortal(purple_perl_bless_object(l->data, "Purple::ListEntry")));
 	}
+	g_list_free(users);
 
 void
 purple_chat_conversation_ignore(chat, name)
diff --git a/libpurple/protocols/yahoo/libymsg.c b/libpurple/protocols/yahoo/libymsg.c
--- a/libpurple/protocols/yahoo/libymsg.c
+++ b/libpurple/protocols/yahoo/libymsg.c
@@ -3815,10 +3815,13 @@ void yahoo_close(PurpleConnection *gc) {
 
 	for (l = yd->confs; l; l = l->next) {
 		PurpleChatConversation *conv = l->data;
-
-		yahoo_conf_leave(yd, purple_conversation_get_name(PURPLE_CONVERSATION(conv)),
-		                 purple_connection_get_display_name(gc),
-				 purple_chat_conversation_get_users(conv));
+		GList *users;
+
+		users = purple_chat_conversation_get_users(conv);
+		yahoo_conf_leave(yd,
+			purple_conversation_get_name(PURPLE_CONVERSATION(conv)),
+			purple_connection_get_display_name(gc), users);
+		g_list_free(users);
 	}
 	g_slist_free(yd->confs);
 
diff --git a/libpurple/protocols/yahoo/yahoochat.c b/libpurple/protocols/yahoo/yahoochat.c
--- a/libpurple/protocols/yahoo/yahoochat.c
+++ b/libpurple/protocols/yahoo/yahoochat.c
@@ -905,23 +905,24 @@ static void yahoo_conf_invite(PurpleConn
 {
 	YahooData *yd = purple_connection_get_protocol_data(gc);
 	struct yahoo_packet *pkt;
-	GList *members;
+	GList *members, *it;
 	char *msg2 = NULL;
 
 	if (msg)
 		msg2 = yahoo_string_encode(gc, msg, FALSE);
 
-	members = purple_chat_conversation_get_users(c);
-
 	pkt = yahoo_packet_new(YAHOO_SERVICE_CONFADDINVITE, YAHOO_STATUS_AVAILABLE, yd->session_id);
 
 	yahoo_packet_hash(pkt, "sssss", 1, dn, 51, buddy, 57, room, 58, msg?msg2:"", 13, "0");
-	for(; members; members = members->next) {
-		const char *name = purple_chat_user_get_name(members->data);
+
+	members = purple_chat_conversation_get_users(c);
+	for(it = members; it; it = it->next) {
+		const char *name = purple_chat_user_get_name(it->data);
 		if (!strcmp(name, dn))
 			continue;
 		yahoo_packet_hash(pkt, "ss", 52, name, 53, name);
 	}
+	g_list_free(members);
 
 	yahoo_packet_send_and_free(pkt, yd);
 	g_free(msg2);
@@ -1095,9 +1096,13 @@ void yahoo_c_leave(PurpleConnection *gc,
 		return;
 
 	if (id != YAHOO_CHAT_ID) {
-		yahoo_conf_leave(yd, purple_conversation_get_name(PURPLE_CONVERSATION(c)),
-			purple_connection_get_display_name(gc), purple_chat_conversation_get_users(c));
-			yd->confs = g_slist_remove(yd->confs, c);
+		GList *users;
+		users = purple_chat_conversation_get_users(c);
+		yahoo_conf_leave(yd,
+			purple_conversation_get_name(PURPLE_CONVERSATION(c)),
+			purple_connection_get_display_name(gc), users);
+		g_list_free(users);
+		yd->confs = g_slist_remove(yd->confs, c);
 	} else {
 		yahoo_chat_leave(gc, purple_conversation_get_name(PURPLE_CONVERSATION(c)),
 				purple_connection_get_display_name(gc), TRUE);
@@ -1121,9 +1126,13 @@ int yahoo_c_send(PurpleConnection *gc, i
 		return -1;
 
 	if (id != YAHOO_CHAT_ID) {
-		ret = yahoo_conf_send(gc, purple_connection_get_display_name(gc),
-				purple_conversation_get_name(PURPLE_CONVERSATION(c)),
-						purple_chat_conversation_get_users(c), what);
+		GList *users;
+		users = purple_chat_conversation_get_users(c);
+		ret = yahoo_conf_send(gc,
+			purple_connection_get_display_name(gc),
+			purple_conversation_get_name(PURPLE_CONVERSATION(c)),
+			users, what);
+		g_list_free(users);
 	} else {
 		ret = yahoo_chat_send(gc, purple_connection_get_display_name(gc),
 						purple_conversation_get_name(PURPLE_CONVERSATION(c)), what, flags);
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -4551,16 +4551,18 @@ tab_complete(PurpleConversation *conv)
 		}
 		g_list_free(list);
 	} else if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
-		GList *l = purple_chat_conversation_get_users(PURPLE_CHAT_CONVERSATION(conv));
+		GList *l, *users;
 		GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(PIDGIN_CONVERSATION(conv)->u.chat->list));
 		GtkTreeIter iter;
 		int f;
 
 		/* Users */
-		for (; l != NULL; l = l->next) {
+		users = purple_chat_conversation_get_users(PURPLE_CHAT_CONVERSATION(conv));
+		for (l = users; l != NULL; l = l->next) {
 			tab_complete_process_item(&most_matched, entered, entered_chars, &partial,
 									  &matches, purple_chat_user_get_name((PurpleChatUser *)l->data));
 		}
+		g_list_free(users);
 
 		/* Aliases */
 		if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter))
@@ -8726,9 +8728,12 @@ gboolean pidgin_conv_attach_to_conversat
 	}
 
 	if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
+		GList *users;
 		PurpleChatConversation *chat = PURPLE_CHAT_CONVERSATION(conv);
 		pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC);
-		pidgin_conv_chat_add_users(chat, purple_chat_conversation_get_users(chat), TRUE);
+		users = purple_chat_conversation_get_users(chat);
+		pidgin_conv_chat_add_users(chat, users, TRUE);
+		g_list_free(users);



More information about the Commits mailing list