/soc/2013/ankitkv/gobjectification: 9336815f86b6: Refactored the...

Ankit Vani a at nevitus.org
Fri Jul 12 04:49:29 EDT 2013


Changeset: 9336815f86b632fd3875d7d0cb573a889bf0d8bf
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-12 14:18 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/9336815f86b6

Description:

Refactored the remaining libpurple to use the initial GObject connection API
* Added _purple_connection_add_active_chat() to internal.h
* Added _purple_connection_remove_active_chat() to internal.h

diffstat:

 libpurple/connection.c   |  20 ++++++++++++++++++++
 libpurple/conversation.c |   2 +-
 libpurple/internal.h     |  23 +++++++++++++++++++++++
 libpurple/server.c       |  10 +++++-----
 4 files changed, 49 insertions(+), 6 deletions(-)

diffs (114 lines):

diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -372,6 +372,26 @@ purple_connection_get_protocol_data(cons
 }
 
 void
+_purple_connection_add_active_chat(PurpleConnection *gc, PurpleChatConversation *chat)
+{
+	PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
+	g_return_if_fail(priv != NULL);
+
+	priv->active_chats = g_slist_append(priv->active_chats, chat);
+}
+
+void
+_purple_connection_remove_active_chat(PurpleConnection *gc, PurpleChatConversation *chat)
+{
+	PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
+	g_return_if_fail(priv != NULL);
+
+	priv->active_chats = g_slist_remove(priv->active_chats, chat);
+}
+
+void
 purple_connection_update_progress(PurpleConnection *gc, const char *text,
 								size_t step, size_t count)
 {
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -500,7 +500,7 @@ purple_conversation_write(PurpleConversa
 		gc = purple_account_get_connection(account);
 
 	if (PURPLE_IS_CHAT_CONVERSATION(conv) &&
-		(gc != NULL && !g_slist_find(gc->buddy_chats, conv)))
+		(gc != NULL && !g_slist_find(purple_connection_get_active_chats(gc), conv)))
 		return;
 
 	if (PURPLE_IS_IM_CONVERSATION(conv) &&
diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -212,4 +212,27 @@ void _purple_connection_new_unregister(P
  */
 gboolean _purple_connection_wants_to_die(const PurpleConnection *gc);
 
+/**
+ * Adds a chat to the active chats list of a connection
+ *
+ * @note This function should only be called by serv_got_joined_chat()
+ *       in server.c.
+ *
+ * @param gc    The connection
+ * @param chat  The chat conversation to add
+ */
+void _purple_connection_add_active_chat(PurpleConnection *gc,
+                                        PurpleChatConversation *chat);
+/**
+ * Removes a chat from the active chats list of a connection
+ *
+ * @note This function should only be called by serv_got_chat_left()
+ *       in server.c.
+ *
+ * @param gc    The connection
+ * @param chat  The chat conversation to remove
+ */
+void _purple_connection_remove_active_chat(PurpleConnection *gc,
+                                           PurpleChatConversation *chat);
+
 #endif /* _PURPLE_INTERNAL_H_ */
diff --git a/libpurple/server.c b/libpurple/server.c
--- a/libpurple/server.c
+++ b/libpurple/server.c
@@ -825,8 +825,8 @@ PurpleChatConversation *serv_got_joined_
 	chat = purple_chat_conversation_new(account, name);
 	g_return_val_if_fail(chat != NULL, NULL);
 
-	if (!g_slist_find(gc->buddy_chats, PURPLE_CONVERSATION(chat)))
-		gc->buddy_chats = g_slist_append(gc->buddy_chats, PURPLE_CONVERSATION(chat));
+	if (!g_slist_find(purple_connection_get_active_chats(gc), chat))
+		_purple_connection_add_active_chat(gc, chat);
 
 	purple_chat_conversation_set_id(chat, id);
 
@@ -840,7 +840,7 @@ void serv_got_chat_left(PurpleConnection
 	GSList *bcs;
 	PurpleChatConversation *chat = NULL;
 
-	for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) {
+	for (bcs = purple_connection_get_active_chats(g); bcs != NULL; bcs = bcs->next) {
 		chat = PURPLE_CHAT_CONVERSATION(bcs->data);
 
 		if (purple_chat_conversation_get_id(chat) == id)
@@ -850,7 +850,7 @@ void serv_got_chat_left(PurpleConnection
 	purple_debug(PURPLE_DEBUG_INFO, "server", "Leaving room: %s\n",
 			   purple_conversation_get_name(PURPLE_CONVERSATION(chat)));
 
-	g->buddy_chats = g_slist_remove(g->buddy_chats, chat);
+	_purple_connection_remove_active_chat(g, chat);
 
 	purple_chat_conversation_leave(chat);
 
@@ -874,7 +874,7 @@ void serv_got_chat_in(PurpleConnection *
 	g_return_if_fail(who != NULL);
 	g_return_if_fail(message != NULL);
 
-	for (bcs = g->buddy_chats; bcs != NULL; bcs = bcs->next) {
+	for (bcs = purple_connection_get_active_chats(g); bcs != NULL; bcs = bcs->next) {
 		chat = PURPLE_CHAT_CONVERSATION(bcs->data);
 
 		if (purple_chat_conversation_get_id(chat) == id)



More information about the Commits mailing list