pidgin.mxit: f447a1b5: Since a buddy's avatar information is di...

andrew.victor at mxit.com andrew.victor at mxit.com
Tue Jul 20 05:50:42 EDT 2010


----------------------------------------------------------------------
Revision: f447a1b5f9e414e5e9c976218c006288f967e565
Parent:   4639b1b177ea7bba7e37b11ac17cfbdf1cade56f
Author:   andrew.victor at mxit.com
Date:     07/20/10 05:46:28
Branch:   im.pidgin.pidgin.mxit
URL: http://d.pidgin.im/viewmtn/revision/info/f447a1b5f9e414e5e9c976218c006288f967e565

Changelog: 

Since a buddy's avatar information is distributed as part of their online   
presence information, if they have changed their avatar while we were
offline (and they're now offline) we won't see the change until we're both
online at the same time.

So when the user requests to view a buddy's profile, we now also request
their current AvatarId - if it is different to what Pidgin has cached, we
request the new image.

Move buddy's avatar processing out of mxit_update_buddy_presence() and into
new function mxit_update_buddy_avatar().  The buddy avatar updating is 
called when we receive a buddy's presence update or when we request the
buddies profile.


Changes against parent 4639b1b177ea7bba7e37b11ac17cfbdf1cade56f

  patched  libpurple/protocols/mxit/profile.c
  patched  libpurple/protocols/mxit/protocol.c
  patched  libpurple/protocols/mxit/roster.c
  patched  libpurple/protocols/mxit/roster.h

-------------- next part --------------
============================================================
--- libpurple/protocols/mxit/profile.c	57a46991d5f97cb9cfb019378b274f552bcc4682
+++ libpurple/protocols/mxit/profile.c	75f372b3d0be740d5e9c49d012241b68dcb6e8ad
@@ -174,7 +174,6 @@ void mxit_show_profile( struct MXitSessi
 
 		/* hidden number */
 		purple_notify_user_info_add_pair( info, _( "Hidden Number" ), ( contact->flags & MXIT_CFLAG_HIDDEN ) ? _( "Yes" ) : _( "No" ) );
-
 	}
 
 	purple_notify_userinfo( session->con, username, info, NULL, NULL );
============================================================
--- libpurple/protocols/mxit/protocol.c	3500d49b2b40825f04228ed136aaebb3065df771
+++ libpurple/protocols/mxit/protocol.c	3284d0181ce1211b38f711f17020957ae4c2051e
@@ -1582,12 +1582,13 @@ static void mxit_parse_cmd_presence( str
 
 		/*
 		 * The format of the record is:
-		 * contactAddressN\1presenceN\1\moodN\1customMoodN\1statusMsgN\1avatarIdN
+		 * contactAddressN\1presenceN\1moodN\1customMoodN\1statusMsgN\1avatarIdN
 		 */
 		mxit_strip_domain( rec->fields[0]->data );		/* contactAddress */
 
 		mxit_update_buddy_presence( session, rec->fields[0]->data, atoi( rec->fields[1]->data ), atoi( rec->fields[2]->data ),
-				rec->fields[3]->data, rec->fields[4]->data, rec->fields[5]->data );
+				rec->fields[3]->data, rec->fields[4]->data );
+		mxit_update_buddy_avatar( session, rec->fields[0]->data, rec->fields[5]->data );
 	}
 }
 
@@ -1605,6 +1606,8 @@ static void mxit_parse_cmd_extprofile( s
 	struct MXitProfile*		profile		= NULL;
 	int						count;
 	int						i;
+	const char*				avatarId	= NULL;
+	const char*				statusMsg	= NULL;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_parse_cmd_extprofile: profile for '%s'\n", mxitId );
 
@@ -1659,8 +1662,13 @@ static void mxit_parse_cmd_extprofile( s
 			/* nickname */
 			g_strlcpy( profile->nickname, fvalue, sizeof( profile->nickname ) );
 		}
+		else if ( strcmp( CP_PROFILE_STATUS, fname ) == 0 ) {
+			/* status message - just keep a reference to the value */
+			statusMsg = fvalue;
+		}
 		else if ( strcmp( CP_PROFILE_AVATAR, fname ) == 0 ) {
-			/* avatar id, we just ingore it cause we dont need it */
+			/* avatar id - just keep a reference to the value */
+			avatarId = fvalue;
 		}
 		else if ( strcmp( CP_PROFILE_TITLE, fname ) == 0 ) {
 			/* title */
@@ -1700,8 +1708,12 @@ static void mxit_parse_cmd_extprofile( s
 		}
 	}
 
-	/* if this is not our profile, just display it */
 	if ( profile != session->profile ) {
+		/* update avatar (if necessary) */
+		if ( avatarId )
+			mxit_update_buddy_avatar( session, mxitId, avatarId );
+
+		/* if this is not our profile, just display it */
 		mxit_show_profile( session, mxitId, profile );
 		g_free( profile );
 	}
============================================================
--- libpurple/protocols/mxit/roster.c	5bfca59d398c795fa2fcd74ad02302b1e54f3433
+++ libpurple/protocols/mxit/roster.c	a91f779a7ddc34e74fce0aa3c17efcbdfc72b0ab
@@ -428,15 +428,14 @@ void mxit_update_contact( struct MXitSes
  *  @param mood			The new mood for the contact
  *  @param customMood	The custom mood identifier
  *  @param statusMsg	This is the contact's status message
- *  @param avatarId		This is the contact's avatar id
  */
-void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg, const char* avatarId )
+void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg )
 {
 	PurpleBuddy*		buddy	= NULL;
 	struct contact*		contact	= NULL;
 
-	purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: user='%s' presence=%i mood=%i customMood='%s' statusMsg='%s' avatar='%s'\n",
-		username, presence, mood, customMood, statusMsg, avatarId );
+	purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: user='%s' presence=%i mood=%i customMood='%s' statusMsg='%s'\n",
+		username, presence, mood, customMood, statusMsg );
 
 	if ( ( presence < MXIT_PRESENCE_OFFLINE ) || ( presence > MXIT_PRESENCE_DND ) ) {
 		purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: invalid presence state %i\n", presence );
@@ -472,7 +471,46 @@ void mxit_update_buddy_presence( struct 
 	if ( statusMsg[0] != '\0' )
 		contact->statusMsg = g_markup_escape_text( statusMsg, -1 );
 
-	/* update avatarId */
+	/* update the buddy's status (reference: "libpurple/prpl.h") */
+	if ( contact->statusMsg )
+		purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL );
+	else
+		purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, NULL );
+
+	/* update the buddy's mood */
+	if ( contact->mood == MXIT_MOOD_NONE )
+		purple_prpl_got_user_status_deactive( session->acc, username, "mood" );
+	else
+		purple_prpl_got_user_status( session->acc, username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL );
+}
+
+
+/*------------------------------------------------------------------------
+ * Update the buddy's avatar.
+ * Either a presence update packet was received from the MXit server, or a profile response.
+ *
+ *  @param session		The MXit session object
+ *  @param username		The contact which presence to update
+ *  @param avatarId		This is the contact's avatar id
+ */
+void mxit_update_buddy_avatar( struct MXitSession* session, const char* username, const char* avatarId )
+{
+	PurpleBuddy*		buddy	= NULL;
+	struct contact*		contact	= NULL;
+
+	purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_avatar: user='%s' avatar='%s'\n", username, avatarId );
+
+	/* find the buddy information for this contact (reference: "libpurple/blist.h") */
+	buddy = purple_find_buddy( session->acc, username );
+	if ( !buddy ) {
+		purple_debug_warning( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: unable to find the buddy '%s'\n", username );
+		return;
+	}
+
+	contact = purple_buddy_get_protocol_data( buddy );
+	if ( !contact )
+		return;
+
 	if ( ( contact->avatarId ) && ( g_ascii_strcasecmp( contact->avatarId, avatarId ) == 0 ) ) {
 		/*  avatar has not changed - do nothing */
 	}
@@ -486,18 +524,6 @@ void mxit_update_buddy_presence( struct 
 	}
 	else		/* clear current avatar */
 		purple_buddy_icons_set_for_user( session->acc, username, NULL, 0, NULL );
-
-	/* update the buddy's status (reference: "libpurple/prpl.h") */
-	if ( contact->statusMsg )
-		purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL );
-	else
-		purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, NULL );
-
-	/* update the buddy's mood */
-	if ( contact->mood == MXIT_MOOD_NONE )
-		purple_prpl_got_user_status_deactive( session->acc, username, "mood" );
-	else
-		purple_prpl_got_user_status( session->acc, username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL );
 }
 
 
============================================================
--- libpurple/protocols/mxit/roster.h	0108cf9e33b5211e8aa632674a8c6c8bc636892b
+++ libpurple/protocols/mxit/roster.h	096f25f2dff8c252f40fe1772add66541504fd13
@@ -124,7 +124,8 @@ void mxit_update_contact( struct MXitSes
 
 /* MXit Protocol callbacks */
 void mxit_update_contact( struct MXitSession* session, struct contact* contact );
-void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg, const char* avatarId );
+void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg );
+void mxit_update_buddy_avatar( struct MXitSession* session, const char* username, const char* avatarId );
 void mxit_new_subscription( struct MXitSession* session, struct contact* contact );
 void mxit_update_blist( struct MXitSession* session );
 gboolean is_mxit_chatroom_contact( struct MXitSession* session, const char* username );


More information about the Commits mailing list