# HG changeset patch
# Node ID a9887df166bb
# Parent  fe16c4d773b4
diff --git a/libpurple/protocols/ircv3/purpleircv3connection.c b/libpurple/protocols/ircv3/purpleircv3connection.c
--- a/libpurple/protocols/ircv3/purpleircv3connection.c
+++ b/libpurple/protocols/ircv3/purpleircv3connection.c
@@ -20,6 +20,7 @@
 
 #include "purpleircv3connection.h"
 
+#include "purpleircv3constants.h"
 #include "purpleircv3core.h"
 #include "purpleircv3formatting.h"
 #include "purpleircv3parser.h"
@@ -117,6 +118,32 @@
 	purple_ircv3_connection_writef(connection, "NICK %s", nickname);
 }
 
+static void
+purple_ircv3_connection_rejoin_channels(PurpleIRCv3Connection *connection) {
+	PurpleAccount *account = NULL;
+	PurpleConversationManager *manager = NULL;
+	GList *conversations = NULL;
+
+	account = purple_connection_get_account(PURPLE_CONNECTION(connection));
+	manager = purple_conversation_manager_get_default();
+
+	conversations = purple_conversation_manager_get_all(manager);
+	while(conversations != NULL) {
+		PurpleConversation *conversation = conversations->data;
+		PurpleAccount *conv_account = NULL;
+
+		conv_account = purple_conversation_get_account(conversation);
+		if(conv_account == account) {
+			const char *id = purple_conversation_get_id(conversation);
+
+			purple_ircv3_connection_writef(connection, "%s %s",
+			                               PURPLE_IRCV3_MSG_JOIN, id);
+		}
+
+		conversations = g_list_delete_link(conversations, conversations);
+	}
+}
+
 /******************************************************************************
  * Callbacks
  *****************************************************************************/
@@ -263,6 +290,11 @@
 	priv->registered = TRUE;
 
 	g_signal_emit(connection, signals[SIG_REGISTRATION_COMPLETE], 0);
+
+	/* Now that registration is complete, rejoin any channels that the
+	 * conversation manager has for us.
+	 */
+	purple_ircv3_connection_rejoin_channels(connection);
 }
 
 /******************************************************************************
diff --git a/libpurple/protocols/ircv3/purpleircv3constants.h b/libpurple/protocols/ircv3/purpleircv3constants.h
--- a/libpurple/protocols/ircv3/purpleircv3constants.h
+++ b/libpurple/protocols/ircv3/purpleircv3constants.h
@@ -69,7 +69,7 @@
 #define PURPLE_IRCV3_ERR_SASLTOOLONG ("905") PURPLE_IRCV3_AVAILABLE_MACRO_IN_3_0
 
 /**
- * PURPLE_IRCV_MSG_AUTHENTICATE:
+ * PURPLE_IRCV3_MSG_AUTHENTICATE:
  *
  * A constant for the IRC %AUTHENTICATE message.
  *
@@ -78,7 +78,7 @@
 #define PURPLE_IRCV3_MSG_AUTHENTICATE ("AUTHENTICATE") PURPLE_IRCV3_AVAILABLE_MACRO_IN_3_0
 
 /**
- * PURPLE_IRCV_MSG_CAP:
+ * PURPLE_IRCV3_MSG_CAP:
  *
  * A constant for the IRC %CAP message.
  *
@@ -87,6 +87,15 @@
 #define PURPLE_IRCV3_MSG_CAP ("CAP") PURPLE_IRCV3_AVAILABLE_MACRO_IN_3_0
 
 /**
+ * PURPLE_IRCV3_MSG_JOIN:
+ *
+ * A constant for the IRC %JOIN message.
+ *
+ * Since: 3.0.0
+ */
+#define PURPLE_IRCV3_MSG_JOIN ("JOIN") PURPLE_IRCV3_AVAILABLE_MACRO_IN_3_0
+
+/**
  * PURPLE_IRCV3_MSG_NOTICE:
  *
  * A constant for the IRC %NOTICE message.
diff --git a/libpurple/protocols/ircv3/purpleircv3protocolconversation.c b/libpurple/protocols/ircv3/purpleircv3protocolconversation.c
--- a/libpurple/protocols/ircv3/purpleircv3protocolconversation.c
+++ b/libpurple/protocols/ircv3/purpleircv3protocolconversation.c
@@ -21,6 +21,7 @@
 #include "purpleircv3protocolconversation.h"
 
 #include "purpleircv3connection.h"
+#include "purpleircv3constants.h"
 #include "purpleircv3core.h"
 
 /******************************************************************************
@@ -126,8 +127,8 @@
 	}
 
 	/* Build our join string. */
-	cmd = g_string_new("JOIN ");
-	g_string_append_printf(cmd, "%s", name);
+	cmd = g_string_new(NULL);
+	g_string_append_printf(cmd, "%s %s", PURPLE_IRCV3_MSG_JOIN, name);
 
 	password = purple_channel_join_details_get_password(details);
 	if(!purple_strempty(password)) {
diff --git a/libpurple/protocols/ircv3/tests/test_ircv3_parser.c b/libpurple/protocols/ircv3/tests/test_ircv3_parser.c
--- a/libpurple/protocols/ircv3/tests/test_ircv3_parser.c
+++ b/libpurple/protocols/ircv3/tests/test_ircv3_parser.c
@@ -324,7 +324,7 @@
 test_purple_ircv3_last_param_no_colon(void) {
 	TestPurpleIRCv3ParserData data = {
 		.source = "src",
-		.command = "JOIN",
+		.command = PURPLE_IRCV3_MSG_JOIN,
 		.n_params = 1,
 		.params = {"#chan"},
 	};
@@ -336,7 +336,7 @@
 test_purple_ircv3_last_param_with_colon(void) {
 	TestPurpleIRCv3ParserData data = {
 		.source = "src",
-		.command = "JOIN",
+		.command = PURPLE_IRCV3_MSG_JOIN,
 		.n_params = 1,
 		.params = {"#chan"},
 	};
