summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-03-28 13:40:14 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-03-28 13:40:43 (GMT)
commitb61486fefe602e0d18fa5279021006f87b965307 (patch)
tree437585cbef1179e1ec31f79789591d5610200c29 /Swiften/Avatars/AvatarManager.cpp
parentdae28dd45e43fc6e6ef2ec4c6c65d5d736ed86f8 (diff)
downloadswift-contrib-b61486fefe602e0d18fa5279021006f87b965307.zip
swift-contrib-b61486fefe602e0d18fa5279021006f87b965307.tar.bz2
Moved Swiften to a separate module.
Diffstat (limited to 'Swiften/Avatars/AvatarManager.cpp')
m---------Swiften0
-rw-r--r--Swiften/Avatars/AvatarManager.cpp108
2 files changed, 0 insertions, 108 deletions
diff --git a/Swiften b/Swiften
new file mode 160000
+Subproject 8213ba16d0043d2461f4b031c881d61dda5a38c
diff --git a/Swiften/Avatars/AvatarManager.cpp b/Swiften/Avatars/AvatarManager.cpp
deleted file mode 100644
index 3825ffd..0000000
--- a/Swiften/Avatars/AvatarManager.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-#include "Swiften/Avatars/AvatarManager.h"
-
-#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"
-
-namespace Swift {
-
-AvatarManager::AvatarManager(StanzaChannel* stanzaChannel, IQRouter* iqRouter, AvatarStorage* avatarStorage, MUCRegistry* mucRegistry) : stanzaChannel_(stanzaChannel), iqRouter_(iqRouter), avatarStorage_(avatarStorage), mucRegistry_(mucRegistry) {
- stanzaChannel->onPresenceReceived.connect(boost::bind(&AvatarManager::handlePresenceReceived, this, _1));
-}
-
-AvatarManager::AvatarManager() {
- stanzaChannel_ = NULL;
- iqRouter_ = NULL;
- avatarStorage_ = NULL;
- mucRegistry_ = NULL;
-}
-
-AvatarManager::~AvatarManager() {
-
-}
-
-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) {
- return;
- }
- JID from = getAvatarJID(presence->getFrom());
- String& hash = avatarHashes_[from];
- if (hash != update->getPhotoHash()) {
- String newHash = update->getPhotoHash();
- if (avatarStorage_->hasAvatar(newHash)) {
- setAvatarHash(from, newHash);
- }
- else {
- boost::shared_ptr<GetVCardRequest> request(new GetVCardRequest(from, iqRouter_));
- request->onResponse.connect(boost::bind(&AvatarManager::handleVCardReceived, this, from, newHash, _1, _2));
- request->send();
- }
- }
-}
-
-void AvatarManager::handleVCardReceived(const JID& from, const String& promisedHash, boost::shared_ptr<VCard> vCard, const boost::optional<ErrorPayload>& error) {
- if (error) {
- // FIXME: What to do here?
- std::cerr << "Warning: " << from << ": Could not get vCard" << std::endl;
- return;
- }
- if (!vCard) {
- std::cerr << "Warning: " << from << ": null vcard payload" << std::endl;
- //FIXME: Why could this happen?
- return;
- }
- String realHash = Hexify::hexify(SHA1::getHash(vCard->getPhoto()));
- if (promisedHash != realHash) {
- std::cerr << "Warning: " << from << ": Got different vCard photo hash (" << promisedHash << " != " << realHash << ")" << std::endl;
- }
- avatarStorage_->addAvatar(realHash, vCard->getPhoto());
- setAvatarHash(from, realHash);
-}
-
-void AvatarManager::setAvatar(const JID& jid, const ByteArray& avatar) {
- String hash = Hexify::hexify(SHA1::getHash(avatar));
- avatarStorage_->addAvatar(hash, avatar);
- setAvatarHash(getAvatarJID(jid), hash);
-}
-
-void AvatarManager::setAvatarHash(const JID& from, const String& hash) {
- avatarHashes_[from] = hash;
- onAvatarChanged(from, 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 "";
- }
-}
-
-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;
-}
-
-
-}