summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-24 09:04:21 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-10-24 09:04:21 (GMT)
commit6b4bdb629ead79141b20ca72b8634136d351966d (patch)
tree4b1ff747c57bb2e7cdf9f8559e15f5ccbe009a1e /Swiften/Avatars
parent4061c75765c2aa1e96d79711baaa735996007cc6 (diff)
downloadswift-contrib-6b4bdb629ead79141b20ca72b8634136d351966d.zip
swift-contrib-6b4bdb629ead79141b20ca72b8634136d351966d.tar.bz2
Clear VCardUpdate avatar hash on stream reset.
Resolves: #554 Release-Notes: Fixed a bug where avatars would no longer appear after reconnecting.
Diffstat (limited to 'Swiften/Avatars')
-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);
+ }
}
}