Mercurial > pidgin.yaz
diff libpurple/protocols/myspace/myspace.c @ 17372:d9aaccef8721
Send typing notifications (tested).
Added msim_send_bm() to send a generic buddy message, used by msim_send_im()
and msim_send_typing().
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Tue, 12 Jun 2007 03:40:38 +0000 |
parents | 948373cbba1c |
children | 2aff11bb5e72 |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c Mon Jun 11 06:17:16 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Tue Jun 12 03:40:38 2007 +0000 @@ -573,45 +573,27 @@ const char *message, PurpleMessageFlags flags) { MsimSession *session; - MsimMessage *msg; - const char *from_username = gc->account->username; - int rc; - + g_return_val_if_fail(gc != NULL, 0); g_return_val_if_fail(who != NULL, 0); g_return_val_if_fail(message != NULL, 0); /* 'flags' has many options, not used here. */ - purple_debug_info("msim", "sending message from %s to %s: %s\n", - from_username, who, message); - - session = gc->proto_data; + session = gc->proto_data; - msg = msim_msg_new(TRUE, - "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_BM_INSTANT), - "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey), - /* 't' will be inserted here */ - "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION), - "msg", MSIM_TYPE_STRING, g_strdup(message), - NULL); - - if (msim_postprocess_outgoing(session, msg, (char *)who, "t", "cv")) + /* TODO: const-correctness */ + if (msim_send_bm(session, (char *)who, (char *)message, MSIM_BM_INSTANT)) { - /* 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 * retrieved from the server (which happens after this function returns). */ - rc = 1; + return 1; } else { - rc = -1; + return -1; } - msim_msg_free(msg); - - return rc; - /* * TODO: In MySpace, you login with your email address, but don't talk to other * users using their email address. So there is currently an asymmetry in the @@ -626,6 +608,39 @@ */ } +/** Send a buddy message of a given type. + * + * @param session + * @param who Username to send message to. + * @param text Message text to send. Not freed; will be copied. + * @param type A MSIM_BM_* constant. + * + * Buddy messages ('bm') include instant messages, action messages, status messages, etc. + */ +gboolean msim_send_bm(MsimSession *session, gchar *who, gchar *text, int type) +{ + gboolean rc; + MsimMessage *msg; + const char *from_username = session->account->username; + + purple_debug_info("msim", "sending %d message from %s to %s: %s\n", + type, from_username, who, text); + + msg = msim_msg_new(TRUE, + "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type), + "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey), + /* 't' will be inserted here */ + "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION), + "msg", MSIM_TYPE_STRING, g_strdup(text), + NULL); + + rc = msim_postprocess_outgoing(session, msg, (char *)who, "t", "cv"); + + msim_msg_free(msg); + + return rc; +} + /** * Handle an incoming instant message. * @@ -704,6 +719,9 @@ unsigned int msim_send_typing(PurpleConnection *gc, const char *name, PurpleTypingState state) { char *typing_str; + MsimSession *session; + + session = (MsimSession *)gc->proto_data; switch (state) { @@ -719,7 +737,7 @@ } purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str); - //msim_send_action(name, typing_str); + msim_send_bm(session, (gchar *)name, typing_str, MSIM_BM_ACTION); return 0; }