comparison libpurple/protocols/msn/userlist.c @ 19843:60bc06498746

Committing khc's msnp14 changes from Trac Ticket #148. --rlaager committer: Richard Laager <rlaager@wiktel.com>
author Ka-Hing Cheung <khc@hxbc.us>
date Sun, 15 Apr 2007 04:12:27 +0000
parents 32c366eeeb99
children 6f986caeab59
comparison
equal deleted inserted replaced
16121:6167ee79ecd0 19843:60bc06498746
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(user->group_ids, group_id))
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;
108 list_op = 1 << list_id; 112 list_op = 1 << list_id;
109 113
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 if (group_id != NULL)
115 if (group_id >= 0)
116 return user_is_in_group(user, group_id); 119 return user_is_in_group(user, group_id);
117 } 120 }
118 121
119 return TRUE; 122 return TRUE;
120 } 123 }
149 152
150 static void 153 static void
151 msn_request_add_group(MsnUserList *userlist, const char *who, 154 msn_request_add_group(MsnUserList *userlist, const char *who,
152 const char *old_group_name, const char *new_group_name) 155 const char *old_group_name, const char *new_group_name)
153 { 156 {
157 MsnSession *session;
154 MsnCmdProc *cmdproc; 158 MsnCmdProc *cmdproc;
155 MsnTransaction *trans;
156 MsnMoveBuddy *data; 159 MsnMoveBuddy *data;
157 160
158 cmdproc = userlist->session->notification->cmdproc; 161 session = userlist->session;
162 cmdproc = session->notification->cmdproc;
159 data = g_new0(MsnMoveBuddy, 1); 163 data = g_new0(MsnMoveBuddy, 1);
160 164
161 data->who = g_strdup(who); 165 data->who = g_strdup(who);
162 166
163 if (old_group_name) 167 if (old_group_name){
164 data->old_group_name = g_strdup(old_group_name); 168 data->old_group_name = g_strdup(old_group_name);
165 169 /*delete the old group via SOAP action*/
166 trans = msn_transaction_new(cmdproc, "ADG", "%s %d", 170 msn_del_group(session,old_group_name);
167 purple_url_encode(new_group_name), 171 }
168 0); 172
169 173 /*add new group via SOAP action*/
170 msn_transaction_set_data(trans, data); 174 msn_add_group(session, new_group_name);
171 175
172 msn_cmdproc_send_trans(cmdproc, trans);
173 } 176 }
174 177
175 /************************************************************************** 178 /**************************************************************************
176 * Server functions 179 * Server functions
177 **************************************************************************/ 180 **************************************************************************/
191 return -1; 194 return -1;
192 } 195 }
193 196
194 void 197 void
195 msn_got_add_user(MsnSession *session, MsnUser *user, 198 msn_got_add_user(MsnSession *session, MsnUser *user,
196 MsnListId list_id, int group_id) 199 MsnListId list_id, const char * group_id)
197 { 200 {
198 PurpleAccount *account; 201 PurpleAccount *account;
199 const char *passport; 202 const char *passport;
200 const char *friendly; 203 const char *friendly;
201 204
205 purple_debug_info("MaYuan","got add user...\n");
202 account = session->account; 206 account = session->account;
203 207
204 passport = msn_user_get_passport(user); 208 passport = msn_user_get_passport(user);
205 friendly = msn_user_get_friendly_name(user); 209 friendly = msn_user_get_friendly_name(user);
206 210
210 214
211 gc = purple_account_get_connection(account); 215 gc = purple_account_get_connection(account);
212 216
213 serv_got_alias(gc, passport, friendly); 217 serv_got_alias(gc, passport, friendly);
214 218
215 if (group_id >= 0) 219 if (group_id != NULL)
216 { 220 {
217 msn_user_add_group_id(user, group_id); 221 msn_user_add_group_id(user, group_id);
218 } 222 }else{
219 else
220 {
221 /* session->sync->fl_users_count++; */ 223 /* session->sync->fl_users_count++; */
222 } 224 }
223 } 225 }else if (list_id == MSN_LIST_AL){
224 else if (list_id == MSN_LIST_AL)
225 {
226 purple_privacy_permit_add(account, passport, TRUE); 226 purple_privacy_permit_add(account, passport, TRUE);
227 } 227 }else if (list_id == MSN_LIST_BL){
228 else if (list_id == MSN_LIST_BL)
229 {
230 purple_privacy_deny_add(account, passport, TRUE); 228 purple_privacy_deny_add(account, passport, TRUE);
231 } 229 }else if (list_id == MSN_LIST_RL){
232 else if (list_id == MSN_LIST_RL)
233 {
234 PurpleConnection *gc; 230 PurpleConnection *gc;
235 PurpleConversation *convo; 231 PurpleConversation *convo;
236 232
237 gc = purple_account_get_connection(account); 233 gc = purple_account_get_connection(account);
238 234
252 purple_conv_im_write(PURPLE_CONV_IM(convo), passport, msg, 248 purple_conv_im_write(PURPLE_CONV_IM(convo), passport, msg,
253 PURPLE_MESSAGE_SYSTEM, time(NULL)); 249 PURPLE_MESSAGE_SYSTEM, time(NULL));
254 g_free(msg); 250 g_free(msg);
255 } 251 }
256 252
257 if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) 253 if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))){
258 {
259 /* 254 /*
260 * TODO: The friendly name was NULL for me when I 255 * TODO: The friendly name was NULL for me when I
261 * looked at this. Maybe we should use the store 256 * looked at this. Maybe we should use the store
262 * name instead? --KingAnt 257 * name instead? --KingAnt
263 */ 258 */
264 got_new_entry(gc, passport, friendly); 259 // got_new_entry(gc, passport, friendly);
265 } 260 }
266 } 261 }
267 262
268 user->list_op |= (1 << list_id); 263 user->list_op |= (1 << list_id);
269 /* purple_user_add_list_id (user, list_id); */ 264 /* purple_user_add_list_id (user, list_id); */
270 } 265 }
271 266
272 void 267 void
273 msn_got_rem_user(MsnSession *session, MsnUser *user, 268 msn_got_rem_user(MsnSession *session, MsnUser *user,
274 MsnListId list_id, int group_id) 269 MsnListId list_id, const char * group_id)
275 { 270 {
276 PurpleAccount *account; 271 PurpleAccount *account;
277 const char *passport; 272 const char *passport;
278 273
279 account = session->account; 274 account = session->account;
280 275
281 passport = msn_user_get_passport(user); 276 passport = msn_user_get_passport(user);
282 277
283 if (list_id == MSN_LIST_FL) 278 if (list_id == MSN_LIST_FL){
284 {
285 /* TODO: When is the user totally removed? */ 279 /* TODO: When is the user totally removed? */
286 if (group_id >= 0) 280 if (group_id != NULL){
287 {
288 msn_user_remove_group_id(user, group_id); 281 msn_user_remove_group_id(user, group_id);
289 return; 282 return;
290 } 283 }else{
291 else
292 {
293 /* session->sync->fl_users_count--; */ 284 /* session->sync->fl_users_count--; */
294 } 285 }
295 } 286 }else if (list_id == MSN_LIST_AL){
296 else if (list_id == MSN_LIST_AL)
297 {
298 purple_privacy_permit_remove(account, passport, TRUE); 287 purple_privacy_permit_remove(account, passport, TRUE);
299 } 288 }else if (list_id == MSN_LIST_BL){
300 else if (list_id == MSN_LIST_BL)
301 {
302 purple_privacy_deny_remove(account, passport, TRUE); 289 purple_privacy_deny_remove(account, passport, TRUE);
303 } 290 }else if (list_id == MSN_LIST_RL){
304 else if (list_id == MSN_LIST_RL)
305 {
306 PurpleConversation *convo; 291 PurpleConversation *convo;
307 292
308 purple_debug_info("msn", 293 purple_debug_info("msn",
309 "%s has removed you from his or her buddy list.\n", 294 "%s has removed you from his or her buddy list.\n",
310 passport); 295 passport);
325 } 310 }
326 311
327 user->list_op &= ~(1 << list_id); 312 user->list_op &= ~(1 << list_id);
328 /* purple_user_remove_list_id (user, list_id); */ 313 /* purple_user_remove_list_id (user, list_id); */
329 314
330 if (user->list_op == 0) 315 if (user->list_op == 0){
331 {
332 purple_debug_info("msn", "Buddy '%s' shall be deleted?.\n", 316 purple_debug_info("msn", "Buddy '%s' shall be deleted?.\n",
333 passport); 317 passport);
334
335 } 318 }
336 } 319 }
337 320
338 void 321 void
339 msn_got_lst_user(MsnSession *session, MsnUser *user, 322 msn_got_lst_user(MsnSession *session, MsnUser *user,
348 gc = purple_account_get_connection(account); 331 gc = purple_account_get_connection(account);
349 332
350 passport = msn_user_get_passport(user); 333 passport = msn_user_get_passport(user);
351 store = msn_user_get_store_name(user); 334 store = msn_user_get_store_name(user);
352 335
353 if (list_op & MSN_LIST_FL_OP) 336 if (list_op & MSN_LIST_FL_OP){
354 {
355 GSList *c; 337 GSList *c;
356 for (c = group_ids; c != NULL; c = g_slist_next(c)) 338 for (c = group_ids; c != NULL; c = g_slist_next(c)) {
357 { 339 char *group_id;
358 int group_id; 340 group_id = c->data;
359 group_id = GPOINTER_TO_INT(c->data);
360 msn_user_add_group_id(user, group_id); 341 msn_user_add_group_id(user, group_id);
361 } 342 }
362 343
363 /* FIXME: It might be a real alias */ 344 /* FIXME: It might be a real alias */
364 /* Umm, what? This might fix bug #1385130 */ 345 /* Umm, what? This might fix bug #1385130 */
365 serv_got_alias(gc, passport, store); 346 serv_got_alias(gc, passport, store);
366 } 347 }
367 348
368 if (list_op & MSN_LIST_AL_OP) 349 if (list_op & MSN_LIST_AL_OP){
369 {
370 /* These are users who are allowed to see our status. */ 350 /* These are users who are allowed to see our status. */
371 purple_privacy_deny_remove(account, passport, TRUE); 351 purple_privacy_deny_remove(account, passport, TRUE);
372 purple_privacy_permit_add(account, passport, TRUE); 352 purple_privacy_permit_add(account, passport, TRUE);
373 } 353 }
374 354
375 if (list_op & MSN_LIST_BL_OP) 355 if (list_op & MSN_LIST_BL_OP){
376 {
377 /* These are users who are not allowed to see our status. */ 356 /* These are users who are not allowed to see our status. */
378 purple_privacy_permit_remove(account, passport, TRUE); 357 purple_privacy_permit_remove(account, passport, TRUE);
379 purple_privacy_deny_add(account, passport, TRUE); 358 purple_privacy_deny_add(account, passport, TRUE);
380 } 359 }
381 360
382 if (list_op & MSN_LIST_RL_OP) 361 if (list_op & MSN_LIST_RL_OP){
383 {
384 /* These are users who have us on their buddy list. */ 362 /* These are users who have us on their buddy list. */
385 /* 363 /*
386 * TODO: What is store name set to when this happens? 364 * TODO: What is store name set to when this happens?
387 * For one of my accounts "something@hotmail.com" 365 * For one of my accounts "something@hotmail.com"
388 * the store name was "something." Maybe we 366 * the store name was "something." Maybe we
389 * should use the friendly name, instead? --KingAnt 367 * should use the friendly name, instead? --KingAnt
390 */ 368 */
391 369
392 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))) 370 if (!(list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP))){
393 { 371 // got_new_entry(gc, passport, store);
394 got_new_entry(gc, passport, store); 372 }
395 } 373 }
396 } 374
397 375 user->list_op |= list_op;
398 user->list_op = list_op;
399 } 376 }
400 377
401 /************************************************************************** 378 /**************************************************************************
402 * UserList functions 379 * UserList functions
403 **************************************************************************/ 380 **************************************************************************/
423 void 400 void
424 msn_userlist_destroy(MsnUserList *userlist) 401 msn_userlist_destroy(MsnUserList *userlist)
425 { 402 {
426 GList *l; 403 GList *l;
427 404
428 for (l = userlist->users; l != NULL; l = l->next) 405 /*destroy userlist*/
429 { 406 for (l = userlist->users; l != NULL; l = l->next){
430 msn_user_destroy(l->data); 407 msn_user_destroy(l->data);
431 } 408 }
432
433 g_list_free(userlist->users); 409 g_list_free(userlist->users);
434 410
435 for (l = userlist->groups; l != NULL; l = l->next) 411 /*destroy group list*/
436 { 412 for (l = userlist->groups; l != NULL; l = l->next){
437 msn_group_destroy(l->data); 413 msn_group_destroy(l->data);
438 } 414 }
439
440 g_list_free(userlist->groups); 415 g_list_free(userlist->groups);
441 416
442 g_queue_free(userlist->buddy_icon_requests); 417 g_queue_free(userlist->buddy_icon_requests);
443 418
444 if (userlist->buddy_icon_request_timer) 419 if (userlist->buddy_icon_request_timer)
445 purple_timeout_remove(userlist->buddy_icon_request_timer); 420 purple_timeout_remove(userlist->buddy_icon_request_timer);
446 421
447 g_free(userlist); 422 g_free(userlist);
448 } 423 }
449 424
425 MsnUser *
426 msn_userlist_find_add_user(MsnUserList *userlist,const char *passport,const char *userName)
427 {
428 MsnUser *user;
429
430 user = msn_userlist_find_user(userlist, passport);
431 if (user == NULL){
432 user = msn_user_new(userlist, passport, userName);
433 msn_userlist_add_user(userlist, user);
434 }
435 msn_user_set_store_name(user, userName);
436 return user;
437 }
438
450 void 439 void
451 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user) 440 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user)
452 { 441 {
453 userlist->users = g_list_append(userlist->users, user); 442 userlist->users = g_list_append(userlist->users, user);
454 } 443 }
464 { 453 {
465 GList *l; 454 GList *l;
466 455
467 g_return_val_if_fail(passport != NULL, NULL); 456 g_return_val_if_fail(passport != NULL, NULL);
468 457
469 for (l = userlist->users; l != NULL; l = l->next) 458 for (l = userlist->users; l != NULL; l = l->next){
470 {
471 MsnUser *user = (MsnUser *)l->data; 459 MsnUser *user = (MsnUser *)l->data;
472 460 // purple_debug_info("MsnUserList","user passport:%s,passport:%s\n",user->passport,passport);
473 g_return_val_if_fail(user->passport != NULL, NULL); 461 g_return_val_if_fail(user->passport != NULL, NULL);
474 462
475 if (!strcmp(passport, user->passport)) 463 if (!g_strcasecmp(passport, user->passport)){
464 // purple_debug_info("MsnUserList","return:%p\n",user);
476 return user; 465 return user;
466 }
477 } 467 }
478 468
479 return NULL; 469 return NULL;
480 } 470 }
481 471
490 { 480 {
491 userlist->groups = g_list_remove(userlist->groups, group); 481 userlist->groups = g_list_remove(userlist->groups, group);
492 } 482 }
493 483
494 MsnGroup * 484 MsnGroup *
495 msn_userlist_find_group_with_id(MsnUserList *userlist, int id) 485 msn_userlist_find_group_with_id(MsnUserList *userlist, const char * id)
496 { 486 {
497 GList *l; 487 GList *l;
498 488
499 g_return_val_if_fail(userlist != NULL, NULL); 489 g_return_val_if_fail(userlist != NULL, NULL);
500 g_return_val_if_fail(id >= 0, NULL); 490 g_return_val_if_fail(id != NULL, NULL);
501 491
502 for (l = userlist->groups; l != NULL; l = l->next) 492 for (l = userlist->groups; l != NULL; l = l->next){
503 {
504 MsnGroup *group = l->data; 493 MsnGroup *group = l->data;
505 494
506 if (group->id == id) 495 if (!g_strcasecmp(group->id,id))
507 return group; 496 return group;
508 } 497 }
509 498
510 return NULL; 499 return NULL;
511 } 500 }
516 GList *l; 505 GList *l;
517 506
518 g_return_val_if_fail(userlist != NULL, NULL); 507 g_return_val_if_fail(userlist != NULL, NULL);
519 g_return_val_if_fail(name != NULL, NULL); 508 g_return_val_if_fail(name != NULL, NULL);
520 509
521 for (l = userlist->groups; l != NULL; l = l->next) 510 for (l = userlist->groups; l != NULL; l = l->next){
522 {
523 MsnGroup *group = l->data; 511 MsnGroup *group = l->data;
524 512
525 if ((group->name != NULL) && !g_ascii_strcasecmp(name, group->name)) 513 if ((group->name != NULL) && !g_strcasecmp(name, group->name))
526 return group; 514 return group;
527 } 515 }
528 516
529 return NULL; 517 return NULL;
530 } 518 }
531 519
532 int 520 const char *
533 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name) 521 msn_userlist_find_group_id(MsnUserList *userlist, const char *group_name)
534 { 522 {
535 MsnGroup *group; 523 MsnGroup *group;
536 524
537 group = msn_userlist_find_group_with_name(userlist, group_name); 525 group = msn_userlist_find_group_with_name(userlist, group_name);
538 526
539 if (group != NULL) 527 if (group != NULL){
540 return msn_group_get_id(group); 528 return msn_group_get_id(group);
541 else 529 }else{
542 return -1; 530 return NULL;
531 }
543 } 532 }
544 533
545 const char * 534 const char *
546 msn_userlist_find_group_name(MsnUserList *userlist, int group_id) 535 msn_userlist_find_group_name(MsnUserList *userlist, const char * group_id)
547 { 536 {
548 MsnGroup *group; 537 MsnGroup *group;
549 538
550 group = msn_userlist_find_group_with_id(userlist, group_id); 539 group = msn_userlist_find_group_with_id(userlist, group_id);
551 540
552 if (group != NULL) 541 if (group != NULL){
553 return msn_group_get_name(group); 542 return msn_group_get_name(group);
554 else 543 }else{
555 return NULL; 544 return NULL;
556 } 545 }
557 546 }
558 void 547
559 msn_userlist_rename_group_id(MsnUserList *userlist, int group_id, 548 void
549 msn_userlist_rename_group_id(MsnUserList *userlist, const char * group_id,
560 const char *new_name) 550 const char *new_name)
561 { 551 {
562 MsnGroup *group; 552 MsnGroup *group;
563 553
564 group = msn_userlist_find_group_with_id(userlist, group_id); 554 group = msn_userlist_find_group_with_id(userlist, group_id);
566 if (group != NULL) 556 if (group != NULL)
567 msn_group_set_name(group, new_name); 557 msn_group_set_name(group, new_name);
568 } 558 }
569 559
570 void 560 void
571 msn_userlist_remove_group_id(MsnUserList *userlist, int group_id) 561 msn_userlist_remove_group_id(MsnUserList *userlist, const char * group_id)
572 { 562 {
573 MsnGroup *group; 563 MsnGroup *group;
574 564
575 group = msn_userlist_find_group_with_id(userlist, group_id); 565 group = msn_userlist_find_group_with_id(userlist, group_id);
576 566
584 void 574 void
585 msn_userlist_rem_buddy(MsnUserList *userlist, 575 msn_userlist_rem_buddy(MsnUserList *userlist,
586 const char *who, int list_id, const char *group_name) 576 const char *who, int list_id, const char *group_name)
587 { 577 {
588 MsnUser *user; 578 MsnUser *user;
589 int group_id; 579 const char *group_id;
590 const char *list; 580 const char *list;
591 581
592 user = msn_userlist_find_user(userlist, who); 582 user = msn_userlist_find_user(userlist, who);
593 group_id = -1; 583
594 584 g_return_if_fail(user != NULL);
595 if (group_name != NULL) 585
596 { 586 /*delete the contact from address book via soap action*/
587 msn_delete_contact(userlist->session->contact,user->uid);
588
589 group_id = NULL;
590
591 if (group_name != NULL){
597 group_id = msn_userlist_find_group_id(userlist, group_name); 592 group_id = msn_userlist_find_group_id(userlist, group_name);
598 593
599 if (group_id < 0) 594 if (group_id == NULL){
600 {
601 /* Whoa, there is no such group. */ 595 /* Whoa, there is no such group. */
602 purple_debug_error("msn", "Group doesn't exist: %s\n", group_name); 596 purple_debug_error("msn", "Group doesn't exist: %s\n", group_name);
603 return; 597 return;
604 } 598 }
605 } 599 }
606 600
607 /* First we're going to check if not there. */ 601 /* First we're going to check if not there. */
608 if (!(user_is_there(user, list_id, group_id))) 602 if (!(user_is_there(user, list_id, group_id))){
609 {
610 list = lists[list_id]; 603 list = lists[list_id];
611 purple_debug_error("msn", "User '%s' is not there: %s\n", 604 purple_debug_error("msn", "User '%s' is not there: %s\n",
612 who, list); 605 who, list);
613 return; 606 return;
614 } 607 }
617 list = lists[list_id]; 610 list = lists[list_id];
618 611
619 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id); 612 msn_notification_rem_buddy(userlist->session->notification, list, who, group_id);
620 } 613 }
621 614
615 /*add buddy*/
622 void 616 void
623 msn_userlist_add_buddy(MsnUserList *userlist, 617 msn_userlist_add_buddy(MsnUserList *userlist,
624 const char *who, int list_id, 618 const char *who, int list_id,
625 const char *group_name) 619 const char *group_name)
626 { 620 {
627 MsnUser *user; 621 MsnUser *user;
628 int group_id; 622 const char *group_id;
629 const char *list; 623 const char *list;
630 const char *store_name; 624 const char *store_name;
631 625
632 group_id = -1; 626 purple_debug_info("MaYuan", "userlist add buddy,name:{%s},group:{%s}\n",who ,group_name);
633 627 group_id = NULL;
634 if (!purple_email_is_valid(who)) 628
635 { 629 if (!purple_email_is_valid(who)){
636 /* only notify the user about problems adding to the friends list 630 /* only notify the user about problems adding to the friends list
637 * maybe we should do something else for other lists, but it probably 631 * maybe we should do something else for other lists, but it probably
638 * won't cause too many problems if we just ignore it */ 632 * won't cause too many problems if we just ignore it */
639 if (list_id == MSN_LIST_FL) 633 if (list_id == MSN_LIST_FL) {
640 {
641 char *str = g_strdup_printf(_("Unable to add \"%s\"."), who); 634 char *str = g_strdup_printf(_("Unable to add \"%s\"."), who);
642 purple_notify_error(NULL, NULL, str, 635 purple_notify_error(NULL, NULL, str,
643 _("The screen name specified is invalid.")); 636 _("The screen name specified is invalid."));
644 g_free(str); 637 g_free(str);
645 } 638 }
646 639
647 return; 640 return;
648 } 641 }
649 642
650 if (group_name != NULL) 643 if (group_name != NULL){
651 {
652 group_id = msn_userlist_find_group_id(userlist, group_name); 644 group_id = msn_userlist_find_group_id(userlist, group_name);
653 645
654 if (group_id < 0) 646 if (group_id == NULL){
655 {
656 /* Whoa, we must add that group first. */ 647 /* Whoa, we must add that group first. */
657 msn_request_add_group(userlist, who, NULL, group_name); 648 msn_request_add_group(userlist, who, NULL, group_name);
658 return; 649 return;
659 } 650 }
660 } 651 }
661 652
662 user = msn_userlist_find_user(userlist, who); 653 user = msn_userlist_find_user(userlist, who);
663 654
664 /* First we're going to check if it's already there. */ 655 /* First we're going to check if it's already there. */
665 if (user_is_there(user, list_id, group_id)) 656 if (user_is_there(user, list_id, group_id)){
666 {
667 list = lists[list_id]; 657 list = lists[list_id];
668 purple_debug_error("msn", "User '%s' is already there: %s\n", who, list); 658 purple_debug_error("msn", "User '%s' is already there: %s\n", who, list);
669 return; 659 return;
670 } 660 }
671 661
672 store_name = (user != NULL) ? get_store_name(user) : who; 662 store_name = (user != NULL) ? get_store_name(user) : who;
673 663
674 /* Then request the add to the server. */ 664 /* Then request the add to the server. */
675 list = lists[list_id]; 665 list = lists[list_id];
676 666
667 purple_debug_info("MaYuan", "add user:{%s} to group id {%s}\n",store_name ,group_id);
668 msn_add_contact(userlist->session->contact,who,group_id);
669 #if 1
677 msn_notification_add_buddy(userlist->session->notification, list, who, 670 msn_notification_add_buddy(userlist->session->notification, list, who,
678 store_name, group_id); 671 store_name, group_id);
672 #endif
679 } 673 }
680 674
681 void 675 void
682 msn_userlist_move_buddy(MsnUserList *userlist, const char *who, 676 msn_userlist_move_buddy(MsnUserList *userlist, const char *who,
683 const char *old_group_name, const char *new_group_name) 677 const char *old_group_name, const char *new_group_name)
684 { 678 {
685 int new_group_id; 679 const char *new_group_id;
686 680
687 new_group_id = msn_userlist_find_group_id(userlist, new_group_name); 681 new_group_id = msn_userlist_find_group_id(userlist, new_group_name);
688 682
689 if (new_group_id < 0) 683 if (new_group_id == NULL){
690 {
691 msn_request_add_group(userlist, who, old_group_name, new_group_name); 684 msn_request_add_group(userlist, who, old_group_name, new_group_name);
692 return; 685 return;
693 } 686 }
694 687
695 msn_userlist_add_buddy(userlist, who, MSN_LIST_FL, new_group_name); 688 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); 689 msn_userlist_rem_buddy(userlist, who, MSN_LIST_FL, old_group_name);
697 } 690 }
691
692 /*load userlist from the Blist file cache*/
693 void
694 msn_userlist_load(MsnSession *session)
695 {
696 PurpleBlistNode *gnode, *cnode, *bnode;
697 PurpleConnection *gc = purple_account_get_connection(session->account);
698 GSList *l;
699 MsnUser * user;
700
701 g_return_if_fail(gc != NULL);
702
703 for (gnode = purple_get_blist()->root; gnode; gnode = gnode->next){
704 if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
705 continue;
706 for(cnode = gnode->child; cnode; cnode = cnode->next) {
707 if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
708 continue;
709 for(bnode = cnode->child; bnode; bnode = bnode->next) {
710 PurpleBuddy *b;
711 if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
712 continue;
713 b = (PurpleBuddy *)bnode;
714 if(b->account == gc->account){
715 user = msn_userlist_find_add_user(session->userlist,
716 b->name,NULL);
717 b->proto_data = user;
718 msn_user_set_op(user, MSN_LIST_FL_OP);
719 }
720 }
721 }
722 }
723 for (l = session->account->permit; l != NULL; l = l->next) {
724 user = msn_userlist_find_add_user(session->userlist,
725 (char *)l->data,NULL);
726 msn_user_set_op(user, MSN_LIST_AL_OP);
727 }
728 for (l = session->account->deny; l != NULL; l = l->next) {
729 user = msn_userlist_find_add_user(session->userlist,
730 (char *)l->data,NULL);
731 msn_user_set_op(user, MSN_LIST_BL_OP);
732 }
733
734 }
735