/pidgin/main: 1ae6f7c41db3: Implement purple_chat_conversation_g...

Tomasz Wasilczyk twasilczyk at pidgin.im
Tue Mar 18 08:11:13 EDT 2014


Changeset: 1ae6f7c41db3f01d925683b68070f2afd690c82f
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-03-18 13:11 +0100
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/1ae6f7c41db3

Description:

Implement purple_chat_conversation_get_users_count and use it instead of counting the list

diffstat:

 libpurple/conversationtypes.c |  10 ++++++++++
 libpurple/conversationtypes.h |  11 +++++++++++
 libpurple/plugins/joinpart.c  |   2 +-
 pidgin/gtkblist.c             |   2 +-
 pidgin/gtkconv.c              |   4 ++--
 5 files changed, 25 insertions(+), 4 deletions(-)

diffs (86 lines):

diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -620,6 +620,16 @@ purple_chat_conversation_get_users(const
 	return priv->in_room;
 }
 
+guint
+purple_chat_conversation_get_users_count(const PurpleChatConversation *chat)
+{
+	PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(chat);
+
+	g_return_val_if_fail(priv != NULL, 0);
+
+	return g_hash_table_size(priv->users);
+}
+
 void
 purple_chat_conversation_ignore(PurpleChatConversation *chat, const char *name)
 {
diff --git a/libpurple/conversationtypes.h b/libpurple/conversationtypes.h
--- a/libpurple/conversationtypes.h
+++ b/libpurple/conversationtypes.h
@@ -385,6 +385,17 @@ PurpleChatConversation *purple_chat_conv
 GList *purple_chat_conversation_get_users(const PurpleChatConversation *chat);
 
 /**
+ * purple_chat_conversation_get_users_count:
+ * @chat: The chat.
+ *
+ * Returns count of users in the chat room.
+ *
+ * Returns: The count of users in the chat room.
+ */
+guint
+purple_chat_conversation_get_users_count(const PurpleChatConversation *chat);
+
+/**
  * purple_chat_conversation_ignore:
  * @chat: The chat.
  * @name: The name of the user.
diff --git a/libpurple/plugins/joinpart.c b/libpurple/plugins/joinpart.c
--- a/libpurple/plugins/joinpart.c
+++ b/libpurple/plugins/joinpart.c
@@ -90,7 +90,7 @@ static gboolean should_hide_notice(Purpl
 	/* If the room is small, don't bother. */
 	chat = PURPLE_CHAT_CONVERSATION(conv);
 	threshold = purple_prefs_get_int(THRESHOLD_PREF);
-	if (g_list_length(purple_chat_conversation_get_users(chat)) < threshold)
+	if (purple_chat_conversation_get_users_count(chat) < threshold)
 		return FALSE;
 
 	if (!purple_prefs_get_bool(HIDE_BUDDIES_PREF) &&
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -3841,7 +3841,7 @@ static char *pidgin_get_tooltip_text(Pur
 
 		if (conv && !purple_chat_conversation_has_left(conv)) {
 			g_string_append_printf(str, _("\n<b>Occupants:</b> %d"),
-					g_list_length(purple_chat_conversation_get_users(conv)));
+				purple_chat_conversation_get_users_count(conv));
 
 			if (prpl_info && (prpl_info->options & OPT_PROTO_CHAT_TOPIC)) {
 				const char *chattopic = purple_chat_conversation_get_topic(conv);
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -7028,7 +7028,7 @@ pidgin_conv_chat_add_users(PurpleChatCon
 	gtkconv = PIDGIN_CONVERSATION(PURPLE_CONVERSATION(chat));
 	gtkchat = gtkconv->u.chat;
 
-	num_users = g_list_length(purple_chat_conversation_get_users(chat));
+	num_users = purple_chat_conversation_get_users_count(chat);
 
 	g_snprintf(tmp, sizeof(tmp),
 			   ngettext("%d person in room", "%d people in room",
@@ -7114,7 +7114,7 @@ pidgin_conv_chat_remove_users(PurpleChat
 	gtkconv = PIDGIN_CONVERSATION(PURPLE_CONVERSATION(chat));
 	gtkchat = gtkconv->u.chat;
 
-	num_users = g_list_length(purple_chat_conversation_get_users(chat));
+	num_users = purple_chat_conversation_get_users_count(chat);
 
 	for (l = users; l != NULL; l = l->next) {
 		model = gtk_tree_view_get_model(GTK_TREE_VIEW(gtkchat->list));



More information about the Commits mailing list