| 1970 |
1970 |
| 1971 user = msim_get_user_from_buddy(buddy); |
1971 user = msim_get_user_from_buddy(buddy); |
| 1972 user->id = msim_msg_get_integer(msg, "f"); |
1972 user->id = msim_msg_get_integer(msg, "f"); |
| 1973 |
1973 |
| 1974 /* Keep track of the user ID across sessions */ |
1974 /* Keep track of the user ID across sessions */ |
| 1975 purple_blist_node_set_int(&buddy->node, "UserID", user->id); |
1975 purple_blist_node_set_int((PurpleBlistNode *)buddy, "UserID", user->id); |
| 1976 |
1976 |
| 1977 msim_store_user_info(session, msg, NULL); |
1977 msim_store_user_info(session, msg, NULL); |
| 1978 } else { |
1978 } else { |
| 1979 purple_debug_info("msim", "msim_status: found buddy %s\n", username); |
1979 purple_debug_info("msim", "msim_status: found buddy %s\n", username); |
| 1980 } |
1980 } |
| 2063 { |
2063 { |
| 2064 MsimSession *session; |
2064 MsimSession *session; |
| 2065 MsimMessage *msg; |
2065 MsimMessage *msg; |
| 2066 MsimMessage *msg_persist; |
2066 MsimMessage *msg_persist; |
| 2067 MsimMessage *body; |
2067 MsimMessage *body; |
| |
2068 const char *name, *gname; |
| 2068 |
2069 |
| 2069 session = (MsimSession *)gc->proto_data; |
2070 session = (MsimSession *)gc->proto_data; |
| |
2071 name = purple_buddy_get_name(buddy); |
| |
2072 gname = group ? purple_group_get_name(group) : NULL; |
| |
2073 |
| 2070 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", |
2074 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", |
| 2071 buddy->name, (group && group->name) ? group->name : "(no group)"); |
2075 name, gname ? gname : "(no group)"); |
| 2072 |
2076 |
| 2073 msg = msim_msg_new( |
2077 msg = msim_msg_new( |
| 2074 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE, |
2078 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE, |
| 2075 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
2079 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
| 2076 /* "newprofileid" will be inserted here with uid. */ |
2080 /* "newprofileid" will be inserted here with uid. */ |
| 2077 "reason", MSIM_TYPE_STRING, g_strdup(""), |
2081 "reason", MSIM_TYPE_STRING, g_strdup(""), |
| 2078 NULL); |
2082 NULL); |
| 2079 |
2083 |
| 2080 if (!msim_postprocess_outgoing(session, msg, buddy->name, "newprofileid", "reason")) { |
2084 if (!msim_postprocess_outgoing(session, msg, name, "newprofileid", "reason")) { |
| 2081 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed.")); |
2085 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed.")); |
| 2082 msim_msg_free(msg); |
2086 msim_msg_free(msg); |
| 2083 return; |
2087 return; |
| 2084 } |
2088 } |
| 2085 msim_msg_free(msg); |
2089 msim_msg_free(msg); |
| 2087 /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from |
2091 /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from |
| 2088 * buddy list since Purple adds it locally. */ |
2092 * buddy list since Purple adds it locally. */ |
| 2089 |
2093 |
| 2090 body = msim_msg_new( |
2094 body = msim_msg_new( |
| 2091 "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"), |
2095 "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"), |
| 2092 "GroupName", MSIM_TYPE_STRING, g_strdup(group->name), |
2096 "GroupName", MSIM_TYPE_STRING, g_strdup(gname), |
| 2093 "Position", MSIM_TYPE_INTEGER, 1000, |
2097 "Position", MSIM_TYPE_INTEGER, 1000, |
| 2094 "Visibility", MSIM_TYPE_INTEGER, 1, |
2098 "Visibility", MSIM_TYPE_INTEGER, 1, |
| 2095 "NickName", MSIM_TYPE_STRING, g_strdup(""), |
2099 "NickName", MSIM_TYPE_STRING, g_strdup(""), |
| 2096 "NameSelect", MSIM_TYPE_INTEGER, 0, |
2100 "NameSelect", MSIM_TYPE_INTEGER, 0, |
| 2097 NULL); |
2101 NULL); |
| 2108 /* TODO: Use msim_new_reply_callback to get rid. */ |
2112 /* TODO: Use msim_new_reply_callback to get rid. */ |
| 2109 "rid", MSIM_TYPE_INTEGER, session->next_rid++, |
2113 "rid", MSIM_TYPE_INTEGER, session->next_rid++, |
| 2110 "body", MSIM_TYPE_DICTIONARY, body, |
2114 "body", MSIM_TYPE_DICTIONARY, body, |
| 2111 NULL); |
2115 NULL); |
| 2112 |
2116 |
| 2113 if (!msim_postprocess_outgoing(session, msg_persist, buddy->name, "body", NULL)) |
2117 if (!msim_postprocess_outgoing(session, msg_persist, name, "body", NULL)) |
| 2114 { |
2118 { |
| 2115 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed")); |
2119 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed")); |
| 2116 msim_msg_free(msg_persist); |
2120 msim_msg_free(msg_persist); |
| 2117 return; |
2121 return; |
| 2118 } |
2122 } |
| 2284 uid = atol(username); |
2288 uid = atol(username); |
| 2285 } else { |
2289 } else { |
| 2286 /* Next, see if on buddy list and know uid. */ |
2290 /* Next, see if on buddy list and know uid. */ |
| 2287 buddy = purple_find_buddy(session->account, username); |
2291 buddy = purple_find_buddy(session->account, username); |
| 2288 if (buddy) { |
2292 if (buddy) { |
| 2289 uid = purple_blist_node_get_int(&buddy->node, "UserID"); |
2293 uid = purple_blist_node_get_int((PurpleBlistNode *)buddy, "UserID"); |
| 2290 } else { |
2294 } else { |
| 2291 uid = 0; |
2295 uid = 0; |
| 2292 } |
2296 } |
| 2293 |
2297 |
| 2294 if (!buddy || !uid) { |
2298 if (!buddy || !uid) { |
| 2326 MsimSession *session; |
2330 MsimSession *session; |
| 2327 MsimMessage *delbuddy_msg; |
2331 MsimMessage *delbuddy_msg; |
| 2328 MsimMessage *persist_msg; |
2332 MsimMessage *persist_msg; |
| 2329 MsimMessage *blocklist_msg; |
2333 MsimMessage *blocklist_msg; |
| 2330 GList *blocklist_updates; |
2334 GList *blocklist_updates; |
| |
2335 const char *name; |
| 2331 |
2336 |
| 2332 session = (MsimSession *)gc->proto_data; |
2337 session = (MsimSession *)gc->proto_data; |
| |
2338 name = purple_buddy_get_name(buddy); |
| 2333 |
2339 |
| 2334 delbuddy_msg = msim_msg_new( |
2340 delbuddy_msg = msim_msg_new( |
| 2335 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE, |
2341 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE, |
| 2336 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
2342 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
| 2337 /* 'delprofileid' with uid will be inserted here. */ |
2343 /* 'delprofileid' with uid will be inserted here. */ |
| 2338 NULL); |
2344 NULL); |
| 2339 |
2345 |
| 2340 if (!msim_postprocess_outgoing(session, delbuddy_msg, buddy->name, "delprofileid", NULL)) { |
2346 if (!msim_postprocess_outgoing(session, delbuddy_msg, name, "delprofileid", NULL)) { |
| 2341 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed")); |
2347 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed")); |
| 2342 msim_msg_free(delbuddy_msg); |
2348 msim_msg_free(delbuddy_msg); |
| 2343 return; |
2349 return; |
| 2344 } |
2350 } |
| 2345 msim_msg_free(delbuddy_msg); |
2351 msim_msg_free(delbuddy_msg); |
| 2354 "rid", MSIM_TYPE_INTEGER, session->next_rid++, |
2360 "rid", MSIM_TYPE_INTEGER, session->next_rid++, |
| 2355 /* <uid> will be replaced by postprocessing */ |
2361 /* <uid> will be replaced by postprocessing */ |
| 2356 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"), |
2362 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"), |
| 2357 NULL); |
2363 NULL); |
| 2358 |
2364 |
| 2359 if (!msim_postprocess_outgoing(session, persist_msg, buddy->name, "body", NULL)) { |
2365 if (!msim_postprocess_outgoing(session, persist_msg, name, "body", NULL)) { |
| 2360 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed")); |
2366 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed")); |
| 2361 msim_msg_free(persist_msg); |
2367 msim_msg_free(persist_msg); |
| 2362 return; |
2368 return; |
| 2363 } |
2369 } |
| 2364 msim_msg_free(persist_msg); |
2370 msim_msg_free(persist_msg); |
| 2376 /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */ |
2382 /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */ |
| 2377 /* "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"), */ |
2383 /* "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"), */ |
| 2378 "idlist", MSIM_TYPE_LIST, blocklist_updates, |
2384 "idlist", MSIM_TYPE_LIST, blocklist_updates, |
| 2379 NULL); |
2385 NULL); |
| 2380 |
2386 |
| 2381 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL)) { |
2387 if (!msim_postprocess_outgoing(session, blocklist_msg, name, "idlist", NULL)) { |
| 2382 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed")); |
2388 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed")); |
| 2383 msim_msg_free(blocklist_msg); |
2389 msim_msg_free(blocklist_msg); |
| 2384 return; |
2390 return; |
| 2385 } |
2391 } |
| 2386 msim_msg_free(blocklist_msg); |
2392 msim_msg_free(blocklist_msg); |
| 2730 msim_status_text(PurpleBuddy *buddy) |
2736 msim_status_text(PurpleBuddy *buddy) |
| 2731 { |
2737 { |
| 2732 MsimSession *session; |
2738 MsimSession *session; |
| 2733 MsimUser *user; |
2739 MsimUser *user; |
| 2734 const gchar *display_name, *headline; |
2740 const gchar *display_name, *headline; |
| |
2741 PurpleAccount *account; |
| |
2742 PurpleConnection *gc; |
| 2735 |
2743 |
| 2736 g_return_val_if_fail(buddy != NULL, NULL); |
2744 g_return_val_if_fail(buddy != NULL, NULL); |
| 2737 |
2745 |
| 2738 user = msim_get_user_from_buddy(buddy); |
2746 user = msim_get_user_from_buddy(buddy); |
| 2739 |
2747 |
| 2740 session = (MsimSession *)buddy->account->gc->proto_data; |
2748 account = purple_buddy_get_account(buddy); |
| |
2749 gc = purple_account_get_connection(account); |
| |
2750 session = (MsimSession *)gc->proto_data; |
| 2741 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); |
2751 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); |
| 2742 |
2752 |
| 2743 display_name = headline = NULL; |
2753 display_name = headline = NULL; |
| 2744 |
2754 |
| 2745 /* Retrieve display name and/or headline, depending on user preference. */ |
2755 /* Retrieve display name and/or headline, depending on user preference. */ |
| 2783 |
2793 |
| 2784 user = msim_get_user_from_buddy(buddy); |
2794 user = msim_get_user_from_buddy(buddy); |
| 2785 |
2795 |
| 2786 if (PURPLE_BUDDY_IS_ONLINE(buddy)) { |
2796 if (PURPLE_BUDDY_IS_ONLINE(buddy)) { |
| 2787 MsimSession *session; |
2797 MsimSession *session; |
| 2788 |
2798 PurpleAccount *account = purple_buddy_get_account(buddy); |
| 2789 session = (MsimSession *)buddy->account->gc->proto_data; |
2799 PurpleConnection *gc = purple_account_get_connection(account); |
| |
2800 |
| |
2801 session = (MsimSession *)gc->proto_data; |
| 2790 |
2802 |
| 2791 g_return_if_fail(MSIM_SESSION_VALID(session)); |
2803 g_return_if_fail(MSIM_SESSION_VALID(session)); |
| 2792 |
2804 |
| 2793 /* TODO: if (full), do something different? */ |
2805 /* TODO: if (full), do something different? */ |
| 2794 |
2806 |
| 2866 /* 3. Update buddy information */ |
2878 /* 3. Update buddy information */ |
| 2867 user = msim_get_user_from_buddy(buddy); |
2879 user = msim_get_user_from_buddy(buddy); |
| 2868 |
2880 |
| 2869 user->id = uid; |
2881 user->id = uid; |
| 2870 /* Keep track of the user ID across sessions */ |
2882 /* Keep track of the user ID across sessions */ |
| 2871 purple_blist_node_set_int(&buddy->node, "UserID", uid); |
2883 purple_blist_node_set_int((PurpleBlistNode *)buddy, "UserID", uid); |
| 2872 |
2884 |
| 2873 /* Stores a few fields in the MsimUser, relevant to the buddy itself. |
2885 /* Stores a few fields in the MsimUser, relevant to the buddy itself. |
| 2874 * AvatarURL, Headline, ContactID. */ |
2886 * AvatarURL, Headline, ContactID. */ |
| 2875 msim_store_user_info(session, contact_info, NULL); |
2887 msim_store_user_info(session, contact_info, NULL); |
| 2876 |
2888 |