summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Avatars/AvatarManager.cpp')
-rw-r--r--Swiften/Avatars/AvatarManager.cpp81
1 files changed, 7 insertions, 74 deletions
diff --git a/Swiften/Avatars/AvatarManager.cpp b/Swiften/Avatars/AvatarManager.cpp
index 33b1bee..909b07c 100644
--- a/Swiften/Avatars/AvatarManager.cpp
+++ b/Swiften/Avatars/AvatarManager.cpp
@@ -8,92 +8,25 @@
#include <boost/bind.hpp>
-#include "Swiften/Client/StanzaChannel.h"
-#include "Swiften/Elements/VCardUpdate.h"
-#include "Swiften/Queries/Requests/GetVCardRequest.h"
-#include "Swiften/StringCodecs/SHA1.h"
-#include "Swiften/StringCodecs/Hexify.h"
-#include "Swiften/Avatars/AvatarStorage.h"
-#include "Swiften/MUC/MUCRegistry.h"
-#include "Swiften/VCards/VCardManager.h"
+#include "Swiften/Avatars/VCardUpdateAvatarManager.h"
namespace Swift {
-AvatarManager::AvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : vcardManager_(vcardManager), stanzaChannel_(stanzaChannel), avatarStorage_(avatarStorage), mucRegistry_(mucRegistry) {
- stanzaChannel->onPresenceReceived.connect(boost::bind(&AvatarManager::handlePresenceReceived, this, _1));
- vcardManager_->onVCardChanged.connect(boost::bind(&AvatarManager::handleVCardChanged, this, _1, _2));
+AvatarManager::AvatarManager(VCardManager* vcardManager, StanzaChannel* stanzaChannel, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) {
+ vcardUpdateAvatarManager = new VCardUpdateAvatarManager(vcardManager, stanzaChannel, avatarStorage, mucRegistry);
+ vcardUpdateAvatarManager->onAvatarChanged.connect(boost::ref(onAvatarChanged));
}
AvatarManager::~AvatarManager() {
-
+ delete vcardUpdateAvatarManager;
}
void AvatarManager::setMUCRegistry(MUCRegistry* mucRegistry) {
- mucRegistry_ = mucRegistry;
-}
-
-void AvatarManager::handlePresenceReceived(boost::shared_ptr<Presence> presence) {
- boost::shared_ptr<VCardUpdate> update = presence->getPayload<VCardUpdate>();
- if (!update || presence->getPayload<ErrorPayload>()) {
- return;
- }
- JID from = getAvatarJID(presence->getFrom());
- if (getAvatarHash(from) == update->getPhotoHash()) {
- return;
- }
- if (avatarStorage_->hasAvatar(update->getPhotoHash())) {
- setAvatarHash(from, update->getPhotoHash());
- }
- else {
- vcardManager_->requestVCard(from);
- }
-}
-
-void AvatarManager::handleVCardChanged(const JID& from, VCard::ref vCard) {
- if (!vCard) {
- std::cerr << "Warning: " << from << ": null vcard payload" << std::endl;
- return;
- }
-
- String hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
- avatarStorage_->addAvatar(hash, vCard->getPhoto());
- setAvatarHash(from, hash);
-}
-
-void AvatarManager::setAvatarHash(const JID& from, const String& hash) {
- avatarHashes_[from] = hash;
- onAvatarChanged(from, hash);
-}
-
-/*
-void AvatarManager::setAvatar(const JID& jid, const ByteArray& avatar) {
- String hash = Hexify::hexify(SHA1::getHash(avatar));
- avatarStorage_->addAvatar(hash, avatar);
- setAvatarHash(getAvatarJID(jid), hash);
-}
-*/
-
-String AvatarManager::getAvatarHash(const JID& jid) const {
- std::map<JID, String>::const_iterator i = avatarHashes_.find(getAvatarJID(jid));
- if (i != avatarHashes_.end()) {
- return i->second;
- }
- else {
- return "";
- }
+ vcardUpdateAvatarManager->setMUCRegistry(mucRegistry);
}
boost::filesystem::path AvatarManager::getAvatarPath(const JID& jid) const {
- String hash = getAvatarHash(jid);
- if (!hash.isEmpty()) {
- return avatarStorage_->getAvatarPath(hash);
- }
- return boost::filesystem::path();
-}
-
-JID AvatarManager::getAvatarJID(const JID& jid) const {
- JID bareFrom = jid.toBare();
- return (mucRegistry_ && mucRegistry_->isMUC(bareFrom)) ? jid : bareFrom;
+ return vcardUpdateAvatarManager->getAvatarPath(jid);
}