changeset 28132:eb2d17945ce3

jabber: Store the "own JabberBuddy" in the JabberStream* struct. This simplifies the roster code a little (don't need to recalculate our own JID for string comparisons) and fixes a few FIXMEs in buddy.c.
author Paul Aurich <paul@darkrain42.org>
date Sat, 01 Aug 2009 22:12:30 +0000
parents 478a3866ea90
children 3eef8392a54b
files libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/buddy.h libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/protocols/jabber/roster.c
diffstat 5 files changed, 20 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Sat Aug 01 21:45:24 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Sat Aug 01 22:12:30 2009 +0000
@@ -1765,9 +1765,7 @@
 	if(!jb)
 		return m;
 
-	/* XXX: fix the NOT ME below */
-
-	if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) {
+	if (js->protocol_version == JABBER_PROTO_0_9 && jb != js->user_jb) {
 		if(jb->invisible & JABBER_INVIS_BUDDY) {
 			act = purple_menu_action_new(_("Un-hide From"),
 			                           PURPLE_CALLBACK(jabber_buddy_make_visible),
@@ -1780,7 +1778,7 @@
 		m = g_list_append(m, act);
 	}
 
-	if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) {
+	if(jb->subscription & JABBER_SUB_FROM && jb != js->user_jb) {
 		act = purple_menu_action_new(_("Cancel Presence Notification"),
 		                           PURPLE_CALLBACK(jabber_buddy_cancel_presence_notification),
 		                           NULL, NULL);
@@ -1793,7 +1791,7 @@
 		                           NULL, NULL);
 		m = g_list_append(m, act);
 
-	} else /* if(NOT ME) */{
+	} else if (jb != js->user_jb) {
 
 		/* shouldn't this just happen automatically when the buddy is
 		   removed? */
--- a/libpurple/protocols/jabber/buddy.h	Sat Aug 01 21:45:24 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.h	Sat Aug 01 22:12:30 2009 +0000
@@ -33,10 +33,12 @@
 	JABBER_BUDDY_STATE_DND
 } JabberBuddyState;
 
+typedef struct _JabberBuddy JabberBuddy;
+
 #include "jabber.h"
 #include "caps.h"
 
-typedef struct _JabberBuddy {
+struct _JabberBuddy {
 	GList *resources;
 	char *error_msg;
 	enum {
@@ -52,7 +54,7 @@
 		JABBER_SUB_BOTH    = (JABBER_SUB_TO | JABBER_SUB_FROM),
 		JABBER_SUB_REMOVE  = 1 << 4
 	} subscription;
-} JabberBuddy;
+};
 
 typedef struct _JabberAdHocCommands {
 	char *jid;
--- a/libpurple/protocols/jabber/jabber.c	Sat Aug 01 21:45:24 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Aug 01 22:12:30 2009 +0000
@@ -132,7 +132,6 @@
 		xmlnode *jid;
 		char *full_jid;
 		if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) {
-			JabberBuddy *my_jb;
 			jabber_id_free(js->user);
 
 			js->user = jabber_id_new(full_jid);
@@ -144,9 +143,8 @@
 				return;
 			}
 
-			my_jb = jabber_buddy_find(js, full_jid, TRUE);
-			if (my_jb)
-				my_jb->subscription |= JABBER_SUB_BOTH;
+			js->user_jb = jabber_buddy_find(js, full_jid, TRUE);
+			js->user_jb->subscription |= JABBER_SUB_BOTH;
 
 			purple_connection_set_display_name(js->gc, full_jid);
 
@@ -781,7 +779,6 @@
 {
 	PurpleConnection *gc = purple_account_get_connection(account);
 	JabberStream *js;
-	JabberBuddy *my_jb;
 	PurplePresence *presence;
 	gchar *user;
 	gchar *slash;
@@ -816,9 +813,9 @@
 	js->buddies = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, (GDestroyNotify)jabber_buddy_free);
 
-	my_jb = jabber_buddy_find(js, user, TRUE);
+	js->user_jb = jabber_buddy_find(js, user, TRUE);
 	g_free(user);
-	if (!my_jb) {
+	if (!js->user_jb) {
 		/* This basically *can't* fail, but for good measure... */
 		purple_connection_error_reason(gc,
 			PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
@@ -827,7 +824,7 @@
 		g_return_val_if_reached(NULL);
 	}
 
-	my_jb->subscription |= JABBER_SUB_BOTH;
+	js->user_jb->subscription |= JABBER_SUB_BOTH;
 
 	js->iq_callbacks = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, g_free);
--- a/libpurple/protocols/jabber/jabber.h	Sat Aug 01 21:45:24 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Sat Aug 01 22:12:30 2009 +0000
@@ -164,6 +164,8 @@
 	time_t old_idle;
 
 	JabberID *user;
+	JabberBuddy *user_jb;
+
 	PurpleConnection *gc;
 	PurpleSslConnection *gsc;
 
--- a/libpurple/protocols/jabber/roster.c	Sat Aug 01 21:45:24 2009 +0000
+++ b/libpurple/protocols/jabber/roster.c	Sat Aug 01 22:12:30 2009 +0000
@@ -66,7 +66,7 @@
 }
 
 static void add_purple_buddy_to_groups(JabberStream *js, const char *jid,
-		const char *alias, GSList *groups, const char *own_jid)
+		const char *alias, GSList *groups)
 {
 	GSList *buddies, *l;
 	GSList *pool = NULL;
@@ -162,12 +162,6 @@
 		purple_blist_add_buddy(b, NULL, g, NULL);
 		purple_blist_alias_buddy(b, alias);
 
-		/* If we just learned about ourself, then fake our status,
-		 * because we won't be receiving a normal presence message
-		 * about ourself. */
-		if(!strcmp(purple_buddy_get_name(b), own_jid))
-			jabber_presence_fake_to_self(js, NULL);
-
 		g_free(groups->data);
 		groups = g_slist_delete_link(groups, groups);
 	}
@@ -187,7 +181,6 @@
                          JabberIqType type, const char *id, xmlnode *query)
 {
 	xmlnode *item, *group;
-	gchar *own_jid;
 
 	if (!jabber_is_own_account(js, from)) {
 		purple_debug_warning("jabber", "Received bogon roster push from %s\n",
@@ -197,8 +190,6 @@
 
 	js->currently_parsing_roster_push = TRUE;
 
-	own_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
-
 	for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item))
 	{
 		const char *jid, *name, *subscription, *ask;
@@ -216,11 +207,7 @@
 			continue;
 
 		if(subscription) {
-			gboolean me = FALSE;
-
-			me = g_str_equal(own_jid, jabber_normalize(js->gc->account, jid));
-
-			if(me)
+			if (jb == js->user_jb)
 				jb->subscription = JABBER_SUB_BOTH;
 			else if(!strcmp(subscription, "none"))
 				jb->subscription = JABBER_SUB_NONE;
@@ -260,11 +247,12 @@
 				groups = g_slist_prepend(groups, group_name);
 			}
 
-			add_purple_buddy_to_groups(js, jid, name, groups, own_jid);
+			add_purple_buddy_to_groups(js, jid, name, groups);
+			if (jb == js->user_jb)
+				jabber_presence_fake_to_self(js, NULL);
 		}
 	}
 
-	g_free(own_jid);
 	js->currently_parsing_roster_push = FALSE;
 
 	/* if we're just now parsing the roster for the first time,
@@ -348,7 +336,6 @@
 	char *who;
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr;
-	char *own_jid;
 	const char *name;
 
 	/* If we haven't received the roster yet, ignore any adds */
@@ -366,8 +353,7 @@
 
 	jabber_roster_update(js, who, NULL);
 
-	own_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
-	if (g_str_equal(who, own_jid)) {
+	if (jb == js->user_jb) {
 		jabber_presence_fake_to_self(js, NULL);
 	} else if(!jb || !(jb->subscription & JABBER_SUB_TO)) {
 		jabber_presence_subscription_set(js, who, "subscribe");
@@ -377,7 +363,6 @@
 				"priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL);
 	}
 
-	g_free(own_jid);
 	g_free(who);
 }