Since a buddy's avatar information is distributed as part of their online mxit

Tue, 20 Jul 2010 09:46:28 +0000

author
Andrew Victor <andrew.victor@mxit.com>
date
Tue, 20 Jul 2010 09:46:28 +0000
branch
mxit
changeset 30522
5b84b44ed654
parent 30521
44e7b773d9d9
child 30523
2629bf405a36

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.

libpurple/protocols/mxit/profile.c file | annotate | diff | comparison | revisions
libpurple/protocols/mxit/protocol.c file | annotate | diff | comparison | revisions
libpurple/protocols/mxit/roster.c file | annotate | diff | comparison | revisions
libpurple/protocols/mxit/roster.h file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/mxit/profile.c	Mon Jul 19 09:52:08 2010 +0000
+++ b/libpurple/protocols/mxit/profile.c	Tue Jul 20 09:46:28 2010 +0000
@@ -174,7 +174,6 @@
 
 		/* 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 );
--- a/libpurple/protocols/mxit/protocol.c	Mon Jul 19 09:52:08 2010 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Tue Jul 20 09:46:28 2010 +0000
@@ -1582,12 +1582,13 @@
 
 		/*
 		 * 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 @@
 	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 @@
 			/* 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 @@
 		}
 	}
 
-	/* 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 );
 	}
--- a/libpurple/protocols/mxit/roster.c	Mon Jul 19 09:52:08 2010 +0000
+++ b/libpurple/protocols/mxit/roster.c	Tue Jul 20 09:46:28 2010 +0000
@@ -428,15 +428,14 @@
  *  @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 @@
 	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 @@
 	}
 	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 );
 }
 
 
--- a/libpurple/protocols/mxit/roster.h	Mon Jul 19 09:52:08 2010 +0000
+++ b/libpurple/protocols/mxit/roster.h	Tue Jul 20 09:46:28 2010 +0000
@@ -124,7 +124,8 @@
 
 /* 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 );

mercurial