diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-03-12 11:45:16 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-03-12 11:45:16 (GMT) |
commit | 1e2722460b9a67713484903bf6382d08f7e09278 (patch) | |
tree | bbce2e9524f927c754ddfedd99f0b9444273c8ff /Swiften/Avatars | |
parent | 137d42c7081fc31deb76446b2f6ef72ae21eeff5 (diff) | |
download | swift-1e2722460b9a67713484903bf6382d08f7e09278.zip swift-1e2722460b9a67713484903bf6382d08f7e09278.tar.bz2 |
Moved vcard photo hash management into vcard storage.
This makes it easy to adapt the code to cache photo hashes if we want to.
Diffstat (limited to 'Swiften/Avatars')
-rw-r--r-- | Swiften/Avatars/AvatarFileStorage.cpp | 4 | ||||
-rw-r--r-- | Swiften/Avatars/VCardAvatarManager.cpp | 13 |
2 files changed, 10 insertions, 7 deletions
diff --git a/Swiften/Avatars/AvatarFileStorage.cpp b/Swiften/Avatars/AvatarFileStorage.cpp index 44a6a7f..5caf794 100644 --- a/Swiften/Avatars/AvatarFileStorage.cpp +++ b/Swiften/Avatars/AvatarFileStorage.cpp @@ -12,6 +12,8 @@ #include <boost/property_tree/xml_parser.hpp> #include <Swiften/Base/foreach.h> +#include <Swiften/StringCodecs/SHA1.h> +#include <Swiften/StringCodecs/Hexify.h> namespace Swift { @@ -44,6 +46,8 @@ bool AvatarFileStorage::hasAvatar(const std::string& hash) const { } void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avatar) { + assert(Hexify::hexify(SHA1::getHash(avatar)) == hash); + boost::filesystem::path avatarPath = getAvatarPath(hash); if (!boost::filesystem::exists(avatarPath.parent_path())) { try { diff --git a/Swiften/Avatars/VCardAvatarManager.cpp b/Swiften/Avatars/VCardAvatarManager.cpp index ce732db..046e6f3 100644 --- a/Swiften/Avatars/VCardAvatarManager.cpp +++ b/Swiften/Avatars/VCardAvatarManager.cpp @@ -29,17 +29,16 @@ void VCardAvatarManager::handleVCardChanged(const JID& from) { } std::string VCardAvatarManager::getAvatarHash(const JID& jid) const { - VCard::ref vCard = vcardManager_->getVCard(getAvatarJID(jid)); - if (vCard && !vCard->getPhoto().isEmpty()) { - std::string hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto())); + JID avatarJID = getAvatarJID(jid); + std::string hash = vcardManager_->getPhotoHash(avatarJID); + if (!hash.empty()) { if (!avatarStorage_->hasAvatar(hash)) { + VCard::ref vCard = vcardManager_->getVCard(avatarJID); + assert(vCard); avatarStorage_->addAvatar(hash, vCard->getPhoto()); } - return hash; - } - else { - return ""; } + return hash; } JID VCardAvatarManager::getAvatarJID(const JID& jid) const { |