Mercurial > pidgin
comparison libpurple/protocols/mxit/roster.c @ 30289:8c586dbcae2d
Since a buddy's avatar information is distributed as part of their online
presence information, if they have changed their avatar while we were
offline (and they're now offline) we won't see the change until we're both
online at the same time.
So when the user requests to view a buddy's profile, we now also request
their current AvatarId - if it is different to what Pidgin has cached, we
request the new image.
Move buddy's avatar processing out of mxit_update_buddy_presence() and into
new function mxit_update_buddy_avatar(). The buddy avatar updating is
called when we receive a buddy's presence update or when we request the
buddies profile.
author | andrew.victor@mxit.com |
---|---|
date | Tue, 20 Jul 2010 09:46:28 +0000 |
parents | d9e94339ca3b |
children | 18a903a3b474 |
comparison
equal
deleted
inserted
replaced
30288:d9e94339ca3b | 30289:8c586dbcae2d |
---|---|
426 * @param username The contact which presence to update | 426 * @param username The contact which presence to update |
427 * @param presence The new presence state for the contact | 427 * @param presence The new presence state for the contact |
428 * @param mood The new mood for the contact | 428 * @param mood The new mood for the contact |
429 * @param customMood The custom mood identifier | 429 * @param customMood The custom mood identifier |
430 * @param statusMsg This is the contact's status message | 430 * @param statusMsg This is the contact's status message |
431 * @param avatarId This is the contact's avatar id | 431 */ |
432 */ | 432 void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg ) |
433 void mxit_update_buddy_presence( struct MXitSession* session, const char* username, short presence, short mood, const char* customMood, const char* statusMsg, const char* avatarId ) | |
434 { | 433 { |
435 PurpleBuddy* buddy = NULL; | 434 PurpleBuddy* buddy = NULL; |
436 struct contact* contact = NULL; | 435 struct contact* contact = NULL; |
437 | 436 |
438 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: user='%s' presence=%i mood=%i customMood='%s' statusMsg='%s' avatar='%s'\n", | 437 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: user='%s' presence=%i mood=%i customMood='%s' statusMsg='%s'\n", |
439 username, presence, mood, customMood, statusMsg, avatarId ); | 438 username, presence, mood, customMood, statusMsg ); |
440 | 439 |
441 if ( ( presence < MXIT_PRESENCE_OFFLINE ) || ( presence > MXIT_PRESENCE_DND ) ) { | 440 if ( ( presence < MXIT_PRESENCE_OFFLINE ) || ( presence > MXIT_PRESENCE_DND ) ) { |
442 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: invalid presence state %i\n", presence ); | 441 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: invalid presence state %i\n", presence ); |
443 return; /* ignore packet */ | 442 return; /* ignore packet */ |
444 } | 443 } |
470 contact->statusMsg = NULL; | 469 contact->statusMsg = NULL; |
471 } | 470 } |
472 if ( statusMsg[0] != '\0' ) | 471 if ( statusMsg[0] != '\0' ) |
473 contact->statusMsg = g_markup_escape_text( statusMsg, -1 ); | 472 contact->statusMsg = g_markup_escape_text( statusMsg, -1 ); |
474 | 473 |
475 /* update avatarId */ | |
476 if ( ( contact->avatarId ) && ( g_ascii_strcasecmp( contact->avatarId, avatarId ) == 0 ) ) { | |
477 /* avatar has not changed - do nothing */ | |
478 } | |
479 else if ( avatarId[0] != '\0' ) { /* avatar has changed */ | |
480 if ( contact->avatarId ) | |
481 g_free( contact->avatarId ); | |
482 contact->avatarId = g_strdup( avatarId ); | |
483 | |
484 /* Send request to download new avatar image */ | |
485 mxit_get_avatar( session, username, avatarId ); | |
486 } | |
487 else /* clear current avatar */ | |
488 purple_buddy_icons_set_for_user( session->acc, username, NULL, 0, NULL ); | |
489 | |
490 /* update the buddy's status (reference: "libpurple/prpl.h") */ | 474 /* update the buddy's status (reference: "libpurple/prpl.h") */ |
491 if ( contact->statusMsg ) | 475 if ( contact->statusMsg ) |
492 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL ); | 476 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, "message", contact->statusMsg, NULL ); |
493 else | 477 else |
494 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, NULL ); | 478 purple_prpl_got_user_status( session->acc, username, mxit_statuses[contact->presence].id, NULL ); |
496 /* update the buddy's mood */ | 480 /* update the buddy's mood */ |
497 if ( contact->mood == MXIT_MOOD_NONE ) | 481 if ( contact->mood == MXIT_MOOD_NONE ) |
498 purple_prpl_got_user_status_deactive( session->acc, username, "mood" ); | 482 purple_prpl_got_user_status_deactive( session->acc, username, "mood" ); |
499 else | 483 else |
500 purple_prpl_got_user_status( session->acc, username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL ); | 484 purple_prpl_got_user_status( session->acc, username, "mood", PURPLE_MOOD_NAME, mxit_moods[contact->mood-1].mood, NULL ); |
485 } | |
486 | |
487 | |
488 /*------------------------------------------------------------------------ | |
489 * Update the buddy's avatar. | |
490 * Either a presence update packet was received from the MXit server, or a profile response. | |
491 * | |
492 * @param session The MXit session object | |
493 * @param username The contact which presence to update | |
494 * @param avatarId This is the contact's avatar id | |
495 */ | |
496 void mxit_update_buddy_avatar( struct MXitSession* session, const char* username, const char* avatarId ) | |
497 { | |
498 PurpleBuddy* buddy = NULL; | |
499 struct contact* contact = NULL; | |
500 | |
501 purple_debug_info( MXIT_PLUGIN_ID, "mxit_update_buddy_avatar: user='%s' avatar='%s'\n", username, avatarId ); | |
502 | |
503 /* find the buddy information for this contact (reference: "libpurple/blist.h") */ | |
504 buddy = purple_find_buddy( session->acc, username ); | |
505 if ( !buddy ) { | |
506 purple_debug_warning( MXIT_PLUGIN_ID, "mxit_update_buddy_presence: unable to find the buddy '%s'\n", username ); | |
507 return; | |
508 } | |
509 | |
510 contact = purple_buddy_get_protocol_data( buddy ); | |
511 if ( !contact ) | |
512 return; | |
513 | |
514 if ( ( contact->avatarId ) && ( g_ascii_strcasecmp( contact->avatarId, avatarId ) == 0 ) ) { | |
515 /* avatar has not changed - do nothing */ | |
516 } | |
517 else if ( avatarId[0] != '\0' ) { /* avatar has changed */ | |
518 if ( contact->avatarId ) | |
519 g_free( contact->avatarId ); | |
520 contact->avatarId = g_strdup( avatarId ); | |
521 | |
522 /* Send request to download new avatar image */ | |
523 mxit_get_avatar( session, username, avatarId ); | |
524 } | |
525 else /* clear current avatar */ | |
526 purple_buddy_icons_set_for_user( session->acc, username, NULL, 0, NULL ); | |
501 } | 527 } |
502 | 528 |
503 | 529 |
504 /*------------------------------------------------------------------------ | 530 /*------------------------------------------------------------------------ |
505 * update the blist cached by libPurple. We need to do this to keep | 531 * update the blist cached by libPurple. We need to do this to keep |