Mercurial > pidgin.yaz
annotate src/protocols/msn/userlist.c @ 10306:56cc5d49472b
[gaim-migrate @ 11492]
" Well, I found a bug, and even though I had code to
prevent that crash it seems it did not. So now here is
in a different way, which by the way is more efficient." --Felipe Contreras
(19:35:44) shx: LSchiere: there's a bugfix patch for msn in the tracker if
it interest you ;)
(19:35:59) LSchiere: the one i assigned to nosnilmot just a little bit ago?
(19:36:24) shx: LSchiere: probably
(19:38:25) LSchiere: i just remembered to day is release day
(19:38:51) shx: yeap... so I tought it was important to commit it
also, i rather like being able to compile
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 03 Dec 2004 00:57:21 +0000 |
parents | ecf3ce2e2ab1 |
children | 1a97d5e88d12 |
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; | |
33 | |
34 } MsnPermitAdd; | |
35 | |
36 /************************************************************************** | |
37 * Callbacks | |
38 **************************************************************************/ | |
39 static void | |
40 msn_accept_add_cb(MsnPermitAdd *pa) | |
41 { | |
42 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
43 { | |
44 MsnSession *session = pa->gc->proto_data; | |
45 MsnUserList *userlist = session->userlist; | |
46 | |
47 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL); | |
48 | |
49 /* TODO: This ask for the alias, right? */ | |
50 gaim_account_notify_added(pa->gc->account, NULL, pa->who, NULL, NULL); | |
51 } | |
52 | |
53 g_free(pa->who); | |
54 g_free(pa); | |
55 } | |
56 | |
57 static void | |
58 msn_cancel_add_cb(MsnPermitAdd *pa) | |
59 { | |
60 if (g_list_find(gaim_connections_get_all(), pa->gc) != NULL) | |
61 { | |
62 MsnSession *session = pa->gc->proto_data; | |
63 MsnUserList *userlist = session->userlist; | |
64 | |
65 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_BL, NULL); | |
66 } | |
67 | |
68 g_free(pa->who); | |
69 g_free(pa); | |
70 } | |
71 | |
72 static void | |
9976 | 73 got_new_entry(GaimConnection *gc, const char *passport, const char *friendly) |
9193 | 74 { |
75 MsnPermitAdd *pa; | |
10225 | 76 char *msg, *escaped; |
9193 | 77 |
78 pa = g_new0(MsnPermitAdd, 1); | |
79 pa->who = g_strdup(passport); | |
80 pa->gc = gc; | |
81 | |
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
82 if (friendly != NULL) |
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
83 { |
10225 | 84 escaped = g_markup_escape_text(friendly, -1); |
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
85 msg = g_strdup_printf( |
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
86 _("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
|
87 "buddy list."), |
10225 | 88 passport, escaped, |
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
89 gaim_account_get_username(gc->account)); |
10225 | 90 g_free(escaped); |
9210
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
91 } |
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
92 else |
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
93 { |
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 wants to add %s to his or " |
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
96 "her buddy list."), |
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
97 passport, gaim_account_get_username(gc->account)); |
62b601ddb4bc
[gaim-migrate @ 10005]
Christian Hammond <chipx86@chipx86.com>
parents:
9208
diff
changeset
|
98 } |
9193 | 99 |
9976 | 100 gaim_request_action(gc, NULL, msg, NULL, |
9948 | 101 GAIM_DEFAULT_ACTION_NONE, pa, 2, |
9193 | 102 _("Authorize"), G_CALLBACK(msn_accept_add_cb), |
103 _("Deny"), G_CALLBACK(msn_cancel_add_cb)); | |
104 | |
105 g_free(msg); | |
106 } | |
107 | |
108 /************************************************************************** | |
109 * Utility functions | |
110 **************************************************************************/ | |
111 | |
112 static gboolean | |
113 user_is_in_group(MsnUser *user, int group_id) | |
114 { | |
115 if (user == NULL) | |
116 return FALSE; | |
117 | |
118 if (group_id < 0) | |
119 return FALSE; | |
120 | |
121 if (g_list_find(user->group_ids, GINT_TO_POINTER(group_id))) | |
122 return TRUE; | |
123 | |
124 return FALSE; | |
125 } | |
126 | |
127 static gboolean | |
128 user_is_there(MsnUser *user, int list_id, int group_id) | |
129 { | |
130 int list_op; | |
131 | |
132 if (user == NULL) | |
133 return FALSE; | |
134 | |
135 list_op = 1 << list_id; | |
136 | |
137 if (!(user->list_op & list_op)) | |
138 return FALSE; | |
139 | |
140 if (list_id == MSN_LIST_FL) | |
141 { | |
142 if (group_id >= 0) | |
143 return user_is_in_group(user, group_id); | |
144 } | |
145 | |
146 return TRUE; | |
147 } | |
148 | |
149 static const char* | |
150 get_store_name(MsnUser *user) | |
151 { | |
152 const char *store_name; | |
153 | |
154 g_return_val_if_fail(user != NULL, NULL); | |
155 | |
156 if ((store_name = msn_user_get_store_name(user)) != NULL) | |
157 return gaim_url_encode(store_name); | |
158 | |
159 return msn_user_get_passport(user); | |
160 } | |
161 | |
162 static void | |
163 msn_request_add_group(MsnUserList *userlist, const char *who, | |
164 const char *old_group_name, const char *new_group_name) | |
165 { | |
166 MsnCmdProc *cmdproc; | |
167 MsnTransaction *trans; | |
9218 | 168 MsnMoveBuddy *data; |
9193 | 169 |
170 cmdproc = userlist->session->notification->cmdproc; | |
9218 | 171 data = g_new0(MsnMoveBuddy, 1); |
9193 | 172 |
173 data->who = g_strdup(who); | |
174 | |
175 if (old_group_name) | |
176 data->old_group_name = g_strdup(old_group_name); | |
177 | |
10225 | 178 trans = msn_transaction_new(cmdproc, "ADG", "%s %d", |
9193 | 179 gaim_url_encode(new_group_name), |
180 0); | |
181 | |
182 msn_transaction_set_data(trans, data); | |
183 | |
184 msn_cmdproc_send_trans(cmdproc, trans); | |
185 } | |
186 | |
187 /************************************************************************** | |
188 * Server functions | |
189 **************************************************************************/ | |
190 | |
191 MsnListId | |
192 msn_get_list_id(const char *list) | |
193 { | |
194 if (list[0] == 'F') | |
195 return MSN_LIST_FL; | |
196 else if (list[0] == 'A') | |
197 return MSN_LIST_AL; | |
198 else if (list[0] == 'B') | |
199 return MSN_LIST_BL; | |
200 else if (list[0] == 'R') | |
201 return MSN_LIST_RL; | |
202 | |
203 return -1; | |
204 } | |
205 | |
206 void | |
207 msn_got_add_user(MsnSession *session, MsnUser *user, | |
208 MsnListId list_id, int group_id) | |
209 { | |
210 GaimAccount *account; | |
211 const char *passport; | |
212 const char *friendly; | |
213 | |
214 account = session->account; | |
215 | |
216 passport = msn_user_get_passport(user); | |
217 friendly = msn_user_get_friendly_name(user); | |
9197
ec417d2f9666
[gaim-migrate @ 9992]
Christian Hammond <chipx86@chipx86.com>
parents:
9196
diff
changeset
|
218 |
9193 | 219 if (list_id == MSN_LIST_FL) |
220 { | |
9861 | 221 GaimConnection *gc; |
222 | |
223 gc = gaim_account_get_connection(account); | |
9193 | 224 |
225 serv_got_alias(gc, passport, friendly); | |
226 | |
227 if (group_id >= 0) | |
228 { | |
229 msn_user_add_group_id(user, group_id); | |
230 return; | |
231 } | |
232 else | |
233 { | |
234 /* session->sync->fl_users_count++; */ | |
235 } | |
236 } | |
237 else if (list_id == MSN_LIST_AL) | |
238 { | |
239 gaim_privacy_permit_add(account, passport, TRUE); | |
240 } | |
241 else if (list_id == MSN_LIST_BL) | |
242 { | |
243 gaim_privacy_deny_add(account, passport, TRUE); | |
244 } | |
245 else if (list_id == MSN_LIST_RL) | |
246 { | |
9861 | 247 GaimConnection *gc; |
248 | |
249 gc = gaim_account_get_connection(account); | |
9193 | 250 |
251 gaim_debug_info("msn", | |
252 "%s has added you to his or her contact list.\n", | |
253 passport); | |
254 | |
9223
f46154d6de2b
[gaim-migrate @ 10019]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
255 if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP | |
f46154d6de2b
[gaim-migrate @ 10019]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
256 MSN_LIST_FL_OP))) |
f46154d6de2b
[gaim-migrate @ 10019]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
257 { |
9193 | 258 got_new_entry(gc, passport, friendly); |
9223
f46154d6de2b
[gaim-migrate @ 10019]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
259 } |
9193 | 260 } |
261 | |
262 user->list_op |= (1 << list_id); | |
263 /* gaim_user_add_list_id (user, list_id); */ | |
264 } | |
265 | |
266 void | |
267 msn_got_rem_user(MsnSession *session, MsnUser *user, | |
268 MsnListId list_id, int group_id) | |
269 { | |
270 GaimAccount *account; | |
271 const char *passport; | |
272 | |
273 account = session->account; | |
274 | |
275 passport = msn_user_get_passport(user); | |
276 | |
277 if (list_id == MSN_LIST_FL) | |
278 { | |
279 /* TODO: When is the user totally removed? */ | |
280 if (group_id >= 0) | |
281 { | |
282 msn_user_remove_group_id(user, group_id); | |
283 return; | |
284 } | |
285 else | |
286 { | |
287 /* session->sync->fl_users_count--; */ | |
288 } | |
289 } | |
290 else if (list_id == MSN_LIST_AL) | |
291 { | |
292 gaim_privacy_permit_remove(account, passport, TRUE); | |
293 } | |
294 else if (list_id == MSN_LIST_BL) | |
295 { | |
296 gaim_privacy_deny_remove(account, passport, TRUE); | |
297 } | |
298 else if (list_id == MSN_LIST_RL) | |
299 { | |
300 gaim_debug_info("msn", | |
301 "%s has removed you from his or her contact list.\n", | |
302 passport); | |
303 } | |
304 | |
305 user->list_op &= ~(1 << list_id); | |
306 /* gaim_user_remove_list_id (user, list_id); */ | |
307 | |
308 if (user->list_op == 0) | |
309 { | |
310 gaim_debug_info("msn", "Buddy '%s' shall be deleted?.\n", | |
311 passport); | |
312 | |
313 } | |
314 } | |
315 | |
316 void | |
317 msn_got_lst_user(MsnSession *session, MsnUser *user, | |
318 int list_op, GSList *group_ids) | |
319 { | |
320 GaimConnection *gc; | |
321 GaimAccount *account; | |
322 const char *passport; | |
323 const char *store; | |
324 | |
325 account = session->account; | |
326 gc = gaim_account_get_connection(account); | |
327 | |
328 passport = msn_user_get_passport(user); | |
9211
74c81f56b0a5
[gaim-migrate @ 10006]
Christian Hammond <chipx86@chipx86.com>
parents:
9210
diff
changeset
|
329 store = msn_user_get_store_name(user); |
9193 | 330 |
331 if (list_op & MSN_LIST_FL_OP) | |
332 { | |
333 GSList *c; | |
334 for (c = group_ids; c != NULL; c = g_slist_next(c)) | |
335 { | |
336 int group_id; | |
337 group_id = GPOINTER_TO_INT(c->data); | |
338 msn_user_add_group_id(user, group_id); | |
339 } | |
340 | |
341 /* FIXME: It might be a real alias */ | |
342 /* serv_got_alias(gc, passport, store); */ | |
343 } | |
344 | |
345 if (list_op & MSN_LIST_AL_OP) | |
346 { | |
347 /* These are users who are allowed to see our status. */ | |
348 | |
349 if (g_slist_find_custom(account->deny, passport, | |
350 (GCompareFunc)strcmp)) | |
351 { | |
352 gaim_privacy_deny_remove(gc->account, passport, TRUE); | |
353 } | |
354 | |
355 gaim_privacy_permit_add(account, passport, TRUE); | |
356 } | |
357 | |
358 if (list_op & MSN_LIST_BL_OP) | |
359 { | |
360 /* These are users who are not allowed to see our status. */ | |
361 | |
362 if (g_slist_find_custom(account->permit, passport, | |
363 (GCompareFunc)strcmp)) | |
364 { | |
365 gaim_privacy_permit_remove(gc->account, passport, TRUE); | |
366 } | |
367 | |
368 gaim_privacy_deny_add(account, passport, TRUE); | |
369 } | |
370 | |
371 if (list_op & MSN_LIST_RL_OP) | |
372 { | |
373 /* These are users who have us on their contact list. */ | |
374 /* TODO: what does store name is when this happens? */ | |
375 | |
9225
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9223
diff
changeset
|
376 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP | |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9223
diff
changeset
|
377 MSN_LIST_FL_OP))) |
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9223
diff
changeset
|
378 { |
9193 | 379 got_new_entry(gc, passport, store); |
9225
554ef91db2dd
[gaim-migrate @ 10021]
Christian Hammond <chipx86@chipx86.com>
parents:
9223
diff
changeset
|
380 } |
9193 | 381 } |
382 | |
383 user->list_op = list_op; | |
384 } | |
385 | |
386 /************************************************************************** | |
387 * UserList functions | |
388 **************************************************************************/ | |
389 | |
390 MsnUserList* | |
391 msn_userlist_new(MsnSession *session) | |
392 { | |
393 MsnUserList *userlist; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
394 |
9193 | 395 userlist = g_new0(MsnUserList, 1); |
396 | |
397 userlist->session = session; | |
9860 | 398 userlist->buddy_icon_requests = g_queue_new(); |
399 userlist->buddy_icon_window = 5; | |
9193 | 400 |
401 return userlist; | |
402 } | |
403 | |
404 void | |
405 msn_userlist_destroy(MsnUserList *userlist) | |
406 { | |
407 GList *l; | |
408 | |
409 for (l = userlist->users; l != NULL; l = l->next) | |
410 { | |
411 msn_user_destroy(l->data); | |
412 } | |
413 | |
414 g_list_free(userlist->users); | |
415 | |
416 for (l = userlist->groups; l != NULL; l = l->next) | |
417 { | |
418 msn_group_destroy(l->data); | |
419 } | |
420 | |
421 g_list_free(userlist->groups); | |
9895 | 422 |
423 g_queue_free(userlist->buddy_icon_requests); | |
9857 | 424 g_free(userlist); |
9193 | 425 } |
426 | |
427 void | |
428 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) | |
429 { | |
430 userlist->users = g_list_append(userlist->users, user); | |
431 } | |
432 | |
433 void | |
434 msn_userlist_remove_user(MsnUserList *userlist, MsnUser *user) | |
435 { | |
436 userlist->users = g_list_remove(userlist->users, user); | |
437 } | |
438 | |
439 MsnUser * | |
440 msn_userlist_find_user(MsnUserList *userlist, const char *passport) | |
441 { | |
442 GList *l; | |
443 | |
444 g_return_val_if_fail(passport != NULL, NULL); | |
445 | |
446 for (l = userlist->users; l != NULL; l = l->next) | |
447 { | |
448 MsnUser *user = (MsnUser *)l->data; | |
449 | |
450 g_return_val_if_fail(user->passport != NULL, NULL); | |
451 | |
452 if (!strcmp(passport, user->passport)) | |
453 return user; | |
454 } | |
455 | |
456 return NULL; | |
457 } | |
458 | |
459 void | |
460 msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group) | |
461 { | |
462 userlist->groups = g_list_append(userlist->groups, group); | |
463 } | |
464 | |
465 void | |
466 msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group) | |
467 { | |
468 userlist->groups = g_list_remove(userlist->groups, group); | |
469 } | |
470 | |
471 MsnGroup * | |
472 msn_userlist_find_group_with_id(MsnUserList *userlist, int id) | |
473 { | |
474 GList *l; | |
475 | |
476 g_return_val_if_fail(userlist != NULL, NULL); | |
477 g_return_val_if_fail(id >= 0, NULL); | |
478 | |
479 for (l = userlist->groups; l != NULL; l = l->next) | |
480 { | |
481 MsnGroup *group = l->data; | |
482 | |
483 if (group->id == id) | |
484 return group; | |
485 } | |
486 | |
487 return NULL; | |
488 } | |
489 | |
490 MsnGroup * | |
491 msn_userlist_find_group_with_name(MsnUserList *userlist, const char *name) | |
492 { | |
493 GList *l; | |
494 | |
495 g_return_val_if_fail(userlist != NULL, NULL); | |
496 g_return_val_if_fail(name != NULL, NULL); | |
497 | |
498 for (l = userlist->groups; l != NULL; l = l->next) | |
499 { | |
500 MsnGroup *group = l->data; | |
501 | |
502 if ((group->name != NULL) && !g_ascii_strcasecmp(name, group->name)) | |
503 return group; | |
504 } | |
505 | |
506 return NULL; | |
507 } | |
508 | |
509 int | |
510 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) | |
511 { | |
512 MsnGroup *group; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
513 |
9193 | 514 group = msn_userlist_find_group_with_name(userlist, group_name); |
515 | |
516 if (group != NULL) | |
517 return msn_group_get_id(group); | |
518 else | |
519 return -1; | |
520 } | |
521 | |
522 const char * | |
523 msn_userlist_find_group_name(MsnUserList *userlist, int group_id) | |
524 { | |
525 MsnGroup *group; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9197
diff
changeset
|
526 |
9193 | 527 group = msn_userlist_find_group_with_id(userlist, group_id); |
528 | |
529 if (group != NULL) | |
530 return msn_group_get_name(group); | |
531 else | |
532 return NULL; | |
533 } | |
534 | |
535 void | |
536 msn_userlist_rename_group_id(MsnUserList *userlist, int group_id, | |
537 const char *new_name) | |
538 { | |
539 MsnGroup *group; | |
540 | |
541 group = msn_userlist_find_group_with_id(userlist, group_id); | |
542 | |
543 if (group != NULL) | |
544 msn_group_set_name(group, new_name); | |
545 } | |
546 | |
547 void | |
548 msn_userlist_remove_group_id(MsnUserList *userlist, int group_id) | |
549 { | |
550 MsnGroup *group; | |
551 | |
552 group = msn_userlist_find_group_with_id(userlist, group_id); | |
553 | |
554 if (group != NULL) | |
555 msn_userlist_remove_group(userlist, group); | |
556 } | |
557 | |
558 void | |
559 msn_userlist_rem_buddy(MsnUserList *userlist, | |
560 const char *who, int list_id, const char *group_name) | |
561 { | |
562 MsnUser *user; | |
563 int group_id; | |
564 const char *list; | |
565 | |
566 user = msn_userlist_find_user(userlist, who); | |
567 group_id = -1; | |
568 | |
569 if (group_name != NULL) | |
570 { | |
571 group_id = msn_userlist_find_group_id(userlist, group_name); | |
572 | |
573 if (group_id < 0) | |
574 { | |
575 /* Whoa, there is no such group. */ | |
576 gaim_debug_error("msn", "Group doesn't exist: %s\n", group_name); | |
577 return; | |
578 } | |
579 } | |
580 | |
581 /* First we're going to check if not there. */ | |
582 if (!(user_is_there(user, list_id, group_id))) | |
583 { | |
584 list = lists[list_id]; | |
585 gaim_debug_error("msn", "User '%s' is not there: %s\n", | |
586 who, list); | |
587 return; | |
588 } | |
589 | |
590 /* Then request the rem to the server. */ | |
591 list = lists[list_id]; | |
592 | |
593 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); | |
594 } | |
595 | |
596 void | |
597 msn_userlist_add_buddy(MsnUserList *userlist, | |
598 const char *who, int list_id, | |
599 const char *group_name) | |
600 { | |
601 MsnUser *user; | |
602 int group_id; | |
603 const char *list; | |
604 const char *store_name; | |
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
605 |
9193 | 606 group_id = -1; |
607 | |
608 if (group_name != NULL) | |
609 { | |
610 group_id = msn_userlist_find_group_id(userlist, group_name); | |
611 | |
612 if (group_id < 0) | |
613 { | |
614 /* Whoa, we must add that group first. */ | |
615 msn_request_add_group(userlist, who, NULL, group_name); | |
616 return; | |
617 } | |
618 } | |
619 | |
620 user = msn_userlist_find_user(userlist, who); | |
621 | |
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
622 /* First we're going to check if it's already there. */ |
9193 | 623 if (user_is_there(user, list_id, group_id)) |
624 { | |
625 list = lists[list_id]; | |
9194
364aa73323b5
[gaim-migrate @ 9989]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
626 gaim_debug_error("msn", "User '%s' is already there: %s\n", who, list); |
9193 | 627 return; |
628 } | |
629 | |
630 store_name = (user != NULL) ? get_store_name(user) : who; | |
631 | |
632 /* Then request the add to the server. */ | |
633 list = lists[list_id]; | |
634 | |
635 msn_notification_add_buddy(userlist->session->notification, list, who, | |
636 store_name, group_id); | |
637 } | |
638 | |
639 void | |
640 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, | |
641 const char *old_group_name, const char *new_group_name) | |
642 { | |
643 int new_group_id; | |
644 | |
645 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); | |
646 | |
647 if (new_group_id < 0) | |
648 { | |
649 msn_request_add_group(userlist, who, old_group_name, new_group_name); | |
650 return; | |
651 } | |
652 | |
653 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name); | |
654 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); | |
655 } |