Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/userlist.c @ 20461:25542d5c94ed
propagate from branch 'im.pidgin.pidgin' (head 007693114b23cd2711c1cb9030a148e2f63de8c8)
to branch 'im.pidgin.cpw.khc.msnp14' (head 46048b0e7414ad1a4545b3a49494fea80191a9d1)
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Sat, 07 Jul 2007 03:52:12 +0000 |
parents | c1ff701bcb0c |
children | 86da6ab1f612 |
comparison
equal
deleted
inserted
replaced
18451:7122bcebf7c9 | 20461:25542d5c94ed |
---|---|
51 } | 51 } |
52 | 52 |
53 static void | 53 static void |
54 msn_cancel_add_cb(MsnPermitAdd *pa) | 54 msn_cancel_add_cb(MsnPermitAdd *pa) |
55 { | 55 { |
56 MsnSession *session = pa->gc->proto_data; | 56 if (g_list_find(purple_connections_get_all(), pa->gc) != NULL) |
57 MsnUserList *userlist = session->userlist; | 57 { |
58 | 58 MsnSession *session = pa->gc->proto_data; |
59 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_BL, NULL); | 59 MsnUserList *userlist = session->userlist; |
60 | |
61 msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_BL, NULL); | |
62 } | |
60 | 63 |
61 g_free(pa->who); | 64 g_free(pa->who); |
62 g_free(pa->friendly); | 65 g_free(pa->friendly); |
63 g_free(pa); | 66 g_free(pa); |
64 } | 67 } |
74 pa->gc = gc; | 77 pa->gc = gc; |
75 | 78 |
76 purple_account_request_authorization(purple_connection_get_account(gc), passport, NULL, friendly, NULL, | 79 purple_account_request_authorization(purple_connection_get_account(gc), passport, NULL, friendly, NULL, |
77 purple_find_buddy(purple_connection_get_account(gc), passport) != NULL, | 80 purple_find_buddy(purple_connection_get_account(gc), passport) != NULL, |
78 G_CALLBACK(msn_accept_add_cb), G_CALLBACK(msn_cancel_add_cb), pa); | 81 G_CALLBACK(msn_accept_add_cb), G_CALLBACK(msn_cancel_add_cb), pa); |
82 | |
79 } | 83 } |
80 | 84 |
81 /************************************************************************** | 85 /************************************************************************** |
82 * Utility functions | 86 * Utility functions |
83 **************************************************************************/ | 87 **************************************************************************/ |
84 | 88 |
85 static gboolean | 89 static gboolean |
86 user_is_in_group(MsnUser *user, int group_id) | 90 user_is_in_group(MsnUser *user, const char * group_id) |
87 { | 91 { |
88 if (user == NULL) | 92 if (user == NULL) |
89 return FALSE; | 93 return FALSE; |
90 | 94 |
91 if (group_id < 0) | 95 if (group_id == NULL) |
92 return FALSE; | 96 return FALSE; |
93 | 97 |
94 if (g_list_find(user->group_ids, GINT_TO_POINTER(group_id))) | 98 if (g_list_find_custom(user->group_ids, group_id, (GCompareFunc)strcmp)) |
95 return TRUE; | 99 return TRUE; |
96 | 100 |
97 return FALSE; | 101 return FALSE; |
98 } | 102 } |
99 | 103 |
100 static gboolean | 104 static gboolean |
101 user_is_there(MsnUser *user, int list_id, int group_id) | 105 user_is_there(MsnUser *user, int list_id, const char * group_id) |
102 { | 106 { |
103 int list_op; | 107 int list_op; |
104 | 108 |
105 if (user == NULL) | 109 if (user == NULL) |
106 return FALSE; | 110 return FALSE; |
110 if (!(user->list_op & list_op)) | 114 if (!(user->list_op & list_op)) |
111 return FALSE; | 115 return FALSE; |
112 | 116 |
113 if (list_id == MSN_LIST_FL) | 117 if (list_id == MSN_LIST_FL) |
114 { | 118 { |
115 if (group_id >= 0) | 119 if (group_id != NULL) |
116 return user_is_in_group(user, group_id); | 120 return user_is_in_group(user, group_id); |
117 } | 121 } |
118 | 122 |
119 return TRUE; | 123 return TRUE; |
120 } | 124 } |
149 | 153 |
150 static void | 154 static void |
151 msn_request_add_group(MsnUserList *userlist, const char *who, | 155 msn_request_add_group(MsnUserList *userlist, const char *who, |
152 const char *old_group_name, const char *new_group_name) | 156 const char *old_group_name, const char *new_group_name) |
153 { | 157 { |
158 MsnSession *session; | |
154 MsnCmdProc *cmdproc; | 159 MsnCmdProc *cmdproc; |
155 MsnTransaction *trans; | |
156 MsnMoveBuddy *data; | 160 MsnMoveBuddy *data; |
157 | 161 |
158 cmdproc = userlist->session->notification->cmdproc; | 162 session = userlist->session; |
163 cmdproc = session->notification->cmdproc; | |
159 data = g_new0(MsnMoveBuddy, 1); | 164 data = g_new0(MsnMoveBuddy, 1); |
160 | 165 |
161 data->who = g_strdup(who); | 166 data->who = g_strdup(who); |
162 | 167 |
163 if (old_group_name) | 168 if (old_group_name) |
169 { | |
164 data->old_group_name = g_strdup(old_group_name); | 170 data->old_group_name = g_strdup(old_group_name); |
165 | 171 /*delete the old group via SOAP action*/ |
166 trans = msn_transaction_new(cmdproc, "ADG", "%s %d", | 172 msn_del_group(session,old_group_name); |
167 purple_url_encode(new_group_name), | 173 } |
168 0); | 174 |
169 | 175 /*add new group via SOAP action*/ |
170 msn_transaction_set_data(trans, data); | 176 msn_add_group(session, new_group_name); |
171 | 177 |
172 msn_cmdproc_send_trans(cmdproc, trans); | |
173 } | 178 } |
174 | 179 |
175 /************************************************************************** | 180 /************************************************************************** |
176 * Server functions | 181 * Server functions |
177 **************************************************************************/ | 182 **************************************************************************/ |
191 return -1; | 196 return -1; |
192 } | 197 } |
193 | 198 |
194 void | 199 void |
195 msn_got_add_user(MsnSession *session, MsnUser *user, | 200 msn_got_add_user(MsnSession *session, MsnUser *user, |
196 MsnListId list_id, int group_id) | 201 MsnListId list_id, const char * group_id) |
197 { | 202 { |
198 PurpleAccount *account; | 203 PurpleAccount *account; |
199 const char *passport; | 204 const char *passport; |
200 const char *friendly; | 205 const char *friendly; |
201 | 206 |
207 purple_debug_info("MaYuan","got add user...\n"); | |
202 account = session->account; | 208 account = session->account; |
203 | 209 |
204 passport = msn_user_get_passport(user); | 210 passport = msn_user_get_passport(user); |
205 friendly = msn_user_get_friendly_name(user); | 211 friendly = msn_user_get_friendly_name(user); |
206 | 212 |
210 | 216 |
211 gc = purple_account_get_connection(account); | 217 gc = purple_account_get_connection(account); |
212 | 218 |
213 serv_got_alias(gc, passport, friendly); | 219 serv_got_alias(gc, passport, friendly); |
214 | 220 |
215 if (group_id >= 0) | 221 if (group_id != NULL) |
216 { | 222 { |
217 msn_user_add_group_id(user, group_id); | 223 msn_user_add_group_id(user, group_id); |
218 } | 224 } |
219 else | 225 else |
220 { | 226 { |
259 /* | 265 /* |
260 * TODO: The friendly name was NULL for me when I | 266 * TODO: The friendly name was NULL for me when I |
261 * looked at this. Maybe we should use the store | 267 * looked at this. Maybe we should use the store |
262 * name instead? --KingAnt | 268 * name instead? --KingAnt |
263 */ | 269 */ |
264 got_new_entry(gc, passport, friendly); | 270 // got_new_entry(gc, passport, friendly); |
265 } | 271 } |
266 } | 272 } |
267 | 273 |
268 user->list_op |= (1 << list_id); | 274 user->list_op |= (1 << list_id); |
269 /* purple_user_add_list_id (user, list_id); */ | 275 /* purple_user_add_list_id (user, list_id); */ |
270 } | 276 } |
271 | 277 |
272 void | 278 void |
273 msn_got_rem_user(MsnSession *session, MsnUser *user, | 279 msn_got_rem_user(MsnSession *session, MsnUser *user, |
274 MsnListId list_id, int group_id) | 280 MsnListId list_id, const char * group_id) |
275 { | 281 { |
276 PurpleAccount *account; | 282 PurpleAccount *account; |
277 const char *passport; | 283 const char *passport; |
278 | 284 |
279 account = session->account; | 285 account = session->account; |
281 passport = msn_user_get_passport(user); | 287 passport = msn_user_get_passport(user); |
282 | 288 |
283 if (list_id == MSN_LIST_FL) | 289 if (list_id == MSN_LIST_FL) |
284 { | 290 { |
285 /* TODO: When is the user totally removed? */ | 291 /* TODO: When is the user totally removed? */ |
286 if (group_id >= 0) | 292 if (group_id != NULL) |
287 { | 293 { |
288 msn_user_remove_group_id(user, group_id); | 294 msn_user_remove_group_id(user, group_id); |
289 return; | 295 return; |
290 } | 296 } |
291 else | 297 else |
329 | 335 |
330 if (user->list_op == 0) | 336 if (user->list_op == 0) |
331 { | 337 { |
332 purple_debug_info("msn", "Buddy '%s' shall be deleted?.\n", | 338 purple_debug_info("msn", "Buddy '%s' shall be deleted?.\n", |
333 passport); | 339 passport); |
334 | |
335 } | 340 } |
336 } | 341 } |
337 | 342 |
338 void | 343 void |
339 msn_got_lst_user(MsnSession *session, MsnUser *user, | 344 msn_got_lst_user(MsnSession *session, MsnUser *user, |
353 if (list_op & MSN_LIST_FL_OP) | 358 if (list_op & MSN_LIST_FL_OP) |
354 { | 359 { |
355 GSList *c; | 360 GSList *c; |
356 for (c = group_ids; c != NULL; c = g_slist_next(c)) | 361 for (c = group_ids; c != NULL; c = g_slist_next(c)) |
357 { | 362 { |
358 int group_id; | 363 char *group_id; |
359 group_id = GPOINTER_TO_INT(c->data); | 364 group_id = c->data; |
360 msn_user_add_group_id(user, group_id); | 365 msn_user_add_group_id(user, group_id); |
361 } | 366 } |
362 | 367 |
363 /* FIXME: It might be a real alias */ | 368 /* FIXME: It might be a real alias */ |
364 /* Umm, what? This might fix bug #1385130 */ | 369 /* Umm, what? This might fix bug #1385130 */ |
389 * should use the friendly name, instead? --KingAnt | 394 * should use the friendly name, instead? --KingAnt |
390 */ | 395 */ |
391 | 396 |
392 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) | 397 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) |
393 { | 398 { |
394 got_new_entry(gc, passport, store); | 399 // got_new_entry(gc, passport, store); |
395 } | 400 } |
396 } | 401 } |
397 | 402 |
398 user->list_op = list_op; | 403 user->list_op |= list_op; |
399 } | 404 } |
400 | 405 |
401 /************************************************************************** | 406 /************************************************************************** |
402 * UserList functions | 407 * UserList functions |
403 **************************************************************************/ | 408 **************************************************************************/ |
423 void | 428 void |
424 msn_userlist_destroy(MsnUserList *userlist) | 429 msn_userlist_destroy(MsnUserList *userlist) |
425 { | 430 { |
426 GList *l; | 431 GList *l; |
427 | 432 |
433 /*destroy userlist*/ | |
428 for (l = userlist->users; l != NULL; l = l->next) | 434 for (l = userlist->users; l != NULL; l = l->next) |
429 { | 435 { |
430 msn_user_destroy(l->data); | 436 msn_user_destroy(l->data); |
431 } | 437 } |
432 | |
433 g_list_free(userlist->users); | 438 g_list_free(userlist->users); |
434 | 439 |
440 /*destroy group list*/ | |
435 for (l = userlist->groups; l != NULL; l = l->next) | 441 for (l = userlist->groups; l != NULL; l = l->next) |
436 { | 442 { |
437 msn_group_destroy(l->data); | 443 msn_group_destroy(l->data); |
438 } | 444 } |
439 | |
440 g_list_free(userlist->groups); | 445 g_list_free(userlist->groups); |
441 | 446 |
442 g_queue_free(userlist->buddy_icon_requests); | 447 g_queue_free(userlist->buddy_icon_requests); |
443 | 448 |
444 if (userlist->buddy_icon_request_timer) | 449 if (userlist->buddy_icon_request_timer) |
445 purple_timeout_remove(userlist->buddy_icon_request_timer); | 450 purple_timeout_remove(userlist->buddy_icon_request_timer); |
446 | 451 |
447 g_free(userlist); | 452 g_free(userlist); |
448 } | 453 } |
449 | 454 |
455 MsnUser * | |
456 msn_userlist_find_add_user(MsnUserList *userlist,const char *passport,const char *userName) | |
457 { | |
458 MsnUser *user; | |
459 | |
460 user = msn_userlist_find_user(userlist, passport); | |
461 if (user == NULL) | |
462 { | |
463 user = msn_user_new(userlist, passport, userName); | |
464 msn_userlist_add_user(userlist, user); | |
465 } | |
466 msn_user_set_store_name(user, userName); | |
467 return user; | |
468 } | |
469 | |
450 void | 470 void |
451 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) | 471 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) |
452 { | 472 { |
453 userlist->users = g_list_append(userlist->users, user); | 473 userlist->users = g_list_append(userlist->users, user); |
454 } | 474 } |
467 g_return_val_if_fail(passport != NULL, NULL); | 487 g_return_val_if_fail(passport != NULL, NULL); |
468 | 488 |
469 for (l = userlist->users; l != NULL; l = l->next) | 489 for (l = userlist->users; l != NULL; l = l->next) |
470 { | 490 { |
471 MsnUser *user = (MsnUser *)l->data; | 491 MsnUser *user = (MsnUser *)l->data; |
472 | 492 // purple_debug_info("MsnUserList","user passport:%s,passport:%s\n",user->passport,passport); |
473 g_return_val_if_fail(user->passport != NULL, NULL); | 493 g_return_val_if_fail(user->passport != NULL, NULL); |
474 | 494 |
475 if (!strcmp(passport, user->passport)) | 495 if (!g_strcasecmp(passport, user->passport)){ |
496 // purple_debug_info("MsnUserList","return:%p\n",user); | |
476 return user; | 497 return user; |
498 } | |
477 } | 499 } |
478 | 500 |
479 return NULL; | 501 return NULL; |
480 } | 502 } |
481 | 503 |
490 { | 512 { |
491 userlist->groups = g_list_remove(userlist->groups, group); | 513 userlist->groups = g_list_remove(userlist->groups, group); |
492 } | 514 } |
493 | 515 |
494 MsnGroup * | 516 MsnGroup * |
495 msn_userlist_find_group_with_id(MsnUserList *userlist, int id) | 517 msn_userlist_find_group_with_id(MsnUserList *userlist, const char * id) |
496 { | 518 { |
497 GList *l; | 519 GList *l; |
498 | 520 |
499 g_return_val_if_fail(userlist != NULL, NULL); | 521 g_return_val_if_fail(userlist != NULL, NULL); |
500 g_return_val_if_fail(id >= 0, NULL); | 522 g_return_val_if_fail(id != NULL, NULL); |
501 | 523 |
502 for (l = userlist->groups; l != NULL; l = l->next) | 524 for (l = userlist->groups; l != NULL; l = l->next) |
503 { | 525 { |
504 MsnGroup *group = l->data; | 526 MsnGroup *group = l->data; |
505 | 527 |
506 if (group->id == id) | 528 if (!g_strcasecmp(group->id,id)) |
507 return group; | 529 return group; |
508 } | 530 } |
509 | 531 |
510 return NULL; | 532 return NULL; |
511 } | 533 } |
520 | 542 |
521 for (l = userlist->groups; l != NULL; l = l->next) | 543 for (l = userlist->groups; l != NULL; l = l->next) |
522 { | 544 { |
523 MsnGroup *group = l->data; | 545 MsnGroup *group = l->data; |
524 | 546 |
525 if ((group->name != NULL) && !g_ascii_strcasecmp(name, group->name)) | 547 if ((group->name != NULL) && !g_strcasecmp(name, group->name)) |
526 return group; | 548 return group; |
527 } | 549 } |
528 | 550 |
529 return NULL; | 551 return NULL; |
530 } | 552 } |
531 | 553 |
532 int | 554 const char * |
533 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) | 555 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) |
534 { | 556 { |
535 MsnGroup *group; | 557 MsnGroup *group; |
536 | 558 |
537 group = msn_userlist_find_group_with_name(userlist, group_name); | 559 group = msn_userlist_find_group_with_name(userlist, group_name); |
538 | 560 |
539 if (group != NULL) | 561 if (group != NULL) |
540 return msn_group_get_id(group); | 562 return msn_group_get_id(group); |
541 else | 563 else |
542 return -1; | 564 return NULL; |
543 } | 565 } |
544 | 566 |
545 const char * | 567 const char * |
546 msn_userlist_find_group_name(MsnUserList *userlist, int group_id) | 568 msn_userlist_find_group_name(MsnUserList *userlist, const char * group_id) |
547 { | 569 { |
548 MsnGroup *group; | 570 MsnGroup *group; |
549 | 571 |
550 group = msn_userlist_find_group_with_id(userlist, group_id); | 572 group = msn_userlist_find_group_with_id(userlist, group_id); |
551 | 573 |
554 else | 576 else |
555 return NULL; | 577 return NULL; |
556 } | 578 } |
557 | 579 |
558 void | 580 void |
559 msn_userlist_rename_group_id(MsnUserList *userlist, int group_id, | 581 msn_userlist_rename_group_id(MsnUserList *userlist, const char * group_id, |
560 const char *new_name) | 582 const char *new_name) |
561 { | 583 { |
562 MsnGroup *group; | 584 MsnGroup *group; |
563 | 585 |
564 group = msn_userlist_find_group_with_id(userlist, group_id); | 586 group = msn_userlist_find_group_with_id(userlist, group_id); |
566 if (group != NULL) | 588 if (group != NULL) |
567 msn_group_set_name(group, new_name); | 589 msn_group_set_name(group, new_name); |
568 } | 590 } |
569 | 591 |
570 void | 592 void |
571 msn_userlist_remove_group_id(MsnUserList *userlist, int group_id) | 593 msn_userlist_remove_group_id(MsnUserList *userlist, const char * group_id) |
572 { | 594 { |
573 MsnGroup *group; | 595 MsnGroup *group; |
574 | 596 |
575 group = msn_userlist_find_group_with_id(userlist, group_id); | 597 group = msn_userlist_find_group_with_id(userlist, group_id); |
576 | 598 |
584 void | 606 void |
585 msn_userlist_rem_buddy(MsnUserList *userlist, | 607 msn_userlist_rem_buddy(MsnUserList *userlist, |
586 const char *who, int list_id, const char *group_name) | 608 const char *who, int list_id, const char *group_name) |
587 { | 609 { |
588 MsnUser *user; | 610 MsnUser *user; |
589 int group_id; | 611 const char *group_id; |
590 const char *list; | 612 const char *list; |
591 | 613 |
592 user = msn_userlist_find_user(userlist, who); | 614 user = msn_userlist_find_user(userlist, who); |
593 group_id = -1; | 615 |
616 g_return_if_fail(user != NULL); | |
617 | |
618 /*delete the contact from address book via soap action*/ | |
619 msn_delete_contact(userlist->session->contact,user->uid); | |
620 | |
621 group_id = NULL; | |
594 | 622 |
595 if (group_name != NULL) | 623 if (group_name != NULL) |
596 { | 624 { |
597 group_id = msn_userlist_find_group_id(userlist, group_name); | 625 group_id = msn_userlist_find_group_id(userlist, group_name); |
598 | 626 |
599 if (group_id < 0) | 627 if (group_id == NULL) |
600 { | 628 { |
601 /* Whoa, there is no such group. */ | 629 /* Whoa, there is no such group. */ |
602 purple_debug_error("msn", "Group doesn't exist: %s\n", group_name); | 630 purple_debug_error("msn", "Group doesn't exist: %s\n", group_name); |
603 return; | 631 return; |
604 } | 632 } |
617 list = lists[list_id]; | 645 list = lists[list_id]; |
618 | 646 |
619 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); | 647 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); |
620 } | 648 } |
621 | 649 |
650 /*add buddy*/ | |
622 void | 651 void |
623 msn_userlist_add_buddy(MsnUserList *userlist, | 652 msn_userlist_add_buddy(MsnUserList *userlist, |
624 const char *who, int list_id, | 653 const char *who, int list_id, |
625 const char *group_name) | 654 const char *group_name) |
626 { | 655 { |
627 MsnUser *user; | 656 MsnUser *user; |
628 int group_id; | 657 const char *group_id; |
629 const char *list; | 658 const char *list; |
630 const char *store_name; | 659 const char *store_name; |
631 | 660 |
632 group_id = -1; | 661 purple_debug_info("MaYuan", "userlist add buddy,name:{%s},group:{%s}\n",who ,group_name); |
662 group_id = NULL; | |
633 | 663 |
634 if (!purple_email_is_valid(who)) | 664 if (!purple_email_is_valid(who)) |
635 { | 665 { |
636 /* only notify the user about problems adding to the friends list | 666 /* only notify the user about problems adding to the friends list |
637 * maybe we should do something else for other lists, but it probably | 667 * maybe we should do something else for other lists, but it probably |
649 | 679 |
650 if (group_name != NULL) | 680 if (group_name != NULL) |
651 { | 681 { |
652 group_id = msn_userlist_find_group_id(userlist, group_name); | 682 group_id = msn_userlist_find_group_id(userlist, group_name); |
653 | 683 |
654 if (group_id < 0) | 684 if (group_id == NULL) |
655 { | 685 { |
656 /* Whoa, we must add that group first. */ | 686 /* Whoa, we must add that group first. */ |
657 msn_request_add_group(userlist, who, NULL, group_name); | 687 msn_request_add_group(userlist, who, NULL, group_name); |
658 return; | 688 return; |
659 } | 689 } |
660 } | 690 } |
661 | 691 |
662 user = msn_userlist_find_user(userlist, who); | 692 /* XXX: using _add_user here may not be correct (should add them in the |
693 ACK to the ADL command, and we might also want to make sure the user's groups | |
694 are correct. but for now we need to make sure they exist early enough that | |
695 the ILN command doesn't screw us up */ | |
696 user = msn_userlist_find_add_user(userlist, who, who); | |
663 | 697 |
664 /* First we're going to check if it's already there. */ | 698 /* First we're going to check if it's already there. */ |
665 if (user_is_there(user, list_id, group_id)) | 699 if (user_is_there(user, list_id, group_id)) |
666 { | 700 { |
667 list = lists[list_id]; | 701 list = lists[list_id]; |
669 return; | 703 return; |
670 } | 704 } |
671 | 705 |
672 store_name = (user != NULL) ? get_store_name(user) : who; | 706 store_name = (user != NULL) ? get_store_name(user) : who; |
673 | 707 |
708 /* XXX: see XXX above, this should really be done when we get the response from | |
709 the server */ | |
710 msn_user_set_op(user, list_id); | |
711 | |
674 /* Then request the add to the server. */ | 712 /* Then request the add to the server. */ |
675 list = lists[list_id]; | 713 list = lists[list_id]; |
676 | 714 |
715 purple_debug_info("MaYuan", "add user:{%s} to group id {%s}\n",store_name ,group_id); | |
716 msn_add_contact(userlist->session->contact,who,group_id); | |
677 msn_notification_add_buddy(userlist->session->notification, list, who, | 717 msn_notification_add_buddy(userlist->session->notification, list, who, |
678 store_name, group_id); | 718 store_name, group_id); |
679 } | 719 } |
680 | 720 |
681 void | 721 void |
682 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, | 722 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, |
683 const char *old_group_name, const char *new_group_name) | 723 const char *old_group_name, const char *new_group_name) |
684 { | 724 { |
685 int new_group_id; | 725 const char *new_group_id; |
686 | 726 |
687 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); | 727 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); |
688 | 728 |
689 if (new_group_id < 0) | 729 if (new_group_id == NULL) |
690 { | 730 { |
691 msn_request_add_group(userlist, who, old_group_name, new_group_name); | 731 msn_request_add_group(userlist, who, old_group_name, new_group_name); |
692 return; | 732 return; |
693 } | 733 } |
694 | 734 |
695 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); | 735 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); |
696 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name); | 736 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name); |
697 } | 737 } |
738 | |
739 /*load userlist from the Blist file cache*/ | |
740 void | |
741 msn_userlist_load(MsnSession *session) | |
742 { | |
743 PurpleBlistNode *gnode, *cnode, *bnode; | |
744 PurpleConnection *gc = purple_account_get_connection(session->account); | |
745 GSList *l; | |
746 MsnUser * user; | |
747 | |
748 g_return_if_fail(gc != NULL); | |
749 | |
750 for (gnode = purple_get_blist()->root; gnode; gnode = gnode->next) | |
751 { | |
752 if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) | |
753 continue; | |
754 for (cnode = gnode->child; cnode; cnode = cnode->next) | |
755 { | |
756 if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) | |
757 continue; | |
758 for (bnode = cnode->child; bnode; bnode = bnode->next) | |
759 { | |
760 PurpleBuddy *b; | |
761 if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) | |
762 continue; | |
763 b = (PurpleBuddy *)bnode; | |
764 if (b->account == gc->account) | |
765 { | |
766 user = msn_userlist_find_add_user(session->userlist, | |
767 b->name,NULL); | |
768 b->proto_data = user; | |
769 msn_user_set_op(user, MSN_LIST_FL_OP); | |
770 } | |
771 } | |
772 } | |
773 } | |
774 for (l = session->account->permit; l != NULL; l = l->next) | |
775 { | |
776 user = msn_userlist_find_add_user(session->userlist, | |
777 (char *)l->data,NULL); | |
778 msn_user_set_op(user, MSN_LIST_AL_OP); | |
779 } | |
780 for (l = session->account->deny; l != NULL; l = l->next) | |
781 { | |
782 user = msn_userlist_find_add_user(session->userlist, | |
783 (char *)l->data,NULL); | |
784 msn_user_set_op(user, MSN_LIST_BL_OP); | |
785 } | |
786 | |
787 } | |
788 |