summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp22
-rw-r--r--Swiften/Avatars/VCardUpdateAvatarManager.cpp6
2 files changed, 24 insertions, 4 deletions
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<VCardUpdateAvatarManager> 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<int>(changes.size()));
CPPUNIT_ASSERT_EQUAL(user1.toBare(), changes[0]);
+ CPPUNIT_ASSERT_EQUAL(String(""), testling->getAvatarHash(user1.toBare()));
+ }
+
+ void testStanzaChannelReset_ReceiveHashAfterResetUpdatesHash() {
+ std::auto_ptr<VCardUpdateAvatarManager> 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<int>(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<JID, String> oldAvatarHashes;
+ avatarHashes_.swap(oldAvatarHashes);
+ for(std::map<JID, String>::const_iterator i = oldAvatarHashes.begin(); i != oldAvatarHashes.end(); ++i) {
+ onAvatarChanged(i->first);
+ }
}
}