cpw.darkrain42.irc: 328f6948: Betterer IRC-channel-polling system (eas...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Mon Jul 13 02:15:52 EDT 2009


-----------------------------------------------------------------
Revision: 328f69486b6578b8a6283431138311f7b594acc6
Ancestor: b11c8c30fb9d2f025bb83e1e3b75bdcceea68793
Author: darkrain42 at pidgin.im
Date: 2009-07-13T06:11:50
Branch: im.pidgin.cpw.darkrain42.irc
URL: http://d.pidgin.im/viewmtn/revision/info/328f69486b6578b8a6283431138311f7b594acc6

Modified files:
        libpurple/protocols/irc/irc.c libpurple/protocols/irc/irc.h
        libpurple/protocols/irc/msgs.c

ChangeLog: 

Betterer IRC-channel-polling system (easier on the network).

On a five minute timer, initiate a poll of each channel we're in in
series (with a 15-25 second delay between the start of each). After
the WHO series is done (or if the user is in no channels), check
again in five minutes.

-------------- next part --------------
============================================================
--- libpurple/protocols/irc/irc.c	1b243cc0c5402a6062c325bfae37170c92a66399
+++ libpurple/protocols/irc/irc.c	6a6cb3ee824f14ed3d88968799a8e89499635f3f
@@ -218,26 +218,57 @@ static void irc_buddy_append(char *name,
 	g_string_append_printf(string, "%s ", name);
 }
 
-static void irc_who_channel(PurpleConversation *conv, struct irc_conn *irc)
+gboolean irc_who_channel(struct irc_conn *irc)
 {
-	if (purple_conversation_get_account(conv) == irc->account &&
-			purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) {
-		char *buf = irc_format(irc, "vc", "WHO",
-		                       purple_conversation_get_name(conv));
+	PurpleConversation *conv;
+	char *buf;
 
-		purple_debug_info("irc", "Performing periodic who on %s",
+	if (irc->who_channel_list) {
+		conv = irc->who_channel_list->data;
+
+		buf = irc_format(irc, "vc", "WHO",
+		                 purple_conversation_get_name(conv));
+
+		purple_debug_info("irc", "Performing periodic WHO on %s\n",
 		                  purple_conversation_get_name(conv));
 		irc_send(irc, buf);
 		g_free(buf);
+
+		irc->who_channel_timer = 0;
+		irc_who_channel_remove(irc, conv);
+	} else {
+		GList *chats;
+		GList *channels = NULL;
+
+		chats = purple_get_chats();
+		for ( ; chats; chats = chats->next) {
+			if (irc->account == purple_conversation_get_account(chats->data))
+				channels = g_list_prepend(channels, chats->data);
+		}
+
+		irc->who_channel_list = channels;
+		if (channels) {
+			/* Start the WHOing now */
+			irc_who_channel(irc);
+		} else {
+			/* Look again later... */
+			irc->who_channel_timer = purple_timeout_add_seconds(307, (GSourceFunc)irc_who_channel, irc);
+		}
 	}
+
+	return FALSE;
 }
 
-gboolean irc_who_channel_timeout(struct irc_conn *irc)
+void irc_who_channel_remove(struct irc_conn *irc, PurpleConversation *convo)
 {
-	/* WHO all of our channels. */
-	g_list_foreach(purple_get_chats(), (GFunc)irc_who_channel, (gpointer)irc);
+	irc->who_channel_list = g_list_remove(irc->who_channel_list, convo);
 
-	return TRUE;
+	if (irc->who_channel_timer == 0) {
+		if (irc->who_channel_list)
+			irc->who_channel_timer = purple_timeout_add_seconds(g_random_int_range(15, 25), (GSourceFunc)irc_who_channel, irc);
+		else
+			irc->who_channel_timer = purple_timeout_add_seconds(307, (GSourceFunc)irc_who_channel, irc);
+	}
 }
 
 static void irc_ison_one(struct irc_conn *irc, struct irc_buddy *ib)
@@ -522,6 +553,8 @@ static void irc_close(PurpleConnection *
 		purple_timeout_remove(irc->timer);
 	if (irc->who_channel_timer)
 		purple_timeout_remove(irc->who_channel_timer);
+	if (irc->who_channel_list)
+		g_list_free(irc->who_channel_list);
 	g_hash_table_destroy(irc->cmds);
 	g_hash_table_destroy(irc->msgs);
 	g_hash_table_destroy(irc->buddies);
@@ -755,6 +788,8 @@ static void irc_chat_leave (PurpleConnec
 	args[1] = NULL;
 	irc_cmd_part(irc, "part", purple_conversation_get_name(convo), args);
 	serv_got_chat_left(gc, id);
+
+	irc_who_channel_remove(irc, convo);
 }
 
 static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags)
============================================================
--- libpurple/protocols/irc/irc.h	9265c6d6c49780c0152e3401dfb5f31c7de9545c
+++ libpurple/protocols/irc/irc.h	c76f131949cb34373a99d0fdba882e3b6d0160d6
@@ -26,6 +26,7 @@
 #include <glib.h>
 
 #include "circbuffer.h"
+#include "conversation.h"
 #include "ft.h"
 #include "roomlist.h"
 #include "sslconn.h"
@@ -57,6 +58,7 @@ struct irc_conn {
 	guint timer;
 	guint who_channel_timer;
 	GHashTable *buddies;
+	GList *who_channel_list;
 
 	gboolean ison_outstanding;
 
@@ -104,7 +106,8 @@ gboolean irc_blist_timeout(struct irc_co
 
 int irc_send(struct irc_conn *irc, const char *buf);
 gboolean irc_blist_timeout(struct irc_conn *irc);
-gboolean irc_who_channel_timeout(struct irc_conn *irc);
+gboolean irc_who_channel(struct irc_conn *irc);
+void irc_who_channel_remove(struct irc_conn *irc, PurpleConversation *conv);
 
 char *irc_escape_privmsg(const char *text, gssize length);
 
============================================================
--- libpurple/protocols/irc/msgs.c	09951cfe70ac9191ac758360483a9b8caa26c34f
+++ libpurple/protocols/irc/msgs.c	5cc359bb200f2c80f5764b8d9840c60460f787ef
@@ -111,7 +111,7 @@ static void irc_connected(struct irc_con
 	if (!irc->timer)
 		irc->timer = purple_timeout_add_seconds(47, (GSourceFunc)irc_blist_timeout, (gpointer)irc);
 	if (!irc->who_channel_timer)
-		irc->who_channel_timer = purple_timeout_add_seconds(307, (GSourceFunc)irc_who_channel_timeout, (gpointer)irc);
+		irc->who_channel_timer = purple_timeout_add_seconds(307, (GSourceFunc)irc_who_channel, (gpointer)irc);
 }
 
 void irc_msg_default(struct irc_conn *irc, const char *name, const char *from, char **args)
@@ -929,6 +929,7 @@ void irc_msg_kick(struct irc_conn *irc, 
 		purple_conv_chat_write(PURPLE_CONV_CHAT(convo), args[0], buf, PURPLE_MESSAGE_SYSTEM, time(NULL));
 		g_free(buf);
 		serv_got_chat_left(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)));
+		irc_who_channel_remove(irc, convo);
 	} else {
 		buf = g_strdup_printf(_("Kicked by %s (%s)"), nick, args[2]);
 		purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), args[1], buf);
@@ -1145,6 +1146,7 @@ void irc_msg_part(struct irc_conn *irc, 
 		purple_conv_chat_write(PURPLE_CONV_CHAT(convo), channel, msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
 		g_free(msg);
 		serv_got_chat_left(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(convo)));
+		irc_who_channel_remove(irc, convo);
 	} else {
 		msg = args[1] ? irc_mirc2txt(args[1]) : NULL;
 		purple_conv_chat_remove_user(PURPLE_CONV_CHAT(convo), nick, msg);


More information about the Commits mailing list