cpw.darkrain42.roster: 192cf9a4: Simplify the fake_to_self function.

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun Jun 7 02:25:42 EDT 2009


-----------------------------------------------------------------
Revision: 192cf9a4c78719d100adffeb17cb30bfbc2040df
Ancestor: 66b6d95f74ec8ccc300839e1089b489230b661fd
Author: darkrain42 at pidgin.im
Date: 2009-06-07T06:17:29
Branch: im.pidgin.cpw.darkrain42.roster
URL: http://d.pidgin.im/viewmtn/revision/info/192cf9a4c78719d100adffeb17cb30bfbc2040df

Modified files:
        libpurple/protocols/jabber/presence.c
        libpurple/protocols/jabber/presence.h
        libpurple/protocols/jabber/roster.c

ChangeLog: 

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).

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/presence.c	662161ab470b3230414ef616c1fc97676e0dcf81
+++ libpurple/protocols/jabber/presence.c	7181bcea07b87320c04f80ffa68b8574fe7d9db6
@@ -59,38 +59,44 @@ static void chats_send_presence_foreach(
 	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);
 
-			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);
-			}
+		purple_status_to_jabber(status, &state, &msg, &priority);
 
-			g_free(msg);
+		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, 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)
============================================================
--- libpurple/protocols/jabber/presence.h	5cb513bf29cd650f8a05a95c1d940d0b1800566d
+++ libpurple/protocols/jabber/presence.h	0238b82fbf3e46e86b38cbb08db4ef8929838d4c
@@ -42,7 +42,7 @@ void jabber_presence_subscription_set(Ja
 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_ */
============================================================
--- libpurple/protocols/jabber/roster.c	49ffaa61edfb406efef23bf4ecf4b5bd297a7be5
+++ libpurple/protocols/jabber/roster.c	f25e5dead825b0a80c435360dad4d46335a5c5c1
@@ -132,17 +132,9 @@ static void add_purple_buddy_to_groups(J
 		/* 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;
+		if(!strcmp(purple_buddy_get_name(b), my_bare_jid))
+			jabber_presence_fake_to_self(js, NULL);
 
-			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);
-		}
-
 		g_free(groups->data);
 		groups = g_slist_delete_link(groups, groups);
 	}
@@ -356,12 +348,7 @@ void jabber_roster_add_buddy(PurpleConne
 
 	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))) {


More information about the Commits mailing list