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