changeset 27027:fdc0035bea5a

Change the way we parse messages on MySpace a little bit. This fixes #8846: people using web myspaceIM can't respond to pidgin myspaceIM For some reason IMs send using the myspace web site are sent so that they won't become offline messages if the other person is offline. I'm not really sure why that decision was made. So now we treat messages with bm 1 the same as messages with bm 121. This means we have to combine the function that parses out typing notification with the function that parses IMs. And we check for typing notifications by looking for %typing%. Which means if someone sends the IM "%typing%" with no markup then we'll interpret it as a typing notification. And there's nothing we can do to differentiate between the two. I asked.
author Mark Doliner <mark@kingant.net>
date Thu, 04 Jun 2009 05:19:49 +0000
parents 53294b47a4a6
children 3acb76e56517
files libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h libpurple/protocols/myspace/zap.c
diffstat 3 files changed, 26 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Thu Jun 04 01:51:41 2009 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Thu Jun 04 05:19:49 2009 +0000
@@ -1473,28 +1473,22 @@
  * @return TRUE if successful.
  */
 static gboolean
-msim_incoming_im(MsimSession *session, MsimMessage *msg)
+msim_incoming_im(MsimSession *session, MsimMessage *msg, const gchar *username)
 {
-	gchar *username, *msg_msim_markup, *msg_purple_markup;
+	gchar *msg_msim_markup, *msg_purple_markup;
 	gchar *userid;
 	time_t time_received;
 	PurpleConversation *conv;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
-	g_return_val_if_fail(msg != NULL, FALSE);
-
-	username = msim_msg_get_string(msg, "_username");
 	/* I know this isn't really a string... but we need it to be one for
 	 * purple_find_conversation_with_account(). */
 	userid = msim_msg_get_string(msg, "f");
-	g_return_val_if_fail(username != NULL, FALSE);
 
 	purple_debug_info("msim_incoming_im", "UserID is %s", userid);
 
 	if (msim_is_userid(username)) {
 		purple_debug_info("msim", "Ignoring message from spambot (%s) on account %s\n",
 				username, purple_account_get_username(session->account));
-		g_free(username);
 		return FALSE;
 	}
 
@@ -1519,14 +1513,13 @@
 
 	serv_got_im(session->gc, username, msg_purple_markup, PURPLE_MESSAGE_RECV, time_received);
 
-	g_free(username);
 	g_free(msg_purple_markup);
 
 	return TRUE;
 }
 
 /**
- * Handle an incoming action message.
+ * Handle an incoming action message or an IM.
  *
  * @param session
  * @param msg
@@ -1534,7 +1527,7 @@
  * @return TRUE if successful.
  */
 static gboolean
-msim_incoming_action(MsimSession *session, MsimMessage *msg)
+msim_incoming_action_or_im(MsimSession *session, MsimMessage *msg)
 {
 	gchar *msg_text, *username;
 	gboolean rc;
@@ -1548,7 +1541,8 @@
 	username = msim_msg_get_string(msg, "_username");
 	g_return_val_if_fail(username != NULL, FALSE);
 
-	purple_debug_info("msim", "msim_incoming_action: action <%s> from <%s>\n",
+	purple_debug_info("msim",
+			"msim_incoming_action_or_im: action <%s> from <%s>\n",
 			msg_text, username);
 
 	if (g_str_equal(msg_text, "%typing%")) {
@@ -1562,13 +1556,16 @@
 	} else if (strstr(msg_text, "!!!GroupCount=")) {
 		/* TODO: support group chats. I think the number in msg_text has
 		 * something to do with the 'gid' field. */
-		purple_debug_info("msim", "msim_incoming_action: TODO: implement #4691, group chats: %s\n", msg_text);
+		purple_debug_info("msim",
+				"msim_incoming_action_or_im: "
+				"TODO: implement #4691, group chats: %s\n", msg_text);
 
 		rc = TRUE;
 	} else if (strstr(msg_text, "!!!Offline=")) {
 		/* TODO: support group chats. This one might mean a user
 		 * went offline or exited the chat. */
-		purple_debug_info("msim", "msim_incoming_action: TODO: implement #4691, group chats: %s\n", msg_text);
+		purple_debug_info("msim", "msim_incoming_action_or_im: "
+				"TODO: implement #4691, group chats: %s\n", msg_text);
 
 		rc = TRUE;
 	} else if (msim_msg_get_integer(msg, "aid") != 0) {
@@ -1579,9 +1576,7 @@
 
 		rc = TRUE;
 	} else {
-		msim_unrecognized(session, msg,
-				"got to msim_incoming_action but unrecognized value for 'msg'");
-		rc = FALSE;
+		rc = msim_incoming_im(session, msg, username);
 	}
 
 	g_free(msg_text);
@@ -1666,10 +1661,9 @@
 	switch (bm) {
 		case MSIM_BM_STATUS:
 			return msim_incoming_status(session, msg);
-		case MSIM_BM_INSTANT:
-			return msim_incoming_im(session, msg);
-		case MSIM_BM_ACTION:
-			return msim_incoming_action(session, msg);
+		case MSIM_BM_INSTANT_ACTION_OR_IM:
+		case MSIM_BM_DELAYABLE_ACTION_OR_IM:
+			return msim_incoming_action_or_im(session, msg);
 		case MSIM_BM_MEDIA:
 			return msim_incoming_media(session, msg);
 		case MSIM_BM_UNOFFICIAL_CLIENT:
@@ -1677,7 +1671,8 @@
 		default:
 			/* Not really an IM, but show it for informational
 			 * purposes during development. */
-			return msim_incoming_im(session, msg);
+			/* TODO: This is probably wrong */
+			return msim_incoming_action_or_im(session, msg);
 	}
 }
 
@@ -2290,7 +2285,7 @@
 
 	message_msim = html_to_msim_markup(session, message);
 
-	if (msim_send_bm(session, who, message_msim, MSIM_BM_INSTANT)) {
+	if (msim_send_bm(session, who, message_msim, MSIM_BM_DELAYABLE_ACTION_OR_IM)) {
 		/* Return 1 to have Purple show this IM as being sent, 0 to not. I always
 		 * return 1 even if the message could not be sent, since I don't know if
 		 * it has failed yet--because the IM is only sent after the userid is
@@ -2343,7 +2338,7 @@
 	}
 
 	purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str);
-	msim_send_bm(session, name, typing_str, MSIM_BM_ACTION);
+	msim_send_bm(session, name, typing_str, MSIM_BM_INSTANT_ACTION_OR_IM);
 	return 0;
 }
 
--- a/libpurple/protocols/myspace/myspace.h	Thu Jun 04 01:51:41 2009 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Thu Jun 04 05:19:49 2009 +0000
@@ -127,12 +127,12 @@
 #define MSIM_FINAL_STRING           "\\final\\" /**< Message end marker */
 
 /* Messages */
-#define MSIM_BM_INSTANT             1
-#define MSIM_BM_STATUS              100
-#define MSIM_BM_ACTION              121
-#define MSIM_BM_MEDIA               122
-#define MSIM_BM_PROFILE             124
-#define MSIM_BM_UNOFFICIAL_CLIENT   200
+#define MSIM_BM_DELAYABLE_ACTION_OR_IM  1
+#define MSIM_BM_STATUS                  100
+#define MSIM_BM_INSTANT_ACTION_OR_IM    121
+#define MSIM_BM_MEDIA                   122
+#define MSIM_BM_PROFILE                 124
+#define MSIM_BM_UNOFFICIAL_CLIENT       200
 
 /* Authentication algorithm for login2 */
 #define MSIM_AUTH_ALGORITHM         196610
--- a/libpurple/protocols/myspace/zap.c	Thu Jun 04 01:51:41 2009 +0000
+++ b/libpurple/protocols/myspace/zap.c	Thu Jun 04 05:19:49 2009 +0000
@@ -109,7 +109,7 @@
 	/* Construct and send the actual zap command. */
 	zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", code);
 
-	if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION)) {
+	if (!msim_send_bm(session, username, zap_string, MSIM_BM_INSTANT_ACTION_OR_IM)) {
 		purple_debug_info("msim_send_zap",
 				"msim_send_bm failed: zapping %s with %s\n",
 				username, zap_string);