pidgin.mxit: 02bbb3e7: * extended the profile information show...
pieter.loubser at mxit.com
pieter.loubser at mxit.com
Fri Apr 1 09:58:18 EDT 2011
----------------------------------------------------------------------
Revision: 02bbb3e7ba9e029ba05484caae8c91a948bb0b35
Parent: d665f09198c857edfed84fb72b61ff0079ecdea5
Author: pieter.loubser at mxit.com
Date: 04/01/11 09:50:10
Branch: im.pidgin.pidgin.mxit
URL: http://d.pidgin.im/viewmtn/revision/info/02bbb3e7ba9e029ba05484caae8c91a948bb0b35
Changelog:
* extended the profile information shown for pending invites
- avatar image
- status message
- invite image
Changes against parent d665f09198c857edfed84fb72b61ff0079ecdea5
patched libpurple/protocols/mxit/mxit.h
patched libpurple/protocols/mxit/profile.c
patched libpurple/protocols/mxit/profile.h
patched libpurple/protocols/mxit/protocol.c
patched libpurple/protocols/mxit/roster.c
patched libpurple/protocols/mxit/roster.h
-------------- next part --------------
============================================================
--- libpurple/protocols/mxit/mxit.h 285c04ee0f8a64b8c9cfe5169a49aa0909cf8189
+++ libpurple/protocols/mxit/mxit.h 6bb4b286c494a71709d8758ed8eabd435b029f70
@@ -173,6 +173,7 @@ struct MXitSession {
char rx_state; /* current receiver state */
gint64 last_rx; /* timestamp of last packet received */
GList* active_chats; /* list of all our contacts we received messages from (active chats) */
+ GList* invites; /* list of all the invites that we have received */
/* groupchat */
GList* rooms; /* active groupchat rooms */
============================================================
--- libpurple/protocols/mxit/profile.c 13b0ac2a3e3ca34146855046a8c8d9486e811e4d
+++ libpurple/protocols/mxit/profile.c 67eaafb5ff37d1d7ebbc28b61c67c8ae6cfa07bc
@@ -214,7 +214,27 @@ void mxit_show_profile( struct MXitSessi
/* hidden number */
purple_notify_user_info_add_pair( info, _( "Hidden Number" ), ( contact->flags & MXIT_CFLAG_HIDDEN ) ? _( "Yes" ) : _( "No" ) );
}
+ else {
+ /* this is an invite */
+ contact = get_mxit_invite_contact( session, username );
+ if ( contact ) {
+ /* invite found */
+ if ( contact->msg )
+ purple_notify_user_info_add_pair( info, _( "Invite Message" ), contact->msg );
+
+ if ( contact->imgid ) {
+ /* this invite has a avatar */
+ char* img_text;
+ img_text = g_strdup_printf( "<img id='%d'>", contact->imgid );
+ purple_notify_user_info_add_pair( info, _( "Photo" ), img_text );
+ }
+
+ if ( contact->statusMsg )
+ purple_notify_user_info_add_pair( info, _( "Status Message" ), contact->statusMsg );
+ }
+ }
+
purple_notify_userinfo( session->con, username, info, NULL, NULL );
purple_notify_user_info_destroy( info );
}
============================================================
--- libpurple/protocols/mxit/profile.h 6d4ab822b16d19872c2b0e9f1161fcda5fcd7ff9
+++ libpurple/protocols/mxit/profile.h a4c773fbc1fcfe33757061f394568f4c05bb0272
@@ -33,7 +33,7 @@ struct MXitProfile {
/* required */
char loginname[64]; /* name user uses to log into MXit with (aka 'mxitid') */
char userid[51]; /* internal UserId (only in search results) */
- char nickname[101]; /* user's own display name (aka 'nickname', aka 'fullname', aka 'alias') in MXit */
+ char nickname[101]; /* user's own display name (aka 'display name', aka 'fullname', aka 'alias') in MXit */
char birthday[16]; /* user's birthday "YYYY-MM-DD" */
gboolean male; /* true if the user's gender is male (otherwise female) */
char pin[16]; /* user's password */
============================================================
--- libpurple/protocols/mxit/protocol.c c074a9e36814c482a6d9cdf870895a3611b6064a
+++ libpurple/protocols/mxit/protocol.c 2a181692465a065b0cf946cf2f2926ed95821d03
@@ -1629,10 +1629,9 @@ static void mxit_parse_cmd_new_sub( stru
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 @@ static void mxit_parse_cmd_extprofile( s
}
if ( profile != session->profile ) {
- /* update avatar (if necessary) */
- if ( avatarId )
- mxit_update_buddy_avatar( session, mxitId, avatarId );
+ /* not our own profile */
+ struct contact* contact = NULL;
- /* if this is not our profile, just display it */
- mxit_show_profile( session, mxitId, profile );
- g_free( profile );
+ 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 @@ static void mxit_parse_cmd_media( struct
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 @@ static void mxit_parse_cmd_media( struct
/* 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 @@ void mxit_close_connection( struct MXitS
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 );
============================================================
--- libpurple/protocols/mxit/roster.c b680ad15a3e8ff2704061a5ca5b82860bb106f1c
+++ libpurple/protocols/mxit/roster.c 0558303b48156ddfbf0da3555c90aaf441861c42
@@ -564,8 +564,8 @@ void mxit_update_blist( struct MXitSessi
buddy = g_slist_nth_data( list, i );
if ( !purple_buddy_get_protocol_data( buddy ) ) {
- const gchar *alias = purple_buddy_get_alias( buddy );
- const gchar *name = purple_buddy_get_name( buddy );
+ const gchar* alias = purple_buddy_get_alias( buddy );
+ const gchar* name = purple_buddy_get_name( buddy );
/* this buddy should be removed, because we did not receive him in our roster update from MXit */
purple_debug_info( MXIT_PLUGIN_ID, "Removed 'old' buddy from the blist '%s' (%s)\n", alias, name );
@@ -592,9 +592,16 @@ static void mxit_cb_buddy_auth( gpointer
/* send a allow subscription packet to MXit */
mxit_send_allow_sub( invite->session, invite->contact->username, invite->contact->alias );
+ /* remove the invite from our internal invites list */
+ invite->session->invites = g_list_remove( invite->session->invites, invite->contact );
+
/* freeup invite object */
if ( invite->contact->msg )
g_free( invite->contact->msg );
+ if ( invite->contact->statusMsg )
+ g_free( invite->contact->statusMsg );
+ if ( invite->contact->profile )
+ g_free( invite->contact->profile );
g_free( invite->contact );
g_free( invite );
}
@@ -614,9 +621,16 @@ static void mxit_cb_buddy_deny( gpointer
/* send a deny subscription packet to MXit */
mxit_send_deny_sub( invite->session, invite->contact->username );
+ /* remove the invite from our internal invites list */
+ invite->session->invites = g_list_remove( invite->session->invites, invite->contact );
+
/* freeup invite object */
if ( invite->contact->msg )
g_free( invite->contact->msg );
+ if ( invite->contact->statusMsg )
+ g_free( invite->contact->statusMsg );
+ if ( invite->contact->profile )
+ g_free( invite->contact->profile );
g_free( invite->contact );
g_free( invite );
}
@@ -639,12 +653,42 @@ void mxit_new_subscription( struct MXitS
invite->session = session;
invite->contact = contact;
+ /* add the invite to our internal invites list */
+ invite->session->invites = g_list_append( invite->session->invites, invite->contact );
+
/* (reference: "libpurple/account.h") */
purple_account_request_authorization( session->acc, contact->username, NULL, contact->alias, contact->msg, FALSE, mxit_cb_buddy_auth, mxit_cb_buddy_deny, invite );
}
/*------------------------------------------------------------------------
+ * Return the contact object for a mxit invite
+ *
+ * @param session The MXit session object
+ * @param username The username of the contact
+ * @return The contact object for the inviting user
+ */
+struct contact* get_mxit_invite_contact( struct MXitSession* session, const char* username )
+{
+ struct contact* con = NULL;
+ struct contact* match = NULL;
+ int i;
+
+ /* run through all the invites and try and find the match */
+ for ( i = 0; i < g_list_length( session->invites ); i++ ) {
+ con = g_list_nth_data( session->invites, i );
+ if ( strcmp( con->username, username ) == 0 ) {
+ /* invite found */
+ match = con;
+ break;
+ }
+ }
+
+ return match;
+}
+
+
+/*------------------------------------------------------------------------
* Return TRUE if this is a MXit Chatroom contact.
*
* @param session The MXit session object
============================================================
--- libpurple/protocols/mxit/roster.h 3eeee5fd180b46d6e508191ac8cf6a7702702623
+++ libpurple/protocols/mxit/roster.h 7f3bfbe4cbd806c5f4da8eb8172766b7ef19758a
@@ -121,6 +121,10 @@ struct contact {
char customMood[16]; /* custom mood */
char* statusMsg; /* status message */
char* avatarId; /* avatarId */
+
+ /* invites only */
+ void* profile; /* user's profile (if available) */
+ int imgid; /* avatar image id in the imgstore */
};
/* Presence / Status */
@@ -140,6 +144,7 @@ gboolean is_mxit_chatroom_contact( struc
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 );
+struct contact* get_mxit_invite_contact( struct MXitSession* session, const char* username );
/* libPurple callbacks */
void mxit_add_buddy( PurpleConnection* gc, PurpleBuddy* buddy, PurpleGroup* group, const char* message );
More information about the Commits
mailing list