diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-09-05 13:30:28 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-09-05 13:30:28 (GMT) |
commit | e8dbe2e2b78cd5e4a66e2e580e12d05b2e69b120 (patch) | |
tree | afe7e15f393ac2a5572e9b5cc16947840c6fa1e9 | |
parent | 89f18c8af344fc94bb5cf19035c74385d1c9df9c (diff) | |
download | swift-e8dbe2e2b78cd5e4a66e2e580e12d05b2e69b120.zip swift-e8dbe2e2b78cd5e4a66e2e580e12d05b2e69b120.tar.bz2 |
Do not store null VCard avatars.
-rw-r--r-- | Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp | 14 | ||||
-rw-r--r-- | Swiften/Avatars/VCardUpdateAvatarManager.cpp | 11 |
2 files changed, 21 insertions, 4 deletions
diff --git a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp index ce100ee..5a98a0e 100644 --- a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp +++ b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp @@ -27,6 +27,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testUpdate_NewHashStoresAvatarAndEmitsNotificationOnVCardReceive); CPPUNIT_TEST(testUpdate_KnownHash); CPPUNIT_TEST(testUpdate_KnownHashFromDifferentUserDoesNotRequestVCardButTriggersNotification); + CPPUNIT_TEST(testVCardWithEmptyPhoto); CPPUNIT_TEST(testStanzaChannelReset); CPPUNIT_TEST_SUITE_END(); @@ -103,6 +104,15 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(avatar1Hash, changes[0].second); } + void testVCardWithEmptyPhoto() { + std::auto_ptr<VCardUpdateAvatarManager> testling = createManager(); + vcardManager->requestVCard(JID("foo@bar.com")); + stanzaChannel->onIQReceived(createVCardResult(ByteArray())); + + CPPUNIT_ASSERT(!avatarStorage->hasAvatar(Hexify::hexify(SHA1::getHash(ByteArray())))); + CPPUNIT_ASSERT_EQUAL(boost::filesystem::path(), testling->getAvatarPath(JID("foo@bar.com"))); + } + void testStanzaChannelReset() { std::auto_ptr<VCardUpdateAvatarManager> testling = createManager(); stanzaChannel->onPresenceReceived(createPresenceWithPhotoHash(user1, avatar1Hash)); @@ -135,7 +145,9 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { IQ::ref createVCardResult(const ByteArray& avatar) { VCard::ref vcard(new VCard()); - vcard->setPhoto(avatar); + if (!avatar.isEmpty()) { + vcard->setPhoto(avatar); + } return IQ::createResult(JID("baz@fum.com"), stanzaChannel->sentStanzas[0]->getID(), vcard); } diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.cpp b/Swiften/Avatars/VCardUpdateAvatarManager.cpp index dbc0b9b..24abfa1 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.cpp +++ b/Swiften/Avatars/VCardUpdateAvatarManager.cpp @@ -52,9 +52,14 @@ void VCardUpdateAvatarManager::handleVCardChanged(const JID& from, VCard::ref vC return; } - String hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto())); - avatarStorage_->addAvatar(hash, vCard->getPhoto()); - setAvatarHash(from, hash); + if (vCard->getPhoto().isEmpty()) { + setAvatarHash(from, ""); + } + else { + String hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto())); + avatarStorage_->addAvatar(hash, vCard->getPhoto()); + setAvatarHash(from, hash); + } } void VCardUpdateAvatarManager::setAvatarHash(const JID& from, const String& hash) { |