changeset 31497:acd92b7d8511

* More enhancements to user-searching. * Update ChangeLog with MXit changes.
author andrew.victor@mxit.com
date Tue, 29 Mar 2011 14:43:15 +0000
parents 91df50ae5e26
children 9e9abd65b840
files ChangeLog libpurple/protocols/mxit/profile.c libpurple/protocols/mxit/profile.h libpurple/protocols/mxit/protocol.c
diffstat 4 files changed, 118 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Mar 29 14:39:29 2011 +0000
+++ b/ChangeLog	Tue Mar 29 14:43:15 2011 +0000
@@ -42,13 +42,17 @@
 	  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)
--- a/libpurple/protocols/mxit/profile.c	Tue Mar 29 14:39:29 2011 +0000
+++ b/libpurple/protocols/mxit/profile.c	Tue Mar 29 14:43:15 2011 +0000
@@ -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 @@
 
 
 /*------------------------------------------------------------------------
+ * 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 @@
 /*------------------------------------------------------------------------
  * 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 @@
 /*------------------------------------------------------------------------
  * 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 @@
 	/* 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 @@
 
 	// 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);
 }
--- a/libpurple/protocols/mxit/profile.h	Tue Mar 29 14:39:29 2011 +0000
+++ b/libpurple/protocols/mxit/profile.h	Tue Mar 29 14:43:15 2011 +0000
@@ -55,7 +55,7 @@
 
 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 );
 
--- a/libpurple/protocols/mxit/protocol.c	Tue Mar 29 14:39:29 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Tue Mar 29 14:43:15 2011 +0000
@@ -1890,8 +1890,11 @@
  */
 static void mxit_parse_cmd_suggestcontacts( struct MXitSession* session, struct record** records, int rcount )
 {
+	GList* entries = NULL;
+	int searchType;
+	int maxResults;
+	int count;
 	int i;
-	GList* entries = NULL;
 
 	/*
 	 * searchType \1 numSuggestions \1 total \1 numAttributes \1 name0 \1 name1 \1 ... \1 nameN \0
@@ -1900,18 +1903,57 @@
 	 * 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 );