From 6b4bdb629ead79141b20ca72b8634136d351966d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sun, 24 Oct 2010 11:04:21 +0200 Subject: Clear VCardUpdate avatar hash on stream reset. Resolves: #554 Release-Notes: Fixed a bug where avatars would no longer appear after reconnecting. diff --git a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp index 3e8dbdf..054853d 100644 --- a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp +++ b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp @@ -28,7 +28,8 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testUpdate_KnownHash); CPPUNIT_TEST(testUpdate_KnownHashFromDifferentUserDoesNotRequestVCardButTriggersNotification); CPPUNIT_TEST(testVCardWithEmptyPhoto); - CPPUNIT_TEST(testStanzaChannelReset); + CPPUNIT_TEST(testStanzaChannelReset_ClearsHash); + CPPUNIT_TEST(testStanzaChannelReset_ReceiveHashAfterResetUpdatesHash); CPPUNIT_TEST_SUITE_END(); public: @@ -113,7 +114,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(String(), testling->getAvatarHash(JID("foo@bar.com"))); } - void testStanzaChannelReset() { + void testStanzaChannelReset_ClearsHash() { std::auto_ptr testling = createManager(); stanzaChannel->onPresenceReceived(createPresenceWithPhotoHash(user1, avatar1Hash)); stanzaChannel->onIQReceived(createVCardResult(avatar1)); @@ -122,10 +123,25 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { stanzaChannel->setAvailable(false); stanzaChannel->setAvailable(true); - stanzaChannel->onPresenceReceived(createPresenceWithPhotoHash(user1, avatar1Hash)); CPPUNIT_ASSERT_EQUAL(1, static_cast(changes.size())); CPPUNIT_ASSERT_EQUAL(user1.toBare(), changes[0]); + CPPUNIT_ASSERT_EQUAL(String(""), testling->getAvatarHash(user1.toBare())); + } + + void testStanzaChannelReset_ReceiveHashAfterResetUpdatesHash() { + std::auto_ptr testling = createManager(); + stanzaChannel->onPresenceReceived(createPresenceWithPhotoHash(user1, avatar1Hash)); + stanzaChannel->onIQReceived(createVCardResult(avatar1)); + changes.clear(); + stanzaChannel->sentStanzas.clear(); + + stanzaChannel->setAvailable(false); + stanzaChannel->setAvailable(true); + stanzaChannel->onPresenceReceived(createPresenceWithPhotoHash(user1, avatar1Hash)); + + CPPUNIT_ASSERT_EQUAL(2, static_cast(changes.size())); + CPPUNIT_ASSERT_EQUAL(user1.toBare(), changes[1]); CPPUNIT_ASSERT_EQUAL(avatar1Hash, testling->getAvatarHash(user1.toBare())); } diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.cpp b/Swiften/Avatars/VCardUpdateAvatarManager.cpp index b2b4635..879846e 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.cpp +++ b/Swiften/Avatars/VCardUpdateAvatarManager.cpp @@ -90,7 +90,11 @@ JID VCardUpdateAvatarManager::getAvatarJID(const JID& jid) const { void VCardUpdateAvatarManager::handleStanzaChannelAvailableChanged(bool available) { if (available) { - avatarHashes_.clear(); + std::map oldAvatarHashes; + avatarHashes_.swap(oldAvatarHashes); + for(std::map::const_iterator i = oldAvatarHashes.begin(); i != oldAvatarHashes.end(); ++i) { + onAvatarChanged(i->first); + } } } -- cgit v0.10.2-6-g49f6