Mercurial > pidgin.yaz
comparison libpurple/protocols/mxit/roster.c @ 29725:ecc6217baa1e
struct hiding updates for mxit
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Fri, 11 Dec 2009 00:44:42 +0000 |
parents | 259bbfb423d4 |
children | 085020c013eb |
comparison
equal
deleted
inserted
replaced
29724:ca106d1e3d6d | 29725:ecc6217baa1e |
---|---|
316 buddy = NULL; | 316 buddy = NULL; |
317 } | 317 } |
318 | 318 |
319 /* create new buddy */ | 319 /* create new buddy */ |
320 buddy = purple_buddy_new( session->acc, contact->username, contact->alias ); | 320 buddy = purple_buddy_new( session->acc, contact->username, contact->alias ); |
321 buddy->proto_data = contact; | 321 purple_buddy_set_protocol_data(buddy, contact); |
322 | 322 |
323 /* add new buddy to list */ | 323 /* add new buddy to list */ |
324 purple_blist_add_buddy( buddy, NULL, group, NULL ); | 324 purple_blist_add_buddy( buddy, NULL, group, NULL ); |
325 } | 325 } |
326 else { | 326 else { |
327 /* buddy was found in the group */ | 327 /* buddy was found in the group */ |
328 | 328 |
329 gpointer data = NULL; | |
330 | |
329 /* now update the buddy's alias */ | 331 /* now update the buddy's alias */ |
330 purple_blist_alias_buddy( buddy, contact->alias ); | 332 purple_blist_alias_buddy( buddy, contact->alias ); |
331 | 333 |
332 /* replace the buddy's contact struct */ | 334 /* replace the buddy's contact struct */ |
333 if ( buddy->proto_data ) | 335 if ( ( data = purple_buddy_get_protocol_data( buddy ) ) ) |
334 free( buddy->proto_data ); | 336 free( data ); |
335 buddy->proto_data = contact; | 337 purple_buddy_set_protocol_data( buddy, contact ); |
336 } | 338 } |
337 | 339 |
338 /* load buddy's avatar id */ | 340 /* load buddy's avatar id */ |
339 id = purple_buddy_icons_get_checksum_for_user( buddy ); | 341 id = purple_buddy_icons_get_checksum_for_user( buddy ); |
340 if ( id ) | 342 if ( id ) |
377 if ( !buddy ) { | 379 if ( !buddy ) { |
378 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: unable to find the buddy '%s'\n", username ); | 380 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: unable to find the buddy '%s'\n", username ); |
379 return; | 381 return; |
380 } | 382 } |
381 | 383 |
382 contact = buddy->proto_data; | 384 contact = purple_buddy_get_protocol_data( buddy ); |
383 if ( !contact ) | 385 if ( !contact ) |
384 return; | 386 return; |
385 | 387 |
386 contact->presence = presence; | 388 contact->presence = presence; |
387 contact->mood = mood; | 389 contact->mood = mood; |
437 list = purple_find_buddies( session->acc, NULL ); | 439 list = purple_find_buddies( session->acc, NULL ); |
438 | 440 |
439 for ( i = 0; i < g_slist_length( list ); i++ ) { | 441 for ( i = 0; i < g_slist_length( list ); i++ ) { |
440 buddy = g_slist_nth_data( list, i ); | 442 buddy = g_slist_nth_data( list, i ); |
441 | 443 |
442 if ( !buddy->proto_data ) { | 444 if ( !purple_buddy_get_protocol_data( buddy ) ) { |
445 const gchar *alias = purple_buddy_get_alias( buddy ); | |
446 const gchar *name = purple_buddy_get_name( buddy ); | |
447 | |
443 /* this buddy should be removed, because we did not receive him in our roster update from MXit */ | 448 /* this buddy should be removed, because we did not receive him in our roster update from MXit */ |
444 purple_debug_info( MXIT_PLUGIN_ID, "Removed 'old' buddy from the blist '%s' (%s)\n", buddy->alias, buddy->name ); | 449 purple_debug_info( MXIT_PLUGIN_ID, "Removed 'old' buddy from the blist '%s' (%s)\n", alias, name ); |
445 purple_blist_remove_buddy( buddy ); | 450 purple_blist_remove_buddy( buddy ); |
446 } | 451 } |
447 } | 452 } |
448 | 453 |
449 /* tell the UI to update the blist */ | 454 /* tell the UI to update the blist */ |
533 if ( !buddy ) { | 538 if ( !buddy ) { |
534 purple_debug_warning( MXIT_PLUGIN_ID, "is_mxit_chatroom_contact: unable to find the buddy '%s'\n", username ); | 539 purple_debug_warning( MXIT_PLUGIN_ID, "is_mxit_chatroom_contact: unable to find the buddy '%s'\n", username ); |
535 return FALSE; | 540 return FALSE; |
536 } | 541 } |
537 | 542 |
538 contact = buddy->proto_data; | 543 contact = purple_buddy_get_protocol_data( buddy ); |
539 if ( !contact ) | 544 if ( !contact ) |
540 return FALSE; | 545 return FALSE; |
541 | 546 |
542 return ( contact->type == MXIT_TYPE_CHATROOM ); | 547 return ( contact->type == MXIT_TYPE_CHATROOM ); |
543 } | 548 } |
558 { | 563 { |
559 struct MXitSession* session = (struct MXitSession*) gc->proto_data; | 564 struct MXitSession* session = (struct MXitSession*) gc->proto_data; |
560 GSList* list = NULL; | 565 GSList* list = NULL; |
561 PurpleBuddy* mxbuddy = NULL; | 566 PurpleBuddy* mxbuddy = NULL; |
562 unsigned int i; | 567 unsigned int i; |
563 | 568 const gchar * buddy_name = purple_buddy_get_name( buddy ); |
564 purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy '%s' (group='%s')\n", buddy->name, group->name ); | 569 const gchar * buddy_alias = purple_buddy_get_alias( buddy ); |
565 | 570 const gchar * group_name = purple_group_get_name( group ); |
566 list = purple_find_buddies( session->acc, buddy->name ); | 571 |
572 purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy '%s' (group='%s')\n", buddy_name, group_name ); | |
573 | |
574 list = purple_find_buddies( session->acc, buddy_name ); | |
567 if ( g_slist_length( list ) == 1 ) { | 575 if ( g_slist_length( list ) == 1 ) { |
568 purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy (scenario 1) (list:%i)\n", g_slist_length( list ) ); | 576 purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy (scenario 1) (list:%i)\n", g_slist_length( list ) ); |
569 /* | 577 /* |
570 * we only send an invite to MXit when the user is not already inside our | 578 * we only send an invite to MXit when the user is not already inside our |
571 * blist. this is done because purple does an add_buddy() call when | 579 * blist. this is done because purple does an add_buddy() call when |
572 * you accept an invite. so in that case the user is already | 580 * you accept an invite. so in that case the user is already |
573 * in our blist and ready to be chatted to. | 581 * in our blist and ready to be chatted to. |
574 */ | 582 */ |
575 mxit_send_invite( session, buddy->name, buddy->alias, group->name ); | 583 mxit_send_invite( session, buddy_name, buddy_alias, group_name ); |
576 } | 584 } |
577 else { | 585 else { |
578 purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy (scenario 2) (list:%i)\n", g_slist_length( list ) ); | 586 purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy (scenario 2) (list:%i)\n", g_slist_length( list ) ); |
579 /* | 587 /* |
580 * we already have the buddy in our list, so we will only update | 588 * we already have the buddy in our list, so we will only update |
583 | 591 |
584 /* find the correct buddy */ | 592 /* find the correct buddy */ |
585 for ( i = 0; i < g_slist_length( list ); i++ ) { | 593 for ( i = 0; i < g_slist_length( list ); i++ ) { |
586 mxbuddy = g_slist_nth_data( list, i ); | 594 mxbuddy = g_slist_nth_data( list, i ); |
587 | 595 |
588 if ( mxbuddy->proto_data != NULL ) { | 596 if ( purple_buddy_get_protocol_data( mxbuddy ) != NULL ) { |
589 /* this is our REAL MXit buddy! */ | 597 /* this is our REAL MXit buddy! */ |
590 | 598 |
591 /* now update the buddy's alias */ | 599 /* now update the buddy's alias */ |
592 purple_blist_alias_buddy( mxbuddy, buddy->alias ); | 600 purple_blist_alias_buddy( mxbuddy, buddy_alias ); |
593 | 601 |
594 /* now update the buddy's group */ | 602 /* now update the buddy's group */ |
595 // mxbuddy = mxit_update_buddy_group( session, mxbuddy, group ); | 603 // mxbuddy = mxit_update_buddy_group( session, mxbuddy, group ); |
596 | 604 |
597 /* send the update to the MXit server */ | 605 /* send the update to the MXit server */ |
598 mxit_send_update_contact( session, mxbuddy->name, mxbuddy->alias, group->name ); | 606 mxit_send_update_contact( session, purple_buddy_get_name( mxbuddy ), purple_buddy_get_alias( mxbuddy ), group_name ); |
599 } | 607 } |
600 } | 608 } |
601 } | 609 } |
602 | 610 |
603 /* | 611 /* |
621 * @param group The group the buddy was in | 629 * @param group The group the buddy was in |
622 */ | 630 */ |
623 void mxit_remove_buddy( PurpleConnection* gc, PurpleBuddy* buddy, PurpleGroup* group ) | 631 void mxit_remove_buddy( PurpleConnection* gc, PurpleBuddy* buddy, PurpleGroup* group ) |
624 { | 632 { |
625 struct MXitSession* session = (struct MXitSession*) gc->proto_data; | 633 struct MXitSession* session = (struct MXitSession*) gc->proto_data; |
626 | 634 const gchar * buddy_name = purple_buddy_get_name( buddy ); |
627 purple_debug_info( MXIT_PLUGIN_ID, "mxit_remove_buddy '%s'\n", buddy->name ); | 635 |
628 | 636 purple_debug_info( MXIT_PLUGIN_ID, "mxit_remove_buddy '%s'\n", buddy_name ); |
629 mxit_send_remove( session, buddy->name ); | 637 |
638 mxit_send_remove( session, buddy_name ); | |
630 } | 639 } |
631 | 640 |
632 | 641 |
633 /*------------------------------------------------------------------------ | 642 /*------------------------------------------------------------------------ |
634 * The user changed the buddy's alias. | 643 * The user changed the buddy's alias. |
657 if ( !group ) { | 666 if ( !group ) { |
658 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_buddy_alias: unable to find the group for buddy '%s'\n", who ); | 667 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_buddy_alias: unable to find the group for buddy '%s'\n", who ); |
659 return; | 668 return; |
660 } | 669 } |
661 | 670 |
662 mxit_send_update_contact( session, who, alias, group->name ); | 671 mxit_send_update_contact( session, who, alias, purple_group_get_name( group ) ); |
663 } | 672 } |
664 | 673 |
665 | 674 |
666 /*------------------------------------------------------------------------ | 675 /*------------------------------------------------------------------------ |
667 * The user changed the group for a single buddy. | 676 * The user changed the group for a single buddy. |
683 if ( !buddy ) { | 692 if ( !buddy ) { |
684 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_buddy_group: unable to find the buddy '%s'\n", who ); | 693 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_buddy_group: unable to find the buddy '%s'\n", who ); |
685 return; | 694 return; |
686 } | 695 } |
687 | 696 |
688 mxit_send_update_contact( session, who, buddy->alias, new_group ); | 697 mxit_send_update_contact( session, who, purple_buddy_get_alias( buddy ), new_group ); |
689 } | 698 } |
690 | 699 |
691 | 700 |
692 /*------------------------------------------------------------------------ | 701 /*------------------------------------------------------------------------ |
693 * The user has selected to rename a group, so update all contacts in that | 702 * The user has selected to rename a group, so update all contacts in that |
702 { | 711 { |
703 struct MXitSession* session = (struct MXitSession*) gc->proto_data; | 712 struct MXitSession* session = (struct MXitSession*) gc->proto_data; |
704 PurpleBuddy* buddy = NULL; | 713 PurpleBuddy* buddy = NULL; |
705 GList* item = NULL; | 714 GList* item = NULL; |
706 | 715 |
707 purple_debug_info( MXIT_PLUGIN_ID, "mxit_rename_group from '%s' to '%s\n", old_name, group->name ); | 716 purple_debug_info( MXIT_PLUGIN_ID, "mxit_rename_group from '%s' to '%s\n", old_name, purple_group_get_name( group ) ); |
708 | 717 |
709 // TODO: Might be more efficient to use the "rename group" command (cmd=29). | 718 // TODO: Might be more efficient to use the "rename group" command (cmd=29). |
710 | 719 |
711 /* loop through all the contacts in the group and send updates */ | 720 /* loop through all the contacts in the group and send updates */ |
712 item = moved_buddies; | 721 item = moved_buddies; |
713 while ( item ) { | 722 while ( item ) { |
714 buddy = item->data; | 723 buddy = item->data; |
715 mxit_send_update_contact( session, buddy->name, buddy->alias, group->name ); | 724 mxit_send_update_contact( session, purple_buddy_get_name( buddy ), purple_buddy_get_alias( buddy ), purple_group_get_name( group ) ); |
716 item = g_list_next( item ); | 725 item = g_list_next( item ); |
717 } | 726 } |
718 } | 727 } |
719 | 728 |