changeset 17346:73720427b132

Show online buddies on buddy list as online.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 02 Jun 2007 20:57:11 +0000
parents d353afe1aa12
children aa8e70fa1edc
files libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h
diffstat 2 files changed, 51 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Sat Jun 02 04:55:07 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sat Jun 02 20:57:11 2007 +0000
@@ -980,15 +980,14 @@
 {
     PurpleBuddyList *blist;
     PurpleBuddy *buddy;
-    PurplePresence *presence;
     GHashTable *body;
 	gchar *body_str;
     //PurpleStatus *status;
     gchar **status_array;
     GList *list;
-    gchar *status_text, *status_code;
+    gchar *status_headline;
     gchar *status_str;
-    gint i;
+    gint i, status_code, purple_status_code;
     gchar *username;
 
     g_return_if_fail(MSIM_SESSION_VALID(session));
@@ -1015,18 +1014,28 @@
 			"msim_status_cb: updating status for <%s> to <%s>\n", 
 			username, status_str);
 
-    /* TODO: generic functions to split into a GList */
+    /* TODO: generic functions to split into a GList, part of MsimMessage */
     status_array = g_strsplit(status_str, "|", 0);
     for (list = NULL, i = 0;
             status_array[i];
             i++)
     {
+		/* Note: this adds the 0th ordinal too, which might not be a value
+		 * at all (the 0 in the 0|1|2|3... status fields, but 0 always appears blank).
+		 */
         list = g_list_append(list, status_array[i]);
     }
 
-    /* Example fields: |s|0|ss|Offline */
-    status_code = g_list_nth_data(list, 2);
-    status_text = g_list_nth_data(list, 4);
+    /* Example fields: 
+	 *  |s|0|ss|Offline 
+	 *  |s|1|ss|:-)|ls||ip|0|p|0 
+	 *
+	 * TODO: write list support in MsimMessage, and use it here.
+	 */
+
+    status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
+	purple_debug_info("msim", "msim_status_cb: %s's status code = %d\n", username, status_code);
+    status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE);
 
     blist = purple_get_blist();
 
@@ -1045,11 +1054,21 @@
         purple_debug_info("msim", "msim_status: found buddy %s\n", username);
     }
 
-    /* For now, always set status to online. 
-     * TODO: make status reflect reality
-     * TODO: show headline */
-    presence = purple_presence_new_for_buddy(buddy);
-    /* purple_presence_set_status_active(presence, PURPLE_STATUS_AVAILABLE, TRUE); */
+    /* TODO: show headline */
+  
+    /* Set user status */	
+    switch (status_code)
+	{
+		case 1: purple_status_code = PURPLE_STATUS_AVAILABLE;
+				break;
+		case 0: purple_status_code = PURPLE_STATUS_OFFLINE;	
+				break;
+		default:
+				purple_debug_info("msim", "msim_status_cb for %s, unknown status code %d\n",
+						username, status_code);
+				purple_status_code = PURPLE_STATUS_AVAILABLE;
+	}
+	purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
 
     g_strfreev(status_array);
     g_list_free(list);
@@ -1538,9 +1557,9 @@
     NULL,              /* set_away */
     NULL,              /* set_idle */
     NULL,              /* change_passwd */
-    NULL,              /* add_buddy */
+    NULL,              /* add_buddy TODO */
     NULL,              /* add_buddies */
-    NULL,              /* remove_buddy */
+    NULL,              /* remove_buddy TODO */
     NULL,              /* remove_buddies */
     NULL,              /* add_permit */
     NULL,              /* add_deny */
@@ -1593,15 +1612,15 @@
     PURPLE_PLUGIN_MAGIC,                                
     PURPLE_MAJOR_VERSION,
     PURPLE_MINOR_VERSION,
-    PURPLE_PLUGIN_PROTOCOL,                             /**< type           */
-    NULL,                                             /**< ui_requirement */
-    0,                                                /**< flags          */
-    NULL,                                             /**< dependencies   */
-    PURPLE_PRIORITY_DEFAULT,                            /**< priority       */
+    PURPLE_PLUGIN_PROTOCOL,                            /**< type           */
+    NULL,                                              /**< ui_requirement */
+    0,                                                 /**< flags          */
+    NULL,                                              /**< dependencies   */
+    PURPLE_PRIORITY_DEFAULT,                           /**< priority       */
 
     "prpl-myspace",                                   /**< id             */
     "MySpaceIM",                                      /**< name           */
-    "0.6"                                             /**< version        */
+    "0.6",                                            /**< version        */
                                                       /**  summary        */
     "MySpaceIM Protocol Plugin",
                                                       /**  description    */
--- a/libpurple/protocols/myspace/myspace.h	Sat Jun 02 04:55:07 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Sat Jun 02 20:57:11 2007 +0000
@@ -92,6 +92,18 @@
 /* Authentication algorithm for login2 */
 #define MSIM_AUTH_ALGORITHM	196610
 
+/* Indexes into status string (0|1|2|3|..., but 0 always empty) */
+#define MSIM_STATUS_ORDINAL_EMPTY		0
+#define MSIM_STATUS_ORDINAL_UNKNOWNs	1
+#define MSIM_STATUS_ORDINAL_ONLINE		2
+#define MSIM_STATUS_ORDINAL_UNKNOWNss	3
+#define MSIM_STATUS_ORDINAL_HEADLINE	4
+#define MSIM_STATUS_ORDINAL_UNKNOWNls	5
+#define MSIM_STATUS_ORDINAL_UNKNOWN		6
+#define MSIM_STATUS_ORDINAL_UNKNOWN1	7
+#define MSIM_STATUS_ORDINAL_UNKNOWNp	8
+#define MSIM_STATUS_ORDINAL_UNKNOWN2	9
+
 /* Random number in every MsimSession, to ensure it is valid. */
 #define MSIM_SESSION_STRUCT_MAGIC       0xe4a6752b