/pidgin/main: b8a88a88cbf2: Add typing indicator support for MXi...

Andrew Victor andrew.victor at mxit.com
Fri Jul 27 03:47:38 EDT 2012


Changeset: b8a88a88cbf20504934da0ee10897b224f8d5f4b
Author:	 Andrew Victor <andrew.victor at mxit.com>
Date:	 2012-07-27 09:47 +0200
Branch:	 mxit-2.x.y
URL: http://hg.pidgin.im/pidgin/main/rev/b8a88a88cbf2

Description:

Add typing indicator support for MXit protocol.

diffstat:

 libpurple/protocols/mxit/mxit.c     |  44 +++++++++++++++++++++++++++++++-
 libpurple/protocols/mxit/protocol.c |  50 ++++++++++++++++++++++++++++++++++++-
 libpurple/protocols/mxit/protocol.h |   5 +++
 3 files changed, 97 insertions(+), 2 deletions(-)

diffs (157 lines):

diff --git a/libpurple/protocols/mxit/mxit.c b/libpurple/protocols/mxit/mxit.c
--- a/libpurple/protocols/mxit/mxit.c
+++ b/libpurple/protocols/mxit/mxit.c
@@ -659,6 +659,48 @@ static GList* mxit_blist_menu( PurpleBli
 	return m;
 }
 
+
+/*------------------------------------------------------------------------
+ * Send a typing indicator event.
+ *
+ *  @param gc		The connection object
+ *  @param name		The username of the contact
+ *  @param state	The typing state to be reported.
+ */
+static unsigned int mxit_send_typing( PurpleConnection *gc, const char *name, PurpleTypingState state )
+{
+	struct MXitSession*	session	= (struct MXitSession*) gc->proto_data;
+	gchar* messageId = purple_uuid_random();		/* generate a unique message id */
+
+	switch ( state ) {
+		case PURPLE_TYPING :
+			purple_debug_info( MXIT_PLUGIN_ID, "Send typing state: TYPING\n");
+
+			mxit_send_msgevent( session, name, messageId, CP_MSGEVENT_TYPING );
+			break;
+
+		case PURPLE_TYPED :
+			purple_debug_info( MXIT_PLUGIN_ID, "Send typing state: TYPED\n");
+
+			mxit_send_msgevent( session, name, messageId, CP_MSGEVENT_STOPPED );
+			break;
+
+		case PURPLE_NOT_TYPING:
+			purple_debug_info( MXIT_PLUGIN_ID, "Send typing state: NOT TYPING\n");
+			break;
+
+		default:
+			purple_debug_info( MXIT_PLUGIN_ID, "Send typing state: UNKNOWN\n");
+
+			break;
+	}
+
+	g_free(messageId);
+
+	return 0;            
+}
+ 
+
 /*========================================================================================================================*/
 
 static PurplePluginProtocolInfo proto_info = {
@@ -685,7 +727,7 @@ static PurplePluginProtocolInfo proto_in
 	mxit_close,				/* close */
 	mxit_send_im,			/* send_im */
 	NULL,					/* set_info */
-	NULL,					/* send_typing */
+	mxit_send_typing,		/* send_typing */
 	mxit_get_info,			/* get_info */
 	mxit_set_status,		/* set_status */
 	NULL,					/* set_idle */
diff --git a/libpurple/protocols/mxit/protocol.c b/libpurple/protocols/mxit/protocol.c
--- a/libpurple/protocols/mxit/protocol.c
+++ b/libpurple/protocols/mxit/protocol.c
@@ -1135,7 +1135,7 @@ void mxit_send_splashclick( struct MXitS
  *  @param id			The identifier of the event (received in message)
  *  @param event		Identified the type of event
  */
-void mxit_send_msgevent( struct MXitSession* session, const char* to, const char* id, int event)
+void mxit_send_msgevent( struct MXitSession* session, const char* to, const char* id, int event )
 {
 	char		data[CP_MAX_PACKET];
 	int			datalen;
@@ -2023,6 +2023,49 @@ static void mxit_parse_cmd_suggestcontac
 	g_list_foreach( entries, (GFunc)g_free, NULL );
 }
 
+/*------------------------------------------------------------------------
+ * Process a received message event packet.
+ *
+ *  @param session		The MXit session object
+ *  @param records		The packet's data records
+ *  @param rcount		The number of data records
+ */
+static void mxit_parse_cmd_msgevent( struct MXitSession* session, struct record** records, int rcount )
+{
+	int event;
+
+	/*
+	 * contactAddress \1 dateTime \1 id \1 event 
+	 */
+
+	/* strip off dummy domain */
+	mxit_strip_domain( records[0]->fields[0]->data );
+
+	event = atoi( records[0]->fields[3]->data );
+
+	switch ( event ) {
+		case CP_MSGEVENT_TYPING :							/* user is typing */
+		case CP_MSGEVENT_ANGRY :							/* user is typing angrily */
+			purple_debug_info( MXIT_PLUGIN_ID, "Got a TYPING event for %s\n", records[0]->fields[3]->data );
+			serv_got_typing( session->con, records[0]->fields[0]->data, 0, PURPLE_TYPING );
+			break;
+
+		case CP_MSGEVENT_STOPPED :							/* user has stopped typing */
+			purple_debug_info( MXIT_PLUGIN_ID, "Got a STOPPED event for %s\n", records[0]->fields[3]->data );
+			serv_got_typing_stopped( session->con, records[0]->fields[0]->data );
+			break;
+
+		case CP_MSGEVENT_ERASING :							/* user is erasing text */
+		case CP_MSGEVENT_DELIVERED :						/* message was delivered */
+		case CP_MSGEVENT_DISPLAYED :						/* message was viewed */
+			/* these are currently not supported by libPurple */
+			break;
+
+		default:
+			purple_debug_error( MXIT_PLUGIN_ID, "Unknown message event received (%i)\n", event );
+	}
+}
+
 
 /*------------------------------------------------------------------------
  * Return the length of a multimedia chunk
@@ -2302,6 +2345,11 @@ static int process_success_response( str
 				mxit_parse_cmd_suggestcontacts( session, &packet->records[2], packet->rcount - 2 );
 				break;
 
+		case CP_CMD_GOT_MSGEVENT :
+				/* received message event */
+				mxit_parse_cmd_msgevent( session, &packet->records[2], packet->rcount - 2 );
+				break;
+
 		case CP_CMD_MOOD :
 				/* mood update */
 		case CP_CMD_UPDATE :
diff --git a/libpurple/protocols/mxit/protocol.h b/libpurple/protocols/mxit/protocol.h
--- a/libpurple/protocols/mxit/protocol.h
+++ b/libpurple/protocols/mxit/protocol.h
@@ -132,6 +132,7 @@
 #define		CP_CMD_SPLASHCLICK		0x001F					/* (31) splash-screen clickthrough */
 #define		CP_CMD_STATUS			0x0020					/* (32) set shown presence & status */
 #define		CP_CMD_MSGEVENT			0x0023					/* (35) Raise message event */
+#define		CP_CMD_GOT_MSGEVENT		0x0024					/* (36) Get message event */
 #define		CP_CMD_MOOD				0x0029					/* (41) set mood */
 #define		CP_CMD_KICK				0x002B					/* (43) login kick */
 #define		CP_CMD_GRPCHAT_CREATE	0x002C					/* (44) create new groupchat */
@@ -176,6 +177,10 @@
 /* message event types */
 #define		CP_MSGEVENT_DELIVERED	0x02					/* message was delivered */
 #define		CP_MSGEVENT_DISPLAYED	0x04					/* message was viewed */
+#define		CP_MSGEVENT_TYPING		0x10					/* user is typing */
+#define		CP_MSGEVENT_STOPPED		0x20					/* user has stopped typing */
+#define		CP_MSGEVENT_ANGRY		0x40					/* user is typing angrily */
+#define		CP_MSGEVENT_ERASING		0x80					/* user is erasing text */
 
 /* extended profile attribute fields */
 #define		CP_PROFILE_BIRTHDATE	"birthdate"				/* Birthdate (String - ISO 8601 format) */



More information about the Commits mailing list