changeset 27573:9a5a9a4e7626

Simplify the fake_to_self function. The majority of the changes are indentation (since I don't expect the jabber_buddy_find to fail, it's now a g_return_if_fail).
author Paul Aurich <paul@darkrain42.org>
date Sun, 07 Jun 2009 06:17:29 +0000
parents e3c2c3e72d7a
children ff640fedbfde
files libpurple/protocols/jabber/presence.c libpurple/protocols/jabber/presence.h libpurple/protocols/jabber/roster.c
diffstat 3 files changed, 34 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/presence.c	Sun Jun 07 06:12:22 2009 +0000
+++ b/libpurple/protocols/jabber/presence.c	Sun Jun 07 06:17:29 2009 +0000
@@ -59,38 +59,44 @@
 	g_free(chat_full_jid);
 }
 
-void jabber_presence_fake_to_self(JabberStream *js, const PurpleStatus *gstatus) {
-	char *my_base_jid;
+void jabber_presence_fake_to_self(JabberStream *js, PurpleStatus *status)
+{
+	PurpleAccount *account;
+	const char *username;
 
-	if(!js->user)
-		return;
+	g_return_if_fail(js->user != NULL);
 
-	my_base_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
-	if(purple_find_buddy(js->gc->account, my_base_jid)) {
-		JabberBuddy *jb;
+	account = purple_connection_get_account(js->gc);
+	username = purple_account_get_username(account);
+	if (status == NULL)
+		status = purple_account_get_active_status(account);
+
+	if (purple_find_buddy(account, username)) {
+		JabberBuddy *jb = jabber_buddy_find(js, username, TRUE);
 		JabberBuddyResource *jbr;
-		if((jb = jabber_buddy_find(js, my_base_jid, TRUE))) {
-			JabberBuddyState state;
-			char *msg;
-			int priority;
+		JabberBuddyState state;
+		char *msg;
+		int priority;
 
-			purple_status_to_jabber(gstatus, &state, &msg, &priority);
+		g_return_if_fail(jb != NULL);
+
+		purple_status_to_jabber(status, &state, &msg, &priority);
 
-			if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) {
-				jabber_buddy_remove_resource(jb, js->user->resource);
-			} else {
-				jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg);
-			}
-			if((jbr = jabber_buddy_find_resource(jb, NULL))) {
-				purple_prpl_got_user_status(js->gc->account, my_base_jid, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL);
-			} else {
-				purple_prpl_got_user_status(js->gc->account, my_base_jid, "offline", msg ? "message" : NULL, msg, NULL);
-			}
+		if (state == JABBER_BUDDY_STATE_UNAVAILABLE ||
+				state == JABBER_BUDDY_STATE_UNKNOWN) {
+			jabber_buddy_remove_resource(jb, js->user->resource);
+		} else {
+			jabber_buddy_track_resource(jb, js->user->resource, priority,
+			                            state, msg);
+		}
 
-			g_free(msg);
+		if ((jbr = jabber_buddy_find_resource(jb, NULL))) {
+			purple_prpl_got_user_status(js->gc->account, username, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL);
+		} else {
+			purple_prpl_got_user_status(js->gc->account, username, "offline", msg ? "message" : NULL, msg, NULL);
 		}
+		g_free(msg);
 	}
-	g_free(my_base_jid);
 }
 
 void jabber_set_status(PurpleAccount *account, PurpleStatus *status)
--- a/libpurple/protocols/jabber/presence.h	Sun Jun 07 06:12:22 2009 +0000
+++ b/libpurple/protocols/jabber/presence.h	Sun Jun 07 06:17:29 2009 +0000
@@ -42,7 +42,7 @@
 void jabber_presence_parse(JabberStream *js, xmlnode *packet);
 void jabber_presence_subscription_set(JabberStream *js, const char *who,
 		const char *type);
-void jabber_presence_fake_to_self(JabberStream *js, const PurpleStatus *status);
+void jabber_presence_fake_to_self(JabberStream *js, PurpleStatus *status);
 void purple_status_to_jabber(const PurpleStatus *status, JabberBuddyState *state, char **msg, int *priority);
 
 #endif /* PURPLE_JABBER_PRESENCE_H_ */
--- a/libpurple/protocols/jabber/roster.c	Sun Jun 07 06:12:22 2009 +0000
+++ b/libpurple/protocols/jabber/roster.c	Sun Jun 07 06:17:29 2009 +0000
@@ -132,16 +132,8 @@
 		/* 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), my_bare_jid)) {
-			PurplePresence *gpresence;
-			PurpleStatus *status;
-			PurpleAccount *account;
-
-			account = purple_connection_get_account(js->gc);
-			gpresence = purple_account_get_presence(account);
-			status = purple_presence_get_active_status(gpresence);
-			jabber_presence_fake_to_self(js, status);
-		}
+		if(!strcmp(purple_buddy_get_name(b), my_bare_jid))
+			jabber_presence_fake_to_self(js, NULL);
 
 		g_free(groups->data);
 		groups = g_slist_delete_link(groups, groups);
@@ -356,12 +348,7 @@
 
 	my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
 	if(!strcmp(who, my_bare_jid)) {
-		PurplePresence *gpresence;
-		PurpleStatus *status;
-
-		gpresence = purple_account_get_presence(js->gc->account);
-		status = purple_presence_get_active_status(gpresence);
-		jabber_presence_fake_to_self(js, status);
+		jabber_presence_fake_to_self(js, NULL);
 	} else if(!jb || !(jb->subscription & JABBER_SUB_TO)) {
 		jabber_presence_subscription_set(js, who, "subscribe");
 	} else if((jbr =jabber_buddy_find_resource(jb, NULL))) {