| 571 * response is received from the server. |
571 * response is received from the server. |
| 572 * |
572 * |
| 573 * The callback function calls msim_send_im_by_userid() to send the actual |
573 * The callback function calls msim_send_im_by_userid() to send the actual |
| 574 * instant message. If a userid is specified directly, this function is called |
574 * instant message. If a userid is specified directly, this function is called |
| 575 * immediately here. |
575 * immediately here. |
| |
576 * |
| |
577 * TODO: change all that above. |
| 576 */ |
578 */ |
| 577 int msim_send_im(PurpleConnection *gc, const char *who, |
579 int msim_send_im(PurpleConnection *gc, const char *who, |
| 578 const char *message, PurpleMessageFlags flags) |
580 const char *message, PurpleMessageFlags flags) |
| 579 { |
581 { |
| 580 MsimSession *session; |
582 MsimSession *session; |
| 600 } |
602 } |
| 601 |
603 |
| 602 /* Otherwise, add callback to IM when userid of destination is available */ |
604 /* Otherwise, add callback to IM when userid of destination is available */ |
| 603 |
605 |
| 604 /* Setup a callback for when the userid is available */ |
606 /* Setup a callback for when the userid is available */ |
| |
607 /* TODO: instead, create and pass an MsimMessage */ |
| 605 cbinfo = g_new0(send_im_cb_struct, 1); |
608 cbinfo = g_new0(send_im_cb_struct, 1); |
| 606 cbinfo->who = g_strdup(who); |
609 cbinfo->who = g_strdup(who); |
| 607 cbinfo->message = g_strdup(message); |
610 cbinfo->message = g_strdup(message); |
| 608 cbinfo->flags = flags; |
611 cbinfo->flags = flags; |
| 609 |
612 |
| 610 /* Send the request to lookup the userid */ |
613 /* Send the request to lookup the userid */ |
| |
614 /* TODO: don't use callbacks */ |
| 611 msim_lookup_user(session, who, msim_send_im_by_userid_cb, cbinfo); |
615 msim_lookup_user(session, who, msim_send_im_by_userid_cb, cbinfo); |
| 612 |
616 |
| 613 /* msim_send_im_by_userid_cb will now be called once userid is looked up */ |
617 /* msim_send_im_by_userid_cb will now be called once userid is looked up */ |
| 614 |
618 |
| 615 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always |
619 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always |
| 754 |
758 |
| 755 purple_debug_info("msim", |
759 purple_debug_info("msim", |
| 756 "msim_incoming_im: got msg <%s> from <%s>, resolving username\n", |
760 "msim_incoming_im: got msg <%s> from <%s>, resolving username\n", |
| 757 msg_text, userid); |
761 msg_text, userid); |
| 758 |
762 |
| |
763 /* TODO: don't use callbacks */ |
| 759 msim_lookup_user(session, userid, msim_incoming_im_cb, msg_text); |
764 msim_lookup_user(session, userid, msim_incoming_im_cb, msg_text); |
| 760 |
765 |
| 761 return TRUE; |
766 return TRUE; |
| 762 } |
767 } |
| 763 |
768 |
| 1035 |
1040 |
| 1036 username = g_hash_table_lookup(body, "UserName"); |
1041 username = g_hash_table_lookup(body, "UserName"); |
| 1037 /* Note: DisplayName doesn't seem to be resolvable. It could be displayed on |
1042 /* Note: DisplayName doesn't seem to be resolvable. It could be displayed on |
| 1038 * the buddy list, if the UserID was stored along with it. */ |
1043 * the buddy list, if the UserID was stored along with it. */ |
| 1039 |
1044 |
| 1040 if (!username) |
1045 g_return_if_fail(username != NULL); |
| 1041 { |
|
| 1042 purple_debug_info("msim", "msim_status_cb: no username?!\n"); |
|
| 1043 return; |
|
| 1044 } |
|
| 1045 |
1046 |
| 1046 purple_debug_info("msim", |
1047 purple_debug_info("msim", |
| 1047 "msim_status_cb: updating status for <%s> to <%s>\n", |
1048 "msim_status_cb: updating status for <%s> to <%s>\n", |
| 1048 username, status_str); |
1049 username, status_str); |
| 1049 |
1050 |
| 1079 /* TODO: purple aliases, userids and usernames */ |
1080 /* TODO: purple aliases, userids and usernames */ |
| 1080 purple_debug_info("msim", |
1081 purple_debug_info("msim", |
| 1081 "msim_status: making new buddy for %s\n", username); |
1082 "msim_status: making new buddy for %s\n", username); |
| 1082 buddy = purple_buddy_new(session->account, username, NULL); |
1083 buddy = purple_buddy_new(session->account, username, NULL); |
| 1083 |
1084 |
| 1084 /* TODO: sometimes (when click on it), buddy list disappears. Fix. */ |
|
| 1085 purple_blist_add_buddy(buddy, NULL, NULL, NULL); |
1085 purple_blist_add_buddy(buddy, NULL, NULL, NULL); |
| 1086 //purple_blist_set_int(&buddy->node, "uid", XYZ); |
1086 /* All buddies on list should have 'uid' integer associated with them. */ |
| 1087 exit(0); |
1087 purple_blist_node_set_int(&buddy->node, "uid", atoi(g_hash_table_lookup(body, "UserID"))); |
| |
1088 purple_debug_info("msim", "UID=%d\n", purple_blist_node_get_int(&buddy->node, "uid")); |
| 1088 } else { |
1089 } else { |
| 1089 purple_debug_info("msim", "msim_status: found buddy %s\n", username); |
1090 purple_debug_info("msim", "msim_status: found buddy %s\n", username); |
| 1090 } |
1091 } |
| 1091 |
1092 |
| 1092 /* TODO: show headline */ |
1093 /* TODO: show headline */ |
| 1133 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
1134 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
| 1134 g_return_val_if_fail(msg != NULL, FALSE); |
1135 g_return_val_if_fail(msg != NULL, FALSE); |
| 1135 |
1136 |
| 1136 /* TODO: free */ |
1137 /* TODO: free */ |
| 1137 status_str = msim_msg_get_string(msg, "msg"); |
1138 status_str = msim_msg_get_string(msg, "msg"); |
| 1138 if (!status_str) |
1139 g_return_val_if_fail(status != NULL, FALSE); |
| 1139 { |
|
| 1140 purple_debug_info("msim", "msim_status: bm is status but no status msg\n"); |
|
| 1141 return FALSE; |
|
| 1142 } |
|
| 1143 |
1140 |
| 1144 /* TODO: free */ |
1141 /* TODO: free */ |
| 1145 userid = msim_msg_get_string(msg, "f"); |
1142 userid = msim_msg_get_string(msg, "f"); |
| 1146 if (!userid) |
1143 g_return_val_if_fail(userid != NULL, FALSE); |
| 1147 { |
|
| 1148 purple_debug_info("msim", "msim_status: bm is status but no f field\n"); |
|
| 1149 return FALSE; |
|
| 1150 } |
|
| 1151 |
1144 |
| 1152 /* TODO: if buddies were identified on buddy list by uid, wouldn't have to lookup |
1145 /* TODO: if buddies were identified on buddy list by uid, wouldn't have to lookup |
| 1153 * before updating the status! Much more efficient. */ |
1146 * before updating the status! Much more efficient. */ |
| 1154 purple_debug_info("msim", |
1147 purple_debug_info("msim", |
| 1155 "msim_status: got status msg <%s> for <%s>, scheduling lookup\n", |
1148 "msim_status: got status msg <%s> for <%s>, scheduling lookup\n", |
| 1158 /* Actually update status, once username is obtained. |
1151 /* Actually update status, once username is obtained. |
| 1159 * status_str() will currently be freed by g_hash_table_destroy() on |
1152 * status_str() will currently be freed by g_hash_table_destroy() on |
| 1160 * user_lookup_cb_data (TODO: this is questionable, since it can also |
1153 * user_lookup_cb_data (TODO: this is questionable, since it can also |
| 1161 * store gpointers. Fix this, and the 2 other TODOs of the same problem.) |
1154 * store gpointers. Fix this, and the 2 other TODOs of the same problem.) |
| 1162 */ |
1155 */ |
| |
1156 /* TODO: don't use callbacks */ |
| 1163 msim_lookup_user(session, userid, msim_status_cb, status_str); |
1157 msim_lookup_user(session, userid, msim_status_cb, status_str); |
| 1164 |
1158 |
| 1165 return TRUE; |
1159 return TRUE; |
| 1166 } |
1160 } |
| 1167 |
1161 |
| 1518 * @param session |
1512 * @param session |
| 1519 * @param user The user id, email address, or username. |
1513 * @param user The user id, email address, or username. |
| 1520 * @param cb Callback, called with user information when available. |
1514 * @param cb Callback, called with user information when available. |
| 1521 * @param data An arbitray data pointer passed to the callback. |
1515 * @param data An arbitray data pointer passed to the callback. |
| 1522 */ |
1516 */ |
| |
1517 /* TODO: change to not use callbacks */ |
| 1523 void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data) |
1518 void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data) |
| 1524 { |
1519 { |
| 1525 gchar *field_name; |
1520 gchar *field_name; |
| 1526 guint rid, cmd, dsn, lid; |
1521 guint rid, cmd, dsn, lid; |
| 1527 |
1522 |