diff libpurple/protocols/mxit/protocol.c @ 31500:80bbed4cb649

* extended the profile information shown for pending invites - avatar image - status message - invite image
author pieter.loubser@mxit.com
date Fri, 01 Apr 2011 13:50:10 +0000
parents acd92b7d8511
children cce18a0ff43a
line wrap: on
line diff
--- a/libpurple/protocols/mxit/protocol.c	Thu Mar 31 20:15:18 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Fri Apr 01 13:50:10 2011 +0000
@@ -1629,10 +1629,9 @@
 
 		if ( rec->fcount >= 5 ) {
 			/* there is a personal invite message attached */
-			contact->msg = strdup( rec->fields[4]->data );
+			if ( ( rec->fields[4]->data ) && ( strlen( rec->fields[4]->data ) > 0 ) )
+				contact->msg = strdup( rec->fields[4]->data );
 		}
-		else
-			contact->msg = NULL;
 
 		/* handle the subscription */
 		if ( contact-> type == MXIT_TYPE_MULTIMX ) {		/* subscription to a MultiMX room */
@@ -1870,13 +1869,43 @@
 	}
 
 	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 );
+		/* not our own profile */
+		struct contact*		contact		= NULL;
+
+		contact = get_mxit_invite_contact( session, mxitId );
+		if ( contact ) {
+			/* this is an invite, so update its profile info */
+			if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
+				/* update the status message */
+				if ( contact->statusMsg )
+					g_free( contact->statusMsg );
+				contact->statusMsg = strdup( statusMsg );
+			}
+			else
+				contact->statusMsg = NULL;
+			if ( contact->profile )
+				g_free( contact->profile );
+			contact->profile = profile;
+			if ( ( avatarId ) && ( strlen( avatarId ) > 0 ) ) {
+				/* avatar must be requested for this invite before we can display it */
+				mxit_get_avatar( session, mxitId, avatarId );
+				if ( contact->avatarId )
+					g_free( contact->avatarId );
+				contact->avatarId = strdup( avatarId );
+			}
+			else {
+				/* display what we have */
+				contact->avatarId = NULL;
+				mxit_show_profile( session, mxitId, profile );
+			}
+		}
+		else {
+			/* this is a contact */
+			if ( avatarId )
+				mxit_update_buddy_avatar( session, mxitId, avatarId );
+			mxit_show_profile( session, mxitId, profile );
+			g_free( profile );
+		}
 	}
 }
 
@@ -2052,6 +2081,7 @@
 		case CP_CHUNK_GET_AVATAR :			/* get avatars */
 			{
 				struct getavatar_chunk chunk;
+				struct contact* contact = NULL;
 
 				/* decode the chunked data */
 				memset( &chunk, 0, sizeof ( struct getavatar_chunk ) );
@@ -2060,9 +2090,18 @@
 				/* update avatar image */
 				if ( chunk.data ) {
 					purple_debug_info( MXIT_PLUGIN_ID, "updating avatar for contact '%s'\n", chunk.mxitid );
-					purple_buddy_icons_set_for_user( session->acc, chunk.mxitid, g_memdup( chunk.data, chunk.length), chunk.length, chunk.avatarid );
+
+					contact = get_mxit_invite_contact( session, chunk.mxitid );
+					if ( contact ) {
+						/* this is an invite (add image to the internal image store) */
+						contact->imgid = purple_imgstore_add_with_id( chunk.data, chunk.length, NULL );
+						mxit_show_profile( session, chunk.mxitid, contact->profile );
+					}
+					else {
+						/* this is a contact's avatar, so update it */
+						purple_buddy_icons_set_for_user( session->acc, chunk.mxitid, g_memdup( chunk.data, chunk.length), chunk.length, chunk.avatarid );
+					}
 				}
-
 			}
 			break;
 
@@ -2764,6 +2803,23 @@
 	g_list_free( session->active_chats );
 	session->active_chats = NULL;
 
+	/* clear the internal invites */
+	while ( session->invites != NULL ) {
+		struct contact* contact = (struct contact*) session->invites->data;
+
+		session->invites = g_list_remove( session->invites, contact );
+
+		if ( contact->msg )
+			g_free( contact->msg );
+		if ( contact->statusMsg )
+			g_free( contact->statusMsg );
+		if ( contact->profile )
+			g_free( contact->profile );
+		g_free( contact );
+	}
+	g_list_free( session->invites );
+	session->invites = NULL;
+
 	/* free profile information */
 	if ( session->profile )
 		free( session->profile );