diff options
Diffstat (limited to 'Swiften/Avatars')
-rw-r--r-- | Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp | 37 | ||||
-rw-r--r-- | Swiften/Avatars/VCardUpdateAvatarManager.cpp | 7 | ||||
-rw-r--r-- | Swiften/Avatars/VCardUpdateAvatarManager.h | 1 |
3 files changed, 22 insertions, 23 deletions
diff --git a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp index e3d9c58..ce100ee 100644 --- a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp +++ b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp @@ -27,22 +27,14 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testUpdate_NewHashStoresAvatarAndEmitsNotificationOnVCardReceive); CPPUNIT_TEST(testUpdate_KnownHash); CPPUNIT_TEST(testUpdate_KnownHashFromDifferentUserDoesNotRequestVCardButTriggersNotification); - /*& - CPPUNIT_TEST(testUpdate_UpdateNewHashAlreadyHaveAvatar); - CPPUNIT_TEST(testUpdate_UpdateNewHashFromMUC); - CPPUNIT_TEST(testUpdate_UpdateSameHash);*/ - //CPPUNIT_TEST(testUpdate_UpdateWithError); - /* - CPPUNIT_TEST(testUpdate_UpdateNewHashSameThanOtherUser); - CPPUNIT_TEST(testReceiveVCard); - CPPUNIT_TEST(testGetAvatarPath); - CPPUNIT_TEST(testGetAvatarPathFromMUC);*/ + CPPUNIT_TEST(testStanzaChannelReset); CPPUNIT_TEST_SUITE_END(); public: void setUp() { ownJID = JID("foo@fum.com/bum"); stanzaChannel = new DummyStanzaChannel(); + stanzaChannel->setAvailable(true); iqRouter = new IQRouter(stanzaChannel); mucRegistry = new DummyMUCRegistry(); avatarStorage = new AvatarMemoryStorage(); @@ -111,22 +103,21 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(avatar1Hash, changes[0].second); } -/* - void testUpdate_UpdateNewHashFromMUC() { + void testStanzaChannelReset() { std::auto_ptr<VCardUpdateAvatarManager> testling = createManager(); - } - - */ - - /*void testUpdate_UpdateWithError() { - std::auto_ptr<VCardUpdateAvatarManager> testling = createManager(); - boost::shared_ptr<Presence> update = createPresenceWithPhotoHash(); - update->addPayload(boost::shared_ptr<ErrorPayload>(new ErrorPayload())); - stanzaChannel_->onPresenceReceived(update); + stanzaChannel->onPresenceReceived(createPresenceWithPhotoHash(user1, avatar1Hash)); + stanzaChannel->onIQReceived(createVCardResult(avatar1)); + changes.clear(); + stanzaChannel->sentStanzas.clear(); - CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(stanzaChannel_->sentStanzas.size())); - }*/ + 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].first); + CPPUNIT_ASSERT_EQUAL(avatar1Hash, changes[0].second); + } private: std::auto_ptr<VCardUpdateAvatarManager> createManager() { diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.cpp b/Swiften/Avatars/VCardUpdateAvatarManager.cpp index 80d7730..dbc0b9b 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.cpp +++ b/Swiften/Avatars/VCardUpdateAvatarManager.cpp @@ -21,6 +21,7 @@ namespace Swift { VCardUpdateAvatarManager::VCardUpdateAvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : vcardManager_(vcardManager), stanzaChannel_(stanzaChannel), avatarStorage_(avatarStorage), mucRegistry_(mucRegistry) { stanzaChannel->onPresenceReceived.connect(boost::bind(&VCardUpdateAvatarManager::handlePresenceReceived, this, _1)); + stanzaChannel->onAvailableChanged.connect(boost::bind(&VCardUpdateAvatarManager::handleStanzaChannelAvailableChanged, this, _1)); vcardManager_->onVCardChanged.connect(boost::bind(&VCardUpdateAvatarManager::handleVCardChanged, this, _1, _2)); } @@ -92,5 +93,11 @@ JID VCardUpdateAvatarManager::getAvatarJID(const JID& jid) const { return (mucRegistry_ && mucRegistry_->isMUC(bareFrom)) ? jid : bareFrom; } +void VCardUpdateAvatarManager::handleStanzaChannelAvailableChanged(bool available) { + if (available) { + avatarHashes_.clear(); + } +} + } diff --git a/Swiften/Avatars/VCardUpdateAvatarManager.h b/Swiften/Avatars/VCardUpdateAvatarManager.h index 16c0ca3..e29db1c 100644 --- a/Swiften/Avatars/VCardUpdateAvatarManager.h +++ b/Swiften/Avatars/VCardUpdateAvatarManager.h @@ -35,6 +35,7 @@ namespace Swift { private: void handlePresenceReceived(boost::shared_ptr<Presence>); + void handleStanzaChannelAvailableChanged(bool); void handleVCardChanged(const JID& from, VCard::ref); void setAvatarHash(const JID& from, const String& hash); JID getAvatarJID(const JID& o) const; |