Mercurial > pidgin
annotate src/protocols/msn/userlist.c @ 19799:88b0c434259a
[gaim-migrate @ 16733]
change the BL process method
continue to debug
This is an in progress version,continue to add support for send Yahoo Message
committed by Ma Yuan <mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
| author | Ma Yuan <mayuan2006@gmail.com> |
|---|---|
| date | Sun, 13 Aug 2006 06:09:48 +0000 |
| parents | 3a15b4e5c336 |
| children | da3f8f7ec3ce |
| rev | line source |
|---|---|
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
1 /** |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
2 * @file userlist.c MSN user list support |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
3 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
4 * gaim |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
5 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
8 * source distribution. |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
9 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
13 * (at your option) any later version. |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
14 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
18 * GNU General Public License for more details. |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
19 * |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
23 */ |
| 9193 | 24 #include "msn.h" |
| 25 #include "userlist.h" | |
| 26 | |
| 27 const char *lists[] = { "FL", "AL", "BL", "RL" }; | |
| 28 | |
| 29 typedef struct | |
| 30 { | |
| 31 GaimConnection *gc; | |
| 32 char *who; | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
33 char *friendly; |
| 9193 | 34 |
| 35 } MsnPermitAdd; | |
| 36 | |
| 37 /************************************************************************** | |
| 38 * Callbacks | |
| 39 **************************************************************************/ | |
| 40 static void | |
| 41 msn_accept_add_cb(MsnPermitAdd *pa) | |
| 42 { | |
| 43 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
| 44 { | |
| 45 MsnSession *session = pa->gc->proto_data; | |
| 46 MsnUserList *userlist = session->userlist; | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
47 GaimBuddy *buddy; |
| 9193 | 48 |
| 49 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL); | |
| 50 | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
51 buddy = gaim_find_buddy(pa->gc->account, pa->who); |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
52 |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
53 if (buddy != NULL) |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
54 gaim_account_notify_added(pa->gc->account, pa->who, |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
55 NULL, pa->friendly, NULL); |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
56 else |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
57 gaim_account_request_add(pa->gc->account, pa->who, |
|
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
58 NULL, pa->friendly, NULL); |
| 9193 | 59 } |
| 60 | |
| 61 g_free(pa->who); | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
62 g_free(pa->friendly); |
| 9193 | 63 g_free(pa); |
| 64 } | |
| 65 | |
| 66 static void | |
| 67 msn_cancel_add_cb(MsnPermitAdd *pa) | |
| 68 { | |
| 69 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
| 70 { | |
| 71 MsnSession *session = pa->gc->proto_data; | |
| 72 MsnUserList *userlist = session->userlist; | |
| 73 | |
| 74 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_BL, NULL); | |
| 75 } | |
| 76 | |
| 77 g_free(pa->who); | |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
78 g_free(pa->friendly); |
| 9193 | 79 g_free(pa); |
| 80 } | |
| 81 | |
| 82 static void | |
| 9976 | 83 got_new_entry(GaimConnection *gc, const char *passport, const char *friendly) |
| 9193 | 84 { |
| 85 MsnPermitAdd *pa; | |
| 10774 | 86 char *msg; |
| 9193 | 87 |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
88 pa = g_new0(MsnPermitAdd, 1); |
| 9193 | 89 pa->who = g_strdup(passport); |
| 12381 | 90 pa->friendly = g_strdup(friendly); |
|
12380
553dd80f6130
[gaim-migrate @ 14684]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12318
diff
changeset
|
91 pa->gc = gc; |
| 9193 | 92 |
|
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
93 if (friendly != NULL) |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
94 { |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
95 msg = g_strdup_printf( |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
96 _("The user %s (%s) wants to add %s to his or her " |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
97 "buddy list."), |
| 10774 | 98 passport, friendly, |
|
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
99 gaim_account_get_username(gc->account)); |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
100 } |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
101 else |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
102 { |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
103 msg = g_strdup_printf( |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
104 _("The user %s wants to add %s to his or " |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
105 "her buddy list."), |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
106 passport, gaim_account_get_username(gc->account)); |
|
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
107 } |
| 9193 | 108 |
| 9976 | 109 gaim_request_action(gc, NULL, msg, NULL, |
| 9948 | 110 GAIM_DEFAULT_ACTION_NONE, pa, 2, |
| 9193 | 111 _("Authorize"), G_CALLBACK(msn_accept_add_cb), |
| 112 _("Deny"), G_CALLBACK(msn_cancel_add_cb)); | |
| 113 | |
| 114 g_free(msg); | |
| 115 } | |
| 116 | |
| 117 /************************************************************************** | |
| 118 * Utility functions | |
| 119 **************************************************************************/ | |
| 120 | |
| 121 static gboolean | |
| 19785 | 122 user_is_in_group(MsnUser *user, const char * group_id) |
| 9193 | 123 { |
| 124 if (user == NULL) | |
| 125 return FALSE; | |
| 126 | |
| 19785 | 127 if (group_id == NULL) |
| 9193 | 128 return FALSE; |
| 129 | |
| 19785 | 130 if (g_list_find(user->group_ids, group_id)) |
| 9193 | 131 return TRUE; |
| 132 | |
| 133 return FALSE; | |
| 134 } | |
| 135 | |
| 136 static gboolean | |
| 19785 | 137 user_is_there(MsnUser *user, int list_id, const char * group_id) |
| 9193 | 138 { |
| 139 int list_op; | |
| 140 | |
| 141 if (user == NULL) | |
| 142 return FALSE; | |
| 143 | |
| 144 list_op = 1 << list_id; | |
| 145 | |
| 146 if (!(user->list_op & list_op)) | |
| 147 return FALSE; | |
| 148 | |
| 19785 | 149 if (list_id == MSN_LIST_FL){ |
| 150 if (group_id != NULL) | |
| 9193 | 151 return user_is_in_group(user, group_id); |
| 152 } | |
| 153 | |
| 154 return TRUE; | |
| 155 } | |
| 156 | |
| 157 static const char* | |
| 158 get_store_name(MsnUser *user) | |
| 159 { | |
| 160 const char *store_name; | |
| 161 | |
| 162 g_return_val_if_fail(user != NULL, NULL); | |
| 163 | |
| 10533 | 164 store_name = msn_user_get_store_name(user); |
| 165 | |
| 166 if (store_name != NULL) | |
| 167 store_name = gaim_url_encode(store_name); | |
| 168 else | |
| 169 store_name = msn_user_get_passport(user); | |
| 9193 | 170 |
| 10533 | 171 /* this might be a bit of a hack, but it should prevent notification server |
| 172 * disconnections for people who have buddies with insane friendly names | |
| 173 * who added you to their buddy list from being disconnected. Stu. */ | |
| 174 /* Shx: What? Isn't the store_name obtained from the server, and hence it's | |
| 175 * below the BUDDY_ALIAS_MAXLEN ? */ | |
| 176 /* Stu: yeah, that's why it's a bit of a hack, as you pointed out, we're | |
| 177 * probably decoding the incoming store_name wrong, or something. bleh. */ | |
| 178 | |
| 179 if (strlen(store_name) > BUDDY_ALIAS_MAXLEN) | |
| 180 store_name = msn_user_get_passport(user); | |
| 181 | |
| 182 return store_name; | |
| 9193 | 183 } |
| 184 | |
| 185 static void | |
| 186 msn_request_add_group(MsnUserList *userlist, const char *who, | |
| 187 const char *old_group_name, const char *new_group_name) | |
| 188 { | |
| 189 MsnCmdProc *cmdproc; | |
| 9218 | 190 MsnMoveBuddy *data; |
| 9193 | 191 |
| 192 cmdproc = userlist->session->notification->cmdproc; | |
| 9218 | 193 data = g_new0(MsnMoveBuddy, 1); |
| 9193 | 194 |
| 195 data->who = g_strdup(who); | |
| 196 | |
| 197 if (old_group_name) | |
| 198 data->old_group_name = g_strdup(old_group_name); | |
| 199 | |
| 19785 | 200 /*TODO:add new group via SOAP action*/ |
| 19795 | 201 |
| 9193 | 202 } |
| 203 | |
| 204 /************************************************************************** | |
| 205 * Server functions | |
| 206 **************************************************************************/ | |
| 207 | |
| 208 MsnListId | |
| 209 msn_get_list_id(const char *list) | |
| 210 { | |
| 211 if (list[0] == 'F') | |
| 212 return MSN_LIST_FL; | |
| 213 else if (list[0] == 'A') | |
| 214 return MSN_LIST_AL; | |
| 215 else if (list[0] == 'B') | |
| 216 return MSN_LIST_BL; | |
| 217 else if (list[0] == 'R') | |
| 218 return MSN_LIST_RL; | |
| 219 | |
| 220 return -1; | |
| 221 } | |
| 222 | |
| 223 void | |
| 224 msn_got_add_user(MsnSession *session, MsnUser *user, | |
| 19785 | 225 MsnListId list_id, const char * group_id) |
| 9193 | 226 { |
| 227 GaimAccount *account; | |
| 228 const char *passport; | |
| 229 const char *friendly; | |
| 230 | |
| 19799 | 231 gaim_debug_info("MaYuan","got add user...\n"); |
| 9193 | 232 account = session->account; |
| 233 | |
| 234 passport = msn_user_get_passport(user); | |
| 235 friendly = msn_user_get_friendly_name(user); | |
|
9197
ec417d2f9666
[gaim-migrate @ 9992]
Christian Hammond <chipx86@chipx86.com>
parents:
9196
diff
changeset
|
236 |
| 9193 | 237 if (list_id == MSN_LIST_FL) |
| 238 { | |
| 9861 | 239 GaimConnection *gc; |
| 240 | |
| 241 gc = gaim_account_get_connection(account); | |
| 9193 | 242 |
| 243 serv_got_alias(gc, passport, friendly); | |
| 244 | |
| 19785 | 245 if (group_id != NULL) |
| 9193 | 246 { |
| 247 msn_user_add_group_id(user, group_id); | |
| 19785 | 248 }else{ |
| 9193 | 249 /* session->sync->fl_users_count++; */ |
| 250 } | |
| 19785 | 251 }else if (list_id == MSN_LIST_AL){ |
| 9193 | 252 gaim_privacy_permit_add(account, passport, TRUE); |
| 19785 | 253 }else if (list_id == MSN_LIST_BL){ |
| 9193 | 254 gaim_privacy_deny_add(account, passport, TRUE); |
| 19785 | 255 }else if (list_id == MSN_LIST_RL){ |
| 9861 | 256 GaimConnection *gc; |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
257 GaimConversation *convo; |
| 9861 | 258 |
| 259 gc = gaim_account_get_connection(account); | |
| 9193 | 260 |
| 261 gaim_debug_info("msn", | |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
262 "%s has added you to his or her buddy list.\n", |
| 9193 | 263 passport); |
| 264 | |
| 11338 | 265 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, account); |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
266 if (convo) { |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
267 GaimBuddy *buddy; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
268 char *msg; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
269 |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
270 buddy = gaim_find_buddy(account, passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
271 msg = g_strdup_printf( |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
272 _("%s has added you to his or her buddy list."), |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
273 buddy ? gaim_buddy_get_contact_alias(buddy) : passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
274 gaim_conv_im_write(GAIM_CONV_IM(convo), passport, msg, |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
275 GAIM_MESSAGE_SYSTEM, time(NULL)); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
276 g_free(msg); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
277 } |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
278 |
| 19785 | 279 if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))){ |
| 13827 | 280 /* |
| 281 * TODO: The friendly name was NULL for me when I | |
| 282 * looked at this. Maybe we should use the store | |
| 283 * name instead? --KingAnt | |
| 284 */ | |
| 9193 | 285 got_new_entry(gc, passport, friendly); |
|
9223
f46154d6de2b
[gaim-migrate @ 10019]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
286 } |
| 9193 | 287 } |
| 288 | |
| 289 user->list_op |= (1 << list_id); | |
| 290 /* gaim_user_add_list_id (user, list_id); */ | |
| 291 } | |
| 292 | |
| 293 void | |
| 294 msn_got_rem_user(MsnSession *session, MsnUser *user, | |
| 19785 | 295 MsnListId list_id, const char * group_id) |
| 9193 | 296 { |
| 297 GaimAccount *account; | |
| 298 const char *passport; | |
| 299 | |
| 300 account = session->account; | |
| 301 | |
| 302 passport = msn_user_get_passport(user); | |
| 303 | |
| 19786 | 304 if (list_id == MSN_LIST_FL){ |
| 9193 | 305 /* TODO: When is the user totally removed? */ |
| 19786 | 306 if (group_id != NULL){ |
| 9193 | 307 msn_user_remove_group_id(user, group_id); |
| 308 return; | |
| 19786 | 309 }else{ |
| 9193 | 310 /* session->sync->fl_users_count--; */ |
| 311 } | |
| 19786 | 312 }else if (list_id == MSN_LIST_AL){ |
| 9193 | 313 gaim_privacy_permit_remove(account, passport, TRUE); |
| 19786 | 314 }else if (list_id == MSN_LIST_BL){ |
| 9193 | 315 gaim_privacy_deny_remove(account, passport, TRUE); |
| 19786 | 316 }else if (list_id == MSN_LIST_RL){ |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
317 GaimConversation *convo; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
318 |
| 9193 | 319 gaim_debug_info("msn", |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
320 "%s has removed you from his or her buddy list.\n", |
| 9193 | 321 passport); |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
322 |
| 11338 | 323 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, account); |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
324 if (convo) { |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
325 GaimBuddy *buddy; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
326 char *msg; |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
327 |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
328 buddy = gaim_find_buddy(account, passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
329 msg = g_strdup_printf( |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
330 _("%s has removed you from his or her buddy list."), |
|
11039
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
331 buddy ? gaim_buddy_get_contact_alias(buddy) : passport); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
332 gaim_conv_im_write(GAIM_CONV_IM(convo), passport, msg, |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
333 GAIM_MESSAGE_SYSTEM, time(NULL)); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
334 g_free(msg); |
|
34d2aac7b34f
[gaim-migrate @ 12938]
Richard Laager <rlaager@wiktel.com>
parents:
10774
diff
changeset
|
335 } |
| 9193 | 336 } |
| 337 | |
| 338 user->list_op &= ~(1 << list_id); | |
| 339 /* gaim_user_remove_list_id (user, list_id); */ | |
| 340 | |
| 19786 | 341 if (user->list_op == 0){ |
| 9193 | 342 gaim_debug_info("msn", "Buddy '%s' shall be deleted?.\n", |
| 343 passport); | |
| 344 } | |
| 345 } | |
| 346 | |
| 347 void | |
| 348 msn_got_lst_user(MsnSession *session, MsnUser *user, | |
| 349 int list_op, GSList *group_ids) | |
| 350 { | |
| 351 GaimConnection *gc; | |
| 352 GaimAccount *account; | |
| 353 const char *passport; | |
| 354 const char *store; | |
| 355 | |
| 356 account = session->account; | |
| 357 gc = gaim_account_get_connection(account); | |
| 358 | |
| 359 passport = msn_user_get_passport(user); | |
|
9211
74c81f56b0a5
[gaim-migrate @ 10006]
Christian Hammond <chipx86@chipx86.com>
parents:
9210
diff
changeset
|
360 store = msn_user_get_store_name(user); |
| 9193 | 361 |
| 19786 | 362 if (list_op & MSN_LIST_FL_OP){ |
| 9193 | 363 GSList *c; |
| 19786 | 364 for (c = group_ids; c != NULL; c = g_slist_next(c)) { |
| 365 char *group_id; | |
| 366 group_id = c->data; | |
| 9193 | 367 msn_user_add_group_id(user, group_id); |
| 368 } | |
| 369 | |
| 370 /* FIXME: It might be a real alias */ | |
| 13448 | 371 /* Umm, what? This might fix bug #1385130 */ |
| 372 serv_got_alias(gc, passport, store); | |
| 9193 | 373 } |
| 374 | |
| 19785 | 375 if (list_op & MSN_LIST_AL_OP){ |
| 9193 | 376 /* These are users who are allowed to see our status. */ |
|
13692
ea77ce998dc7
[gaim-migrate @ 16095]
Richard Laager <rlaager@wiktel.com>
parents:
13448
diff
changeset
|
377 gaim_privacy_deny_remove(account, passport, TRUE); |
| 9193 | 378 gaim_privacy_permit_add(account, passport, TRUE); |
| 379 } | |
| 380 | |
| 19785 | 381 if (list_op & MSN_LIST_BL_OP){ |
| 9193 | 382 /* These are users who are not allowed to see our status. */ |
|
13692
ea77ce998dc7
[gaim-migrate @ 16095]
Richard Laager <rlaager@wiktel.com>
parents:
13448
diff
changeset
|
383 gaim_privacy_permit_remove(account, passport, TRUE); |
| 9193 | 384 gaim_privacy_deny_add(account, passport, TRUE); |
| 385 } | |
| 386 | |
| 19785 | 387 if (list_op & MSN_LIST_RL_OP){ |
|
12318
e346a085bb4f
[gaim-migrate @ 14622]
Richard Laager <rlaager@wiktel.com>
parents:
11638
diff
changeset
|
388 /* These are users who have us on their buddy list. */ |
| 13827 | 389 /* |
| 390 * TODO: What is store name set to when this happens? | |
| 391 * For one of my accounts "something@hotmail.com" | |
| 392 * the store name was "something." Maybe we | |
| 393 * should use the friendly name, instead? --KingAnt | |
| 394 */ | |
| 9193 | 395 |
| 19785 | 396 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))){ |
| 9193 | 397 got_new_entry(gc, passport, store); |
|
9225
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9223
diff
changeset
|
398 } |
| 9193 | 399 } |
| 400 | |
| 19785 | 401 user->list_op |= list_op; |
| 9193 | 402 } |
| 403 | |
| 404 /************************************************************************** | |
| 405 * UserList functions | |
| 406 **************************************************************************/ | |
| 407 | |
| 408 MsnUserList* | |
| 409 msn_userlist_new(MsnSession *session) | |
| 410 { | |
| 411 MsnUserList *userlist; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
412 |
| 9193 | 413 userlist = g_new0(MsnUserList, 1); |
| 414 | |
| 415 userlist->session = session; | |
| 9860 | 416 userlist->buddy_icon_requests = g_queue_new(); |
| 13125 | 417 |
| 418 /* buddy_icon_window is the number of allowed simultaneous buddy icon requests. | |
| 419 * XXX With smarter rate limiting code, we could allow more at once... 5 was the limit set when | |
| 420 * we weren't retrieiving any more than 5 per MSN session. */ | |
| 421 userlist->buddy_icon_window = 1; | |
| 9193 | 422 |
| 423 return userlist; | |
| 424 } | |
| 425 | |
| 426 void | |
| 427 msn_userlist_destroy(MsnUserList *userlist) | |
| 428 { | |
| 429 GList *l; | |
| 430 | |
| 19785 | 431 /*destroy userlist*/ |
| 432 for (l = userlist->users; l != NULL; l = l->next){ | |
| 9193 | 433 msn_user_destroy(l->data); |
| 434 } | |
| 435 g_list_free(userlist->users); | |
| 436 | |
| 19785 | 437 /*destroy group list*/ |
| 438 for (l = userlist->groups; l != NULL; l = l->next){ | |
| 9193 | 439 msn_group_destroy(l->data); |
| 440 } | |
| 441 g_list_free(userlist->groups); | |
| 9895 | 442 |
| 443 g_queue_free(userlist->buddy_icon_requests); | |
| 13125 | 444 |
| 445 if (userlist->buddy_icon_request_timer) | |
| 446 gaim_timeout_remove(userlist->buddy_icon_request_timer); | |
| 447 | |
| 9857 | 448 g_free(userlist); |
| 9193 | 449 } |
| 450 | |
| 451 void | |
| 452 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) | |
| 453 { | |
| 454 userlist->users = g_list_append(userlist->users, user); | |
| 455 } | |
| 456 | |
| 457 void | |
| 458 msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user) | |
| 459 { | |
| 460 userlist->users = g_list_remove(userlist->users, user); | |
| 461 } | |
| 462 | |
| 463 MsnUser * | |
| 464 msn_userlist_find_user(MsnUserList *userlist, const char *passport) | |
| 465 { | |
| 466 GList *l; | |
| 467 | |
| 468 g_return_val_if_fail(passport != NULL, NULL); | |
| 469 | |
| 19785 | 470 for (l = userlist->users; l != NULL; l = l->next){ |
| 9193 | 471 MsnUser *user = (MsnUser *)l->data; |
| 19787 | 472 // gaim_debug_info("MsnUserList","user passport:%s,passport:%s\n",user->passport,passport); |
| 9193 | 473 g_return_val_if_fail(user->passport != NULL, NULL); |
| 474 | |
| 19787 | 475 if (!g_strcasecmp(passport, user->passport)){ |
| 476 // gaim_debug_info("MsnUserList","return:%p\n",user); | |
| 9193 | 477 return user; |
| 19787 | 478 } |
| 9193 | 479 } |
| 480 | |
| 481 return NULL; | |
| 482 } | |
| 483 | |
| 484 void | |
| 485 msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group) | |
| 486 { | |
| 487 userlist->groups = g_list_append(userlist->groups, group); | |
| 488 } | |
| 489 | |
| 490 void | |
| 491 msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group) | |
| 492 { | |
| 493 userlist->groups = g_list_remove(userlist->groups, group); | |
| 494 } | |
| 495 | |
| 496 MsnGroup * | |
| 19785 | 497 msn_userlist_find_group_with_id(MsnUserList *userlist, const char * id) |
| 9193 | 498 { |
| 499 GList *l; | |
| 500 | |
| 501 g_return_val_if_fail(userlist != NULL, NULL); | |
| 19785 | 502 g_return_val_if_fail(id != NULL, NULL); |
| 9193 | 503 |
| 19785 | 504 for (l = userlist->groups; l != NULL; l = l->next){ |
| 9193 | 505 MsnGroup *group = l->data; |
| 506 | |
| 19786 | 507 if (!g_strcasecmp(group->id,id)) |
| 9193 | 508 return group; |
| 509 } | |
| 510 | |
| 511 return NULL; | |
| 512 } | |
| 513 | |
| 514 MsnGroup * | |
| 515 msn_userlist_find_group_with_name(MsnUserList *userlist, const char *name) | |
| 516 { | |
| 517 GList *l; | |
| 518 | |
| 519 g_return_val_if_fail(userlist != NULL, NULL); | |
| 520 g_return_val_if_fail(name != NULL, NULL); | |
| 521 | |
| 19787 | 522 for (l = userlist->groups; l != NULL; l = l->next){ |
| 9193 | 523 MsnGroup *group = l->data; |
| 524 | |
| 19787 | 525 if ((group->name != NULL) && !g_strcasecmp(name, group->name)) |
| 9193 | 526 return group; |
| 527 } | |
| 528 | |
| 529 return NULL; | |
| 530 } | |
| 531 | |
| 19785 | 532 const char * |
| 9193 | 533 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) |
| 534 { | |
| 535 MsnGroup *group; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
536 |
| 9193 | 537 group = msn_userlist_find_group_with_name(userlist, group_name); |
| 538 | |
| 19786 | 539 if (group != NULL){ |
| 9193 | 540 return msn_group_get_id(group); |
| 19786 | 541 }else{ |
| 19785 | 542 return NULL; |
| 19786 | 543 } |
| 9193 | 544 } |
| 545 | |
| 546 const char * | |
| 19785 | 547 msn_userlist_find_group_name(MsnUserList *userlist, const char * group_id) |
| 9193 | 548 { |
| 549 MsnGroup *group; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
550 |
| 9193 | 551 group = msn_userlist_find_group_with_id(userlist, group_id); |
| 552 | |
| 19785 | 553 if (group != NULL){ |
| 9193 | 554 return msn_group_get_name(group); |
| 19785 | 555 }else{ |
| 9193 | 556 return NULL; |
| 19785 | 557 } |
| 9193 | 558 } |
| 559 | |
| 560 void | |
| 19785 | 561 msn_userlist_rename_group_id(MsnUserList *userlist, const char * group_id, |
| 9193 | 562 const char *new_name) |
| 563 { | |
| 564 MsnGroup *group; | |
| 565 | |
| 566 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 567 | |
| 568 if (group != NULL) | |
| 569 msn_group_set_name(group, new_name); | |
| 570 } | |
| 571 | |
| 572 void | |
| 19785 | 573 msn_userlist_remove_group_id(MsnUserList *userlist, const char * group_id) |
| 9193 | 574 { |
| 575 MsnGroup *group; | |
| 576 | |
| 577 group = msn_userlist_find_group_with_id(userlist, group_id); | |
| 578 | |
| 579 if (group != NULL) | |
| 10533 | 580 { |
| 9193 | 581 msn_userlist_remove_group(userlist, group); |
| 10533 | 582 msn_group_destroy(group); |
| 583 } | |
| 9193 | 584 } |
| 585 | |
| 586 void | |
| 587 msn_userlist_rem_buddy(MsnUserList *userlist, | |
| 588 const char *who, int list_id, const char *group_name) | |
| 589 { | |
| 590 MsnUser *user; | |
| 19786 | 591 const char *group_id; |
| 9193 | 592 const char *list; |
| 593 | |
| 594 user = msn_userlist_find_user(userlist, who); | |
| 19796 | 595 |
| 596 /*delete the contact from address book via soap action*/ | |
| 597 msn_delete_contact(userlist->session->contact,user->uid); | |
| 598 | |
| 19785 | 599 group_id = NULL; |
| 9193 | 600 |
| 19785 | 601 if (group_name != NULL){ |
| 9193 | 602 group_id = msn_userlist_find_group_id(userlist, group_name); |
| 603 | |
| 19785 | 604 if (group_id == NULL){ |
| 9193 | 605 /* Whoa, there is no such group. */ |
| 606 gaim_debug_error("msn", "Group doesn't exist: %s\n", group_name); | |
| 607 return; | |
| 608 } | |
| 609 } | |
| 610 | |
| 611 /* First we're going to check if not there. */ | |
| 19785 | 612 if (!(user_is_there(user, list_id, group_id))){ |
| 9193 | 613 list = lists[list_id]; |
| 614 gaim_debug_error("msn", "User '%s' is not there: %s\n", | |
| 615 who, list); | |
| 616 return; | |
| 617 } | |
| 618 | |
| 619 /* Then request the rem to the server. */ | |
| 620 list = lists[list_id]; | |
| 621 | |
| 19796 | 622 // msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); |
| 9193 | 623 } |
| 624 | |
| 19791 | 625 /*add buddy*/ |
| 9193 | 626 void |
| 627 msn_userlist_add_buddy(MsnUserList *userlist, | |
| 628 const char *who, int list_id, | |
| 629 const char *group_name) | |
| 630 { | |
| 631 MsnUser *user; | |
| 19786 | 632 const char *group_id; |
| 9193 | 633 const char *list; |
| 634 const char *store_name; | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
635 |
| 19796 | 636 gaim_debug_info("MaYuan", "userlist add buddy,name:{%s},group:{%s}\n",who ,group_name); |
| 19786 | 637 group_id = NULL; |
| 9193 | 638 |
| 19785 | 639 if (!gaim_email_is_valid(who)){ |
| 11638 | 640 /* only notify the user about problems adding to the friends list |
| 641 * maybe we should do something else for other lists, but it probably | |
| 642 * won't cause too many problems if we just ignore it */ | |
| 19785 | 643 if (list_id == MSN_LIST_FL) { |
| 11638 | 644 char *str = g_strdup_printf(_("Unable to add \"%s\"."), who); |
| 645 gaim_notify_error(NULL, NULL, str, | |
| 646 _("The screen name specified is invalid.")); | |
| 647 g_free(str); | |
| 648 } | |
| 649 | |
|
11057
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
650 return; |
|
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
651 } |
|
e9eeacd1a8d0
[gaim-migrate @ 13009]
Richard Laager <rlaager@wiktel.com>
parents:
11039
diff
changeset
|
652 |
| 19785 | 653 if (group_name != NULL){ |
| 9193 | 654 group_id = msn_userlist_find_group_id(userlist, group_name); |
| 655 | |
| 19786 | 656 if (group_id == NULL){ |
| 9193 | 657 /* Whoa, we must add that group first. */ |
| 658 msn_request_add_group(userlist, who, NULL, group_name); | |
| 659 return; | |
| 660 } | |
| 661 } | |
| 662 | |
| 663 user = msn_userlist_find_user(userlist, who); | |
| 664 | |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
665 /* First we're going to check if it's already there. */ |
| 19785 | 666 if (user_is_there(user, list_id, group_id)){ |
| 9193 | 667 list = lists[list_id]; |
|
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
668 gaim_debug_error("msn", "User '%s' is already there: %s\n", who, list); |
| 9193 | 669 return; |
| 670 } | |
| 671 | |
| 672 store_name = (user != NULL) ? get_store_name(user) : who; | |
| 673 | |
| 674 /* Then request the add to the server. */ | |
| 675 list = lists[list_id]; | |
| 676 | |
| 19796 | 677 gaim_debug_info("MaYuan", "add user:{%s} to group id {%s}\n",store_name ,group_id); |
| 678 msn_add_contact(userlist->session->contact,who,group_id); | |
| 19799 | 679 msn_notification_add_buddy(userlist->session->notification, list, who, |
| 9193 | 680 store_name, group_id); |
| 681 } | |
| 682 | |
| 683 void | |
| 684 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, | |
| 685 const char *old_group_name, const char *new_group_name) | |
| 686 { | |
| 19786 | 687 const char *new_group_id; |
| 9193 | 688 |
| 689 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); | |
| 690 | |
| 19786 | 691 if (new_group_id == NULL){ |
| 9193 | 692 msn_request_add_group(userlist, who, old_group_name, new_group_name); |
| 693 return; | |
| 694 } | |
| 695 | |
| 10568 | 696 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); |
| 9193 | 697 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name); |
| 698 } | |
| 19785 | 699 |
