changeset 17929:87b77f1ea086

Add support for idle.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Wed, 04 Jul 2007 19:05:21 +0000
parents ea5258b0f67d
children d0c8b7748065
files libpurple/protocols/myspace/CHANGES libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h
diffstat 3 files changed, 55 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/CHANGES	Wed Jul 04 06:37:08 2007 +0000
+++ b/libpurple/protocols/myspace/CHANGES	Wed Jul 04 19:05:21 2007 +0000
@@ -1,3 +1,7 @@
+2007-07-xx Jeff Connelly <jeff2@soc.pidgin.im> - 0.11
+* Allow going idle (tested with I'dle Ma'ker) and viewing idle status of buddies
+ (thanks to Scott Ellis for finding the idle status code.)
+
 2007-07-03 Jeff Connelly <jeff2@soc.pidgin.im> - 0.10
 * On incoming instant messages, add support for:
  * Text color
--- a/libpurple/protocols/myspace/myspace.c	Wed Jul 04 06:37:08 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Wed Jul 04 19:05:21 2007 +0000
@@ -1162,21 +1162,13 @@
 {
 	PurpleStatusType *type;
 	MsimSession *session;
+    guint status_code;
 
 	session = (MsimSession *)account->gc->proto_data;
 
 	type = purple_status_get_type(status);
 
-    msim_set_status_primitive(session, purple_status_type_get_primitive(type));
-}
-
-/** Set status using a status primitive type. */
-void 
-msim_set_status_primitive(MsimSession *session, guint code)
-{
-    guint status_code;
-
-	switch (code)
+	switch (purple_status_type_get_primitive(type))
 	{
 		case PURPLE_STATUS_AVAILABLE:
 			status_code = MSIM_STATUS_CODE_ONLINE;
@@ -1197,6 +1189,35 @@
 			break;
 	}
 
+
+    msim_set_status_code(session, status_code);
+}
+
+/** Go idle. */
+void
+msim_set_idle(PurpleConnection *gc, int time)
+{
+    MsimSession *session;
+
+    session = (MsimSession *)gc->proto_data;
+
+    if (time == 0)
+    {
+        /* Going back from idle. In msim, idle is mutually exclusive 
+         * from the other states (you can only be away or idle, but not
+         * both, for example), so by going non-idle I go online.
+         */
+        msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE);
+    } else {
+        /* msim doesn't support idle time */
+        msim_set_status_code(session, MSIM_STATUS_CODE_IDLE);
+    }
+}
+
+/** Set status using an MSIM_STATUS_CODE_* value. (TODO: also set message) */
+void 
+msim_set_status_code(MsimSession *session, guint status_code)
+{
 	if (!msim_send(session,
 			"status", MSIM_TYPE_INTEGER, status_code,
 			"sesskey", MSIM_TYPE_INTEGER, session->sesskey,
@@ -1428,7 +1449,7 @@
 #endif
 
     /* Set status depending on preference. */
-    msim_set_status_primitive(session, 
+    msim_set_status_code(session, 
             purple_account_get_bool(session->account, "hidden", FALSE) 
             ?  PURPLE_STATUS_INVISIBLE
             : PURPLE_STATUS_AVAILABLE);
@@ -1756,6 +1777,11 @@
 			purple_status_code = PURPLE_STATUS_AWAY;
 			break;
 
+        case MSIM_STATUS_CODE_IDLE:
+            /* will be handled below */
+            purple_status_code = -1;
+            break;
+
 		default:
 				purple_debug_info("msim", "msim_status_cb for %s, unknown status code %d, treating as available\n",
 						username, status_code);
@@ -1766,13 +1792,22 @@
 	if (!strcmp(username, session->username) && purple_status_code == PURPLE_STATUS_OFFLINE)
 	{
 		/* Hack to ignore offline status notices on self. */
-	} else {
+	} else if (status_code != MSIM_STATUS_CODE_IDLE) {
 #endif
 		purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
 #ifdef MSIM_FAKE_SELF_ONLINE
 	}
 #endif
 
+    if (status_code == MSIM_STATUS_CODE_IDLE)
+    {
+        purple_debug_info("msim", "msim_status: got idle: %s\n", username);
+        purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL));
+    } else {
+        /* All other statuses indicate going back to non-idle. */
+        purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL));
+    }
+
     g_strfreev(status_array);
 	g_free(status_str);
 	g_free(username);
@@ -2605,7 +2640,7 @@
     msim_send_typing,  /* send_typing */
 	msim_get_info, 	   /* get_info */
     msim_set_status,   /* set_status */
-    NULL,              /* set_idle */
+    msim_set_idle,     /* set_idle */
     NULL,              /* change_passwd */
     msim_add_buddy,    /* add_buddy */
     NULL,              /* add_buddies */
--- a/libpurple/protocols/myspace/myspace.h	Wed Jul 04 06:37:08 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Wed Jul 04 19:05:21 2007 +0000
@@ -131,6 +131,7 @@
 /* Status codes - states a buddy (or you!) can be in. */
 #define MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN		0
 #define MSIM_STATUS_CODE_ONLINE			1
+#define MSIM_STATUS_CODE_IDLE           2
 #define MSIM_STATUS_CODE_AWAY			5
 /* TODO: hidden */
 
@@ -203,7 +204,8 @@
 void msim_get_info(PurpleConnection *gc, const gchar *name);
 
 void msim_set_status(PurpleAccount *account, PurpleStatus *status);
-void msim_set_status_primitive(MsimSession *session, guint code);
+void msim_set_idle(PurpleConnection *gc, int time);
+void msim_set_status_code(MsimSession *session, guint code);
 
 void msim_store_buddy_info_each(gpointer key, gpointer value, gpointer user_data);
 gboolean msim_store_buddy_info(MsimSession *session, MsimMessage *msg);