comparison libpurple/protocols/msn/userlist.c @ 31292:47b6eda87723

propagate from branch 'im.pidgin.pidgin' (head 07d0765c444a097af45c2650f54323afb900a07b) to branch 'im.pidgin.soc.2010.msn-tlc' (head f3998422a4724ab424e4e2328f58fc0504856557)
author masca@cpw.pidgin.im
date Mon, 19 Jul 2010 21:11:32 +0000
parents 56ef12440d52
children ac9035aeb087
comparison
equal deleted inserted replaced
30698:e874875a74a7 31292:47b6eda87723
19 * 19 *
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 */ 23 */
24
25 #include "internal.h"
26 #include "debug.h"
27 #include "request.h"
28
24 #include "msn.h" 29 #include "msn.h"
30 #include "msnutils.h"
25 #include "userlist.h" 31 #include "userlist.h"
26 32
27 #include "contact.h" 33 #include "contact.h"
28 34
29 const char *lists[] = { "FL", "AL", "BL", "RL" }; 35 const char *lists[] = { "FL", "AL", "BL", "RL" };
102 acct = purple_connection_get_account(gc); 108 acct = purple_connection_get_account(gc);
103 purple_account_request_authorization(acct, passport, NULL, friendly, message, 109 purple_account_request_authorization(acct, passport, NULL, friendly, message,
104 purple_find_buddy(acct, passport) != NULL, 110 purple_find_buddy(acct, passport) != NULL,
105 msn_accept_add_cb, msn_cancel_add_cb, pa); 111 msn_accept_add_cb, msn_cancel_add_cb, pa);
106 112
107 }
108
109 /**************************************************************************
110 * Utility functions
111 **************************************************************************/
112
113 gboolean
114 msn_userlist_user_is_in_group(MsnUser *user, const char * group_id)
115 {
116 if (user == NULL)
117 return FALSE;
118
119 if (group_id == NULL)
120 return FALSE;
121
122 return (g_list_find_custom(user->group_ids, group_id, (GCompareFunc)strcmp)) != NULL;
123 }
124
125 gboolean
126 msn_userlist_user_is_in_list(MsnUser *user, MsnListId list_id)
127 {
128 if (user == NULL)
129 return FALSE;
130
131 return (user->list_op & (1 << list_id));
132 } 113 }
133 114
134 /************************************************************************** 115 /**************************************************************************
135 * Server functions 116 * Server functions
136 **************************************************************************/ 117 **************************************************************************/
233 GList *l; 214 GList *l;
234 215
235 /*destroy userlist*/ 216 /*destroy userlist*/
236 for (l = userlist->users; l != NULL; l = l->next) 217 for (l = userlist->users; l != NULL; l = l->next)
237 { 218 {
238 msn_user_destroy(l->data); 219 msn_user_unref(l->data);
239 } 220 }
240 g_list_free(userlist->users); 221 g_list_free(userlist->users);
241 222
242 /*destroy group list*/ 223 /*destroy group list*/
243 for (l = userlist->groups; l != NULL; l = l->next) 224 for (l = userlist->groups; l != NULL; l = l->next)
501 482
502 user = msn_userlist_find_user(userlist, who); 483 user = msn_userlist_find_user(userlist, who);
503 484
504 g_return_if_fail(user != NULL); 485 g_return_if_fail(user != NULL);
505 486
506 if ( !msn_userlist_user_is_in_list(user, list_id)) { 487 if ( !msn_user_is_in_list(user, list_id)) {
507 list = lists[list_id]; 488 list = lists[list_id];
508 purple_debug_info("msn", "User %s is not in list %s, not removing.\n", who, list); 489 purple_debug_info("msn", "User %s is not in list %s, not removing.\n", who, list);
509 return; 490 return;
510 } 491 }
511 492
567 * ACK to the ADL command), but for now we need to make sure they exist 548 * ACK to the ADL command), but for now we need to make sure they exist
568 * early enough that the ILN command doesn't screw us up */ 549 * early enough that the ILN command doesn't screw us up */
569 550
570 user = msn_userlist_find_add_user(userlist, who, who); 551 user = msn_userlist_find_add_user(userlist, who, who);
571 552
572 if ( msn_userlist_user_is_in_list(user, MSN_LIST_FL) ) { 553 if ( msn_user_is_in_list(user, MSN_LIST_FL) ) {
573 554
574 purple_debug_info("msn", "User %s already exists\n", who); 555 purple_debug_info("msn", "User %s already exists\n", who);
575 556
576 msn_userlist_rem_buddy_from_list(userlist, who, MSN_LIST_BL); 557 msn_userlist_rem_buddy_from_list(userlist, who, MSN_LIST_BL);
577 558
578 if (msn_userlist_user_is_in_group(user, group_id)) { 559 if (msn_user_is_in_group(user, group_id)) {
579 purple_debug_info("msn", "User %s is already in group %s, returning\n", who, new_group_name); 560 purple_debug_info("msn", "User %s is already in group %s, returning\n", who, new_group_name);
580 msn_callback_state_free(state); 561 msn_callback_state_free(state);
581 return; 562 return;
582 } 563 }
583 } 564 }
602 g_return_if_fail(userlist != NULL); 583 g_return_if_fail(userlist != NULL);
603 584
604 user = msn_userlist_find_add_user(userlist, who, who); 585 user = msn_userlist_find_add_user(userlist, who, who);
605 586
606 /* First we're going to check if it's already there. */ 587 /* First we're going to check if it's already there. */
607 if (msn_userlist_user_is_in_list(user, list_id)) 588 if (msn_user_is_in_list(user, list_id))
608 { 589 {
609 list = lists[list_id]; 590 list = lists[list_id];
610 purple_debug_info("msn", "User '%s' is already in list: %s\n", who, list); 591 purple_debug_info("msn", "User '%s' is already in list: %s\n", who, list);
611 return; 592 return;
612 } 593 }
704 * the callback 685 * the callback
705 */ 686 */
706 msn_add_contact_to_group(userlist->session, state, who, new_group_id); 687 msn_add_contact_to_group(userlist->session, state, who, new_group_id);
707 } 688 }
708 689
690 void
691 msn_release_buddy_icon_request(MsnUserList *userlist)
692 {
693 MsnUser *user;
694
695 g_return_if_fail(userlist != NULL);
696
697 if (purple_debug_is_verbose())
698 purple_debug_info("msn", "Releasing buddy icon request\n");
699
700 if (userlist->buddy_icon_window > 0) {
701 GQueue *queue;
702 PurpleAccount *account;
703 const char *username;
704
705 queue = userlist->buddy_icon_requests;
706
707 if (g_queue_is_empty(userlist->buddy_icon_requests))
708 return;
709
710 user = g_queue_pop_head(queue);
711
712 account = userlist->session->account;
713 username = user->passport;
714
715 userlist->buddy_icon_window--;
716
717 msn_request_user_display(user);
718
719 if (purple_debug_is_verbose())
720 purple_debug_info("msn",
721 "msn_release_buddy_icon_request(): buddy_icon_window-- yields =%d\n",
722 userlist->buddy_icon_window);
723 }
724 }
725
709 /*load userlist from the Blist file cache*/ 726 /*load userlist from the Blist file cache*/
710 void 727 void
711 msn_userlist_load(MsnSession *session) 728 msn_userlist_load(MsnSession *session)
712 { 729 {
713 PurpleAccount *account = session->account; 730 PurpleAccount *account = session->account;