summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-09-05 11:29:34 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-09-05 12:45:52 (GMT)
commitc9ab4b6c41eef3ccfe6627f62e7bc085c6743a41 (patch)
treed29d63b3100061e4ef54ce3310eb7658996a8a3e /Swiften/Avatars
parent0630c01cf274a9de6b67856b8c00b1503b39353e (diff)
downloadswift-contrib-c9ab4b6c41eef3ccfe6627f62e7bc085c6743a41.zip
swift-contrib-c9ab4b6c41eef3ccfe6627f62e7bc085c6743a41.tar.bz2
Clear VCardUpdateManager's cache upon login.
Resolves: #554
Diffstat (limited to 'Swiften/Avatars')
-rw-r--r--Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp37
-rw-r--r--Swiften/Avatars/VCardUpdateAvatarManager.cpp7
-rw-r--r--Swiften/Avatars/VCardUpdateAvatarManager.h1
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;