changeset 20053:fb2880587f34

If there's a chat open when an account gets disconnected because of an error, then try to rejoin that chat after the account gets back online. I'll see how this goes here, if it goes well, we can do the same in pidgin. References #104.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 15 Sep 2007 09:53:30 +0000
parents f6abebd4d0ff
children 505fc3b20c40
files finch/gntconn.c finch/gntconv.c
diffstat 2 files changed, 46 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntconn.c	Sat Sep 15 08:22:15 2007 +0000
+++ b/finch/gntconn.c	Sat Sep 15 09:53:30 2007 +0000
@@ -104,10 +104,11 @@
 {
 	FinchAutoRecon *info;
 	PurpleAccount *account = purple_connection_get_account(gc);
-
-	info = g_hash_table_lookup(hash, account);
+	GList *list;
 
 	if (!gc->wants_to_die) {
+		info = g_hash_table_lookup(hash, account);
+
 		if (info == NULL) {
 			info = g_new0(FinchAutoRecon, 1);
 			g_hash_table_insert(hash, account, info);
@@ -140,6 +141,17 @@
 		g_free(secondary);
 		purple_account_set_enabled(account, FINCH_UI, FALSE);
 	}
+
+	/* If we have any open chats, we probably want to rejoin when we get back online. */
+	list = purple_get_chats();
+	while (list) {
+		PurpleConversation *conv = list->data;
+		list = list->next;
+		if (conv->account != account ||
+				purple_conv_chat_has_left(PURPLE_CONV_CHAT(conv)))
+			continue;
+		purple_conversation_set_data(conv, "want-to-rejoin", GINT_TO_POINTER(TRUE));
+	}
 }
 
 static void
--- a/finch/gntconv.c	Sat Sep 15 08:22:15 2007 +0000
+++ b/finch/gntconv.c	Sat Sep 15 09:53:30 2007 +0000
@@ -310,13 +310,41 @@
 static void
 account_signed_on_off(PurpleConnection *gc, gpointer null)
 {
-	GList *ims = purple_get_ims();
-	while (ims) {
-		PurpleConversation *conv = ims->data;
+	GList *list = purple_get_ims();
+	while (list) {
+		PurpleConversation *conv = list->data;
 		PurpleConversation *cc = find_conv_with_contact(conv->account, conv->name);
 		if (cc)
 			generate_send_to_menu(cc->ui_data);
-		ims = ims->next;
+		list = list->next;
+	}
+
+	if (PURPLE_CONNECTION_IS_CONNECTED(gc)) {
+		/* We just signed on. Let's see if there's any chat that we have open,
+		 * and hadn't left before the disconnect. */
+		list = purple_get_chats();
+		while (list) {
+			PurpleConversation *conv = list->data;
+			gboolean del = FALSE;
+			PurpleChat *chat;
+
+			list = list->next;
+			if (conv->account != gc->account ||
+					!purple_conversation_get_data(conv, "want-to-rejoin"))
+				continue;
+
+			chat = purple_blist_find_chat(conv->account, conv->name);
+			if (chat == NULL) {
+				GHashTable *hash = NULL;
+				if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL)
+					hash = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, conv->name);
+				chat = purple_chat_new(gc->account, conv->name, hash);
+				del = TRUE;
+			}
+			serv_join_chat(gc, chat->components);
+			if (del)
+				purple_blist_remove_chat(chat);
+		}
 	}
 }