Mercurial > pidgin.yaz
changeset 31952: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 | a769e6da0a8e |
children | 12676cfd4a1e |
files | libpurple/protocols/mxit/mxit.h libpurple/protocols/mxit/profile.c libpurple/protocols/mxit/profile.h libpurple/protocols/mxit/protocol.c libpurple/protocols/mxit/roster.c libpurple/protocols/mxit/roster.h |
diffstat | 6 files changed, 141 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/mxit/mxit.h Thu Mar 31 20:15:18 2011 +0000 +++ b/libpurple/protocols/mxit/mxit.h Fri Apr 01 13:50:10 2011 +0000 @@ -173,6 +173,7 @@ 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 */
--- a/libpurple/protocols/mxit/profile.c Thu Mar 31 20:15:18 2011 +0000 +++ b/libpurple/protocols/mxit/profile.c Fri Apr 01 13:50:10 2011 +0000 @@ -214,6 +214,26 @@ /* 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 );
--- a/libpurple/protocols/mxit/profile.h Thu Mar 31 20:15:18 2011 +0000 +++ b/libpurple/protocols/mxit/profile.h Fri Apr 01 13:50:10 2011 +0000 @@ -33,7 +33,7 @@ /* 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 */
--- 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 );
--- a/libpurple/protocols/mxit/roster.c Thu Mar 31 20:15:18 2011 +0000 +++ b/libpurple/protocols/mxit/roster.c Fri Apr 01 13:50:10 2011 +0000 @@ -564,8 +564,8 @@ 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 @@ /* 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 @@ /* 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 @@ 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
--- a/libpurple/protocols/mxit/roster.h Thu Mar 31 20:15:18 2011 +0000 +++ b/libpurple/protocols/mxit/roster.h Fri Apr 01 13:50:10 2011 +0000 @@ -121,6 +121,10 @@ 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 @@ 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 );