comparison 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
comparison
equal deleted inserted replaced
31499:a769e6da0a8e 31500:80bbed4cb649
1627 g_strlcpy( contact->alias, rec->fields[1]->data, sizeof( contact->alias ) ); 1627 g_strlcpy( contact->alias, rec->fields[1]->data, sizeof( contact->alias ) );
1628 contact->type = atoi( rec->fields[2]->data ); 1628 contact->type = atoi( rec->fields[2]->data );
1629 1629
1630 if ( rec->fcount >= 5 ) { 1630 if ( rec->fcount >= 5 ) {
1631 /* there is a personal invite message attached */ 1631 /* there is a personal invite message attached */
1632 contact->msg = strdup( rec->fields[4]->data ); 1632 if ( ( rec->fields[4]->data ) && ( strlen( rec->fields[4]->data ) > 0 ) )
1633 } 1633 contact->msg = strdup( rec->fields[4]->data );
1634 else 1634 }
1635 contact->msg = NULL;
1636 1635
1637 /* handle the subscription */ 1636 /* handle the subscription */
1638 if ( contact-> type == MXIT_TYPE_MULTIMX ) { /* subscription to a MultiMX room */ 1637 if ( contact-> type == MXIT_TYPE_MULTIMX ) { /* subscription to a MultiMX room */
1639 char* creator = NULL; 1638 char* creator = NULL;
1640 1639
1868 purple_debug_error( MXIT_PLUGIN_ID, "Invalid profile attribute received '%s' \n", fname ); 1867 purple_debug_error( MXIT_PLUGIN_ID, "Invalid profile attribute received '%s' \n", fname );
1869 } 1868 }
1870 } 1869 }
1871 1870
1872 if ( profile != session->profile ) { 1871 if ( profile != session->profile ) {
1873 /* update avatar (if necessary) */ 1872 /* not our own profile */
1874 if ( avatarId ) 1873 struct contact* contact = NULL;
1875 mxit_update_buddy_avatar( session, mxitId, avatarId ); 1874
1876 1875 contact = get_mxit_invite_contact( session, mxitId );
1877 /* if this is not our profile, just display it */ 1876 if ( contact ) {
1878 mxit_show_profile( session, mxitId, profile ); 1877 /* this is an invite, so update its profile info */
1879 g_free( profile ); 1878 if ( ( statusMsg ) && ( strlen( statusMsg ) > 0 ) ) {
1879 /* update the status message */
1880 if ( contact->statusMsg )
1881 g_free( contact->statusMsg );
1882 contact->statusMsg = strdup( statusMsg );
1883 }
1884 else
1885 contact->statusMsg = NULL;
1886 if ( contact->profile )
1887 g_free( contact->profile );
1888 contact->profile = profile;
1889 if ( ( avatarId ) && ( strlen( avatarId ) > 0 ) ) {
1890 /* avatar must be requested for this invite before we can display it */
1891 mxit_get_avatar( session, mxitId, avatarId );
1892 if ( contact->avatarId )
1893 g_free( contact->avatarId );
1894 contact->avatarId = strdup( avatarId );
1895 }
1896 else {
1897 /* display what we have */
1898 contact->avatarId = NULL;
1899 mxit_show_profile( session, mxitId, profile );
1900 }
1901 }
1902 else {
1903 /* this is a contact */
1904 if ( avatarId )
1905 mxit_update_buddy_avatar( session, mxitId, avatarId );
1906 mxit_show_profile( session, mxitId, profile );
1907 g_free( profile );
1908 }
1880 } 1909 }
1881 } 1910 }
1882 1911
1883 1912
1884 /*------------------------------------------------------------------------ 1913 /*------------------------------------------------------------------------
2050 break; 2079 break;
2051 2080
2052 case CP_CHUNK_GET_AVATAR : /* get avatars */ 2081 case CP_CHUNK_GET_AVATAR : /* get avatars */
2053 { 2082 {
2054 struct getavatar_chunk chunk; 2083 struct getavatar_chunk chunk;
2084 struct contact* contact = NULL;
2055 2085
2056 /* decode the chunked data */ 2086 /* decode the chunked data */
2057 memset( &chunk, 0, sizeof ( struct getavatar_chunk ) ); 2087 memset( &chunk, 0, sizeof ( struct getavatar_chunk ) );
2058 mxit_chunk_parse_get_avatar( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk ); 2088 mxit_chunk_parse_get_avatar( &records[0]->fields[0]->data[sizeof( char ) + sizeof( int )], records[0]->fields[0]->len, &chunk );
2059 2089
2060 /* update avatar image */ 2090 /* update avatar image */
2061 if ( chunk.data ) { 2091 if ( chunk.data ) {
2062 purple_debug_info( MXIT_PLUGIN_ID, "updating avatar for contact '%s'\n", chunk.mxitid ); 2092 purple_debug_info( MXIT_PLUGIN_ID, "updating avatar for contact '%s'\n", chunk.mxitid );
2063 purple_buddy_icons_set_for_user( session->acc, chunk.mxitid, g_memdup( chunk.data, chunk.length), chunk.length, chunk.avatarid ); 2093
2094 contact = get_mxit_invite_contact( session, chunk.mxitid );
2095 if ( contact ) {
2096 /* this is an invite (add image to the internal image store) */
2097 contact->imgid = purple_imgstore_add_with_id( chunk.data, chunk.length, NULL );
2098 mxit_show_profile( session, chunk.mxitid, contact->profile );
2099 }
2100 else {
2101 /* this is a contact's avatar, so update it */
2102 purple_buddy_icons_set_for_user( session->acc, chunk.mxitid, g_memdup( chunk.data, chunk.length), chunk.length, chunk.avatarid );
2103 }
2064 } 2104 }
2065
2066 } 2105 }
2067 break; 2106 break;
2068 2107
2069 case CP_CHUNK_SET_AVATAR : 2108 case CP_CHUNK_SET_AVATAR :
2070 /* this is a reply packet to a set avatar request. no action is required */ 2109 /* this is a reply packet to a set avatar request. no action is required */
2762 g_free( chat ); 2801 g_free( chat );
2763 } 2802 }
2764 g_list_free( session->active_chats ); 2803 g_list_free( session->active_chats );
2765 session->active_chats = NULL; 2804 session->active_chats = NULL;
2766 2805
2806 /* clear the internal invites */
2807 while ( session->invites != NULL ) {
2808 struct contact* contact = (struct contact*) session->invites->data;
2809
2810 session->invites = g_list_remove( session->invites, contact );
2811
2812 if ( contact->msg )
2813 g_free( contact->msg );
2814 if ( contact->statusMsg )
2815 g_free( contact->statusMsg );
2816 if ( contact->profile )
2817 g_free( contact->profile );
2818 g_free( contact );
2819 }
2820 g_list_free( session->invites );
2821 session->invites = NULL;
2822
2767 /* free profile information */ 2823 /* free profile information */
2768 if ( session->profile ) 2824 if ( session->profile )
2769 free( session->profile ); 2825 free( session->profile );
2770 2826
2771 /* free custom emoticons */ 2827 /* free custom emoticons */