pidgin/pidgin

bf4beafd15a3
Parents cc095f9ce1f3
Children 8e8f223cdd5a
IRCv3: Reuse existing status window if it exists

Previously we were always creating a new status conversation during connection,
as you may have guessed this means you get a bunch of conversations when you
reconnect multiple times.

Testing Done:
Reconnected to my local ergo instance a few times and verified the status conversation was properly reused.

Reviewed at https://reviews.imfreedom.org/r/2828/
--- a/libpurple/protocols/ircv3/purpleircv3connection.c Thu Nov 16 23:50:35 2023 -0600
+++ b/libpurple/protocols/ircv3/purpleircv3connection.c Fri Nov 17 00:30:55 2023 -0600
@@ -428,6 +428,7 @@
PurpleIRCv3ConnectionPrivate *priv = NULL;
PurpleAccount *account = NULL;
PurpleContactInfo *info = NULL;
+ PurpleConversationManager *conversation_manager = NULL;
char **userparts = NULL;
const char *username = NULL;
char *title = NULL;
@@ -451,23 +452,31 @@
/* Free the userparts vector. */
g_strfreev(userparts);
- /* Create our status conversation. */
- priv->status_conversation = g_object_new(
- PURPLE_TYPE_CONVERSATION,
- "account", account,
- "name", priv->server_name,
- "title", title,
- NULL);
+ /* Check if we have an existing status conversation. */
+ conversation_manager = purple_conversation_manager_get_default();
+ priv->status_conversation = purple_conversation_manager_find_with_id(conversation_manager,
+ account,
+ priv->server_name);
+
+ if(!PURPLE_IS_CONVERSATION(priv->status_conversation)) {
+ /* Create our status conversation. */
+ priv->status_conversation = g_object_new(
+ PURPLE_TYPE_CONVERSATION,
+ "account", account,
+ "id", priv->server_name,
+ "name", priv->server_name,
+ "title", title,
+ NULL);
+
+ purple_conversation_manager_register(conversation_manager,
+ priv->status_conversation);
+ } else {
+ /* The conversation existed, so add a reference to it. */
+ g_object_ref(priv->status_conversation);
+ }
g_clear_pointer(&title, g_free);
- /* TODO later: add an account action that'll register and unregister this
- * with the conversation manager.
- */
- purple_conversation_manager_register(purple_conversation_manager_get_default(),
- priv->status_conversation);
-
-
/* Finally create our objects. */
priv->cancellable = g_cancellable_new();