pidgin.mxit: 524638c7: * More enhancements to user-searching.

andrew.victor at mxit.com andrew.victor at mxit.com
Tue Mar 29 10:47:40 EDT 2011


----------------------------------------------------------------------
Revision: 524638c79d3d0540b9343247091acf620ef2c733
Parent:   4c43384dab623819bd0b3f95db70b0a711267ec1
Author:   andrew.victor at mxit.com
Date:     03/29/11 10:43:15
Branch:   im.pidgin.pidgin.mxit
URL: http://d.pidgin.im/viewmtn/revision/info/524638c79d3d0540b9343247091acf620ef2c733

Changelog: 

* More enhancements to user-searching.
* Update ChangeLog with MXit changes.


Changes against parent 4c43384dab623819bd0b3f95db70b0a711267ec1

  patched  ChangeLog
  patched  libpurple/protocols/mxit/profile.c
  patched  libpurple/protocols/mxit/profile.h
  patched  libpurple/protocols/mxit/protocol.c

-------------- next part --------------
============================================================
--- ChangeLog	c1e49de66d270a4ed611e0e7756b27aeb7724ce5
+++ ChangeLog	ce0a28375234ba60e9affaf9445b8a563c3ead3e
@@ -42,13 +42,17 @@ version 2.8.0 (??/??/????):
 	  an ICQ account's settings by using a comma-delimited list.  (Dmitry
 	  Utkin (#13496)
 
+	MXit:
+	* Support for an Invite Message when adding a buddy.
+	* Fix bug when splitting a long messages with lots of links.
+	* Fix detection of new kick message from a MultiMX room.
+	* Fix crash caused by fast-queue timer not being removed on session
+	  close. (broken in 2.7.11)
+
 	Plugins:
 	* The Voice/Video Settings plugin now includes the ability to test
 	  microphone settings. (Jakub Adam) (#13182)
 
-	MXit:
-	* Support for an Invite Message when adding a buddy.
-
 	Windows-Specific Changes:
 	* Fix building libpurple with Visual C++ .NET 2005. This was accidentally
 	  broken in 2.7.11. (Florian Qu?ze)
============================================================
--- libpurple/protocols/mxit/profile.c	df6e42d2c19505742496f2ed74bd4233904605f1
+++ libpurple/protocols/mxit/profile.c	13b0ac2a3e3ca34146855046a8c8d9486e811e4d
@@ -23,6 +23,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#define		_XOPEN_SOURCE
+#include	<time.h>
+
 #include    "internal.h"
 #include	"purple.h"
 
@@ -34,7 +37,7 @@
 /*------------------------------------------------------------------------
  * Returns true if it is a valid date.
  *
- * @param bday		Date-of-Birth string
+ * @param bday		Date-of-Birth string (YYYY-MM-DD)
  * @return			TRUE if valid, else FALSE
  */
 gboolean validateDate( const char* bday )
@@ -101,6 +104,40 @@ gboolean validateDate( const char* bday 
 
 
 /*------------------------------------------------------------------------
+ * Calculate an Age from the date-of-birth.
+ *
+ * @param date		Date-of-Birth string (YYYY-MM-DD)
+ * @return			The age
+ */
+static int calculateAge( const char* date )
+{
+	time_t t;
+	struct tm now, bdate;
+	int age;
+
+	if ( ( !date ) || ( strlen( date ) == 0 ) )
+		return 0;
+
+	/* current time */
+	t = time(NULL);
+	localtime_r( &t, &now );
+
+	/* decode hdate */
+	memset( &bdate, 0, sizeof( struct tm ) );
+	strptime( date, "%Y-%m-%d", &bdate );
+
+	/* calculate difference */
+	age = now.tm_year - bdate.tm_year;
+	if ( now.tm_mon < bdate.tm_mon )		/* is before month of birth */
+		age--;
+	else if ( (now.tm_mon == bdate.tm_mon ) && ( now.tm_mday < bdate.tm_mday ) )	/* before birthday in current month */
+		age--;
+
+	return age;
+}
+
+
+/*------------------------------------------------------------------------
  * Returns timestamp field in date & time format (DD-MM-YYYY HH:MM:SS)
  *
  * @param msecs		The timestamps (milliseconds since epoch)
@@ -120,9 +157,9 @@ static const char* datetime( gint64 msec
 /*------------------------------------------------------------------------
  * Display the profile information.
  *
- *  @param session		The MXit session object
- *  @param username		The username who's profile information this is
- *  @param profile		The profile
+ * @param session		The MXit session object
+ * @param username		The username who's profile information this is
+ * @param profile		The profile
  */
 void mxit_show_profile( struct MXitSession* session, const char* username, struct MXitProfile* profile )
 {
@@ -185,13 +222,16 @@ void mxit_show_profile( struct MXitSessi
 /*------------------------------------------------------------------------
  * Display the profiles of search results.
  *
- *  @param session		The MXit session object
- *  @param entries		The list of profile entries
+ * @param session		The MXit session object
+ * @param searchType	The type of search (CP_SUGGEST_*)
+ * @param maxResults	The maximum number of results
+ * @param entries		The list of profile entries
  */
-void mxit_show_search_results( struct MXitSession* session, GList* entries )
+void mxit_show_search_results( struct MXitSession* session, int searchType, int maxResults, GList* entries )
 {
 	PurpleNotifySearchResults*	results;
 	PurpleNotifySearchColumn*	column;
+	gchar*						text;
 
 	if ( !entries ) {
 		mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "No results" ), _( "No users found." ) );
@@ -205,13 +245,25 @@ void mxit_show_search_results( struct MX
 	/* define columns */
 	column = purple_notify_searchresults_column_new( _( "UserId" ) );
 	purple_notify_searchresults_column_add( results, column );
-	
+	column = purple_notify_searchresults_column_new( _( "Display Name" ) );
+	purple_notify_searchresults_column_add( results, column );
+	column = purple_notify_searchresults_column_new( _( "Gender" ) );
+	purple_notify_searchresults_column_add( results, column );
+	column = purple_notify_searchresults_column_new( _( "Age" ) );
+	purple_notify_searchresults_column_add( results, column );
+	column = purple_notify_searchresults_column_new( _( "Where I live" ) );
+	purple_notify_searchresults_column_add( results, column );
+
 	while (entries != NULL) {
 		struct MXitProfile* profile	= ( struct MXitProfile *) entries->data;
 		GList*	row;
 
 		/* column values */
 		row = g_list_append( NULL, g_strdup( profile->userid ) );
+		row = g_list_append( row, g_strdup( profile->nickname ) );
+		row = g_list_append( row, g_strdup( profile->male ? "Male" : "Female" ) );
+		row = g_list_append( row, g_strdup_printf( "%i", calculateAge( profile->birthday ) ) );
+		row = g_list_append( row, g_strdup( profile->whereami ) );
 
 		purple_notify_searchresults_row_add( results, row );
 		entries = g_list_next( entries );
@@ -219,5 +271,9 @@ void mxit_show_search_results( struct MX
 
 	// TODO: add buttons
 
-	purple_notify_searchresults( session->con, NULL, NULL, NULL, results, NULL, NULL );
+	text = g_strdup_printf( _( "We found %i contacts that match your search." ), maxResults );
+
+	purple_notify_searchresults( session->con, NULL, text, NULL, results, NULL, NULL );
+
+	g_free( text);
 }
============================================================
--- libpurple/protocols/mxit/profile.h	f50b43f89a66026b0aa5d13c52a5093f05df616f
+++ libpurple/protocols/mxit/profile.h	6d4ab822b16d19872c2b0e9f1161fcda5fcd7ff9
@@ -55,7 +55,7 @@ void mxit_show_profile( struct MXitSessi
 
 struct MXitSession;
 void mxit_show_profile( struct MXitSession* session, const char* username, struct MXitProfile* profile );
-void mxit_show_search_results( struct MXitSession* session, GList* entries );
+void mxit_show_search_results( struct MXitSession* session, int searchType, int maxResults, GList* entries );
 
 gboolean validateDate( const char* bday );
 
============================================================
--- libpurple/protocols/mxit/protocol.c	af0a5b89c6e961cc7859482d8389bb5e036562c1
+++ libpurple/protocols/mxit/protocol.c	c074a9e36814c482a6d9cdf870895a3611b6064a
@@ -1890,8 +1890,11 @@ static void mxit_parse_cmd_suggestcontac
  */
 static void mxit_parse_cmd_suggestcontacts( struct MXitSession* session, struct record** records, int rcount )
 {
-	int i;
 	GList* entries = NULL;
+	int searchType;
+	int maxResults;
+	int count;
+	int i;
 
 	/*
 	 * searchType \1 numSuggestions \1 total \1 numAttributes \1 name0 \1 name1 \1 ... \1 nameN \0
@@ -1900,18 +1903,57 @@ static void mxit_parse_cmd_suggestcontac
 	 * userid \1 contactType \1 value0 \1 value1 ... valueN
 	 */
 
+	/* the type of results */
+	searchType = atoi( records[0]->fields[0]->data );
+
+	/* the maximum number of results */
+	maxResults = atoi( records[0]->fields[2]->data );
+
+	/* set the count for attributes */
+	count = atoi( records[0]->fields[3]->data );
+
 	for ( i = 1; i < rcount; i ++ ) {
 		struct record*		rec		= records[i];
 		struct MXitProfile*	profile	= g_new0( struct MXitProfile, 1 );
+		int j;
 
 		g_strlcpy( profile->userid, rec->fields[0]->data, sizeof( profile->userid ) );
-		// TODO: Decoce other profile fields.
+		// TODO: ContactType - User or Service
 
+		for ( j = 0; j < count; j++ ) {
+			char* fname;
+			char* fvalue = "";
+
+			fname = records[0]->fields[4 + j]->data;		/* field name */
+			if ( records[i]->fcount > ( 2 + j ) )
+				fvalue = records[i]->fields[2 + j]->data;	/* field value */
+
+			purple_debug_info( MXIT_PLUGIN_ID, " %s: field='%s' value='%s'\n", profile->userid, fname, fvalue );
+
+			if ( strcmp( CP_PROFILE_BIRTHDATE, fname ) == 0 ) {
+				/* birthdate */
+				g_strlcpy( profile->birthday, fvalue, sizeof( profile->birthday ) );
+			}
+			else if ( strcmp( CP_PROFILE_GENDER, fname ) == 0 ) {
+				/* gender */
+				profile->male = ( fvalue[0] == '1' );
+			}
+			else if ( strcmp( CP_PROFILE_FULLNAME, fname ) == 0 ) {
+				/* nickname */
+				g_strlcpy( profile->nickname, fvalue, sizeof( profile->nickname ) );
+			}
+			else if ( strcmp( CP_PROFILE_WHEREAMI, fname ) == 0 ) {
+				/* where am I */
+				g_strlcpy( profile->whereami, fvalue, sizeof( profile->whereami ) );
+			}
+			/* ignore other attibutes */
+		}
+
 		entries = g_list_append( entries, profile );
 	}
 
 	/* display */
-	mxit_show_search_results( session, entries );
+	mxit_show_search_results( session, searchType, maxResults, entries );
 
 	/* cleanup */
 	g_list_foreach( entries, (GFunc)g_free, NULL );


More information about the Commits mailing list