From e8dbe2e2b78cd5e4a66e2e580e12d05b2e69b120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be> Date: Sun, 5 Sep 2010 15:30:28 +0200 Subject: Do not store null VCard avatars. 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) { -- cgit v0.10.2-6-g49f6