| 571 */ |
571 */ |
| 572 int msim_send_im(PurpleConnection *gc, const char *who, |
572 int msim_send_im(PurpleConnection *gc, const char *who, |
| 573 const char *message, PurpleMessageFlags flags) |
573 const char *message, PurpleMessageFlags flags) |
| 574 { |
574 { |
| 575 MsimSession *session; |
575 MsimSession *session; |
| 576 MsimMessage *msg; |
576 |
| 577 const char *from_username = gc->account->username; |
|
| 578 int rc; |
|
| 579 |
|
| 580 g_return_val_if_fail(gc != NULL, 0); |
577 g_return_val_if_fail(gc != NULL, 0); |
| 581 g_return_val_if_fail(who != NULL, 0); |
578 g_return_val_if_fail(who != NULL, 0); |
| 582 g_return_val_if_fail(message != NULL, 0); |
579 g_return_val_if_fail(message != NULL, 0); |
| 583 |
580 |
| 584 /* 'flags' has many options, not used here. */ |
581 /* 'flags' has many options, not used here. */ |
| 585 |
582 |
| 586 purple_debug_info("msim", "sending message from %s to %s: %s\n", |
583 session = gc->proto_data; |
| 587 from_username, who, message); |
584 |
| 588 |
585 /* TODO: const-correctness */ |
| 589 session = gc->proto_data; |
586 if (msim_send_bm(session, (char *)who, (char *)message, MSIM_BM_INSTANT)) |
| 590 |
|
| 591 msg = msim_msg_new(TRUE, |
|
| 592 "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_BM_INSTANT), |
|
| 593 "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey), |
|
| 594 /* 't' will be inserted here */ |
|
| 595 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION), |
|
| 596 "msg", MSIM_TYPE_STRING, g_strdup(message), |
|
| 597 NULL); |
|
| 598 |
|
| 599 if (msim_postprocess_outgoing(session, msg, (char *)who, "t", "cv")) |
|
| 600 { |
587 { |
| 601 |
|
| 602 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always |
588 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always |
| 603 * return 1 even if the message could not be sent, since I don't know if |
589 * return 1 even if the message could not be sent, since I don't know if |
| 604 * it has failed yet--because the IM is only sent after the userid is |
590 * it has failed yet--because the IM is only sent after the userid is |
| 605 * retrieved from the server (which happens after this function returns). |
591 * retrieved from the server (which happens after this function returns). |
| 606 */ |
592 */ |
| 607 rc = 1; |
593 return 1; |
| 608 } else { |
594 } else { |
| 609 rc = -1; |
595 return -1; |
| 610 } |
596 } |
| 611 msim_msg_free(msg); |
|
| 612 |
|
| 613 return rc; |
|
| 614 |
|
| 615 /* |
597 /* |
| 616 * TODO: In MySpace, you login with your email address, but don't talk to other |
598 * TODO: In MySpace, you login with your email address, but don't talk to other |
| 617 * users using their email address. So there is currently an asymmetry in the |
599 * users using their email address. So there is currently an asymmetry in the |
| 618 * IM windows when using this plugin: |
600 * IM windows when using this plugin: |
| 619 * |
601 * |
| 622 * you@example.com: just coding a prpl |
604 * you@example.com: just coding a prpl |
| 623 * |
605 * |
| 624 * TODO: Make the sent IM's appear as from the user's username, instead of |
606 * TODO: Make the sent IM's appear as from the user's username, instead of |
| 625 * their email address. Purple uses the login (in MSIM, the email)--change this. |
607 * their email address. Purple uses the login (in MSIM, the email)--change this. |
| 626 */ |
608 */ |
| |
609 } |
| |
610 |
| |
611 /** Send a buddy message of a given type. |
| |
612 * |
| |
613 * @param session |
| |
614 * @param who Username to send message to. |
| |
615 * @param text Message text to send. Not freed; will be copied. |
| |
616 * @param type A MSIM_BM_* constant. |
| |
617 * |
| |
618 * Buddy messages ('bm') include instant messages, action messages, status messages, etc. |
| |
619 */ |
| |
620 gboolean msim_send_bm(MsimSession *session, gchar *who, gchar *text, int type) |
| |
621 { |
| |
622 gboolean rc; |
| |
623 MsimMessage *msg; |
| |
624 const char *from_username = session->account->username; |
| |
625 |
| |
626 purple_debug_info("msim", "sending %d message from %s to %s: %s\n", |
| |
627 type, from_username, who, text); |
| |
628 |
| |
629 msg = msim_msg_new(TRUE, |
| |
630 "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type), |
| |
631 "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey), |
| |
632 /* 't' will be inserted here */ |
| |
633 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION), |
| |
634 "msg", MSIM_TYPE_STRING, g_strdup(text), |
| |
635 NULL); |
| |
636 |
| |
637 rc = msim_postprocess_outgoing(session, msg, (char *)who, "t", "cv"); |
| |
638 |
| |
639 msim_msg_free(msg); |
| |
640 |
| |
641 return rc; |
| 627 } |
642 } |
| 628 |
643 |
| 629 /** |
644 /** |
| 630 * Handle an incoming instant message. |
645 * Handle an incoming instant message. |
| 631 * |
646 * |
| 717 typing_str = "%stoptyping%"; |
735 typing_str = "%stoptyping%"; |
| 718 break; |
736 break; |
| 719 } |
737 } |
| 720 |
738 |
| 721 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str); |
739 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str); |
| 722 //msim_send_action(name, typing_str); |
740 msim_send_bm(session, (gchar *)name, typing_str, MSIM_BM_ACTION); |
| 723 return 0; |
741 return 0; |
| 724 } |
742 } |
| 725 |
743 |
| 726 /** After a uid is resolved to username, tag it with the username and submit for processing. |
744 /** After a uid is resolved to username, tag it with the username and submit for processing. |
| 727 * |
745 * |