changeset 18691:54a5fbeadd7c

Now showing ad-hoc commands of other clients connected to the same account in the account menu (per XEP-0146). Since it is becoming messy in that menu, I also prefixed all ad-hoc commands with the node this command belongs to in [], which is the resource name for clients and the domain name for the server. Examples: "[home] Set status" for clients and "[jabber.org] Send message to all connected users" for servers.
author Andreas Monitzer <pidgin@monitzer.com>
date Fri, 13 Jul 2007 15:34:16 +0000
parents fdd07827ecb1
children f02902d2f00b
files libpurple/protocols/jabber/adhoccommands.c libpurple/protocols/jabber/presence.c
diffstat 2 files changed, 37 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/adhoccommands.c	Thu Jul 12 03:24:55 2007 +0000
+++ b/libpurple/protocols/jabber/adhoccommands.c	Fri Jul 13 15:34:16 2007 +0000
@@ -262,11 +262,34 @@
 
 void jabber_adhoc_init_server_commands(JabberStream *js, GList **m) {
 	GList *cmdlst;
+	JabberBuddy *jb;
 	
+	/* also add commands for other clients connected to the same account on another resource */
+	char *accountname = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
+	if((jb = jabber_buddy_find(js, accountname, TRUE))) {
+		GList *iter;
+		for(iter = jb->resources; iter; iter = g_list_next(iter)) {
+			JabberBuddyResource *jbr = iter->data;
+			GList *riter;
+			for(riter = jbr->commands; riter; riter = g_list_next(riter)) {
+				JabberAdHocCommands *cmd = riter->data;
+				char *cmdname = g_strdup_printf("[%s] %s",jbr->name,cmd->name);
+				PurplePluginAction *act = purple_plugin_action_new(cmdname, jabber_adhoc_server_execute);
+				act->user_data = cmd;
+				*m = g_list_append(*m, act);
+				g_free(cmdname);
+			}
+		}
+	}
+	g_free(accountname);
+	
+	/* now add server commands */
 	for(cmdlst = js->commands; cmdlst; cmdlst = g_list_next(cmdlst)) {
 		JabberAdHocCommands *cmd = cmdlst->data;
-		PurplePluginAction *act = purple_plugin_action_new(cmd->name, jabber_adhoc_server_execute);
+		char *cmdname = g_strdup_printf("[%s] %s",js->user->domain,cmd->name);
+		PurplePluginAction *act = purple_plugin_action_new(cmdname, jabber_adhoc_server_execute);
 		act->user_data = cmd;
 		*m = g_list_append(*m, act);
+		g_free(cmdname);
 	}
 }
--- a/libpurple/protocols/jabber/presence.c	Thu Jul 12 03:24:55 2007 +0000
+++ b/libpurple/protocols/jabber/presence.c	Fri Jul 13 15:34:16 2007 +0000
@@ -655,18 +655,22 @@
 		g_free(room_jid);
 	} else {
 		buddy_name = g_strdup_printf("%s%s%s", jid->node ? jid->node : "",
-				jid->node ? "@" : "", jid->domain);
+									 jid->node ? "@" : "", jid->domain);
 		if((b = purple_find_buddy(js->gc->account, buddy_name)) == NULL) {
-			purple_debug_warning("jabber", "Got presence for unknown buddy %s on account %s (%x)\n",
-				buddy_name, purple_account_get_username(js->gc->account), js->gc->account);
-			jabber_id_free(jid);
-			g_free(avatar_hash);
-			g_free(buddy_name);
-			g_free(status);
-			return;
+			if(!jid->node || strcmp(jid->node,js->user->node) || strcmp(jid->domain,js->user->domain)) {
+				purple_debug_warning("jabber", "Got presence for unknown buddy %s on account %s (%x)\n",
+									 buddy_name, purple_account_get_username(js->gc->account), js->gc->account);
+				jabber_id_free(jid);
+				g_free(avatar_hash);
+				g_free(buddy_name);
+				g_free(status);
+				return;
+			} else {
+				/* this is a different resource of our own account. Resume even when this account isn't on our blist */
+			}
 		}
 
-		if(avatar_hash) {
+		if(b && avatar_hash) {
 			const char *avatar_hash2 = purple_buddy_icons_get_checksum_for_user(b);
 			if(!avatar_hash2 || strcmp(avatar_hash, avatar_hash2)) {
 				JabberIq *iq;