diff options
Diffstat (limited to 'Swift/Controllers/NickResolver.cpp')
-rw-r--r-- | Swift/Controllers/NickResolver.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Swift/Controllers/NickResolver.cpp b/Swift/Controllers/NickResolver.cpp index 29ff51b..1d2a3a0 100644 --- a/Swift/Controllers/NickResolver.cpp +++ b/Swift/Controllers/NickResolver.cpp @@ -7,14 +7,22 @@ #include "Swift/Controllers/NickResolver.h" #include <boost/shared_ptr.hpp> +#include <boost/bind.hpp> #include "Swiften/MUC/MUCRegistry.h" #include "Swiften/Roster/XMPPRoster.h" +#include "Swiften/VCards/VCardManager.h" namespace Swift { -NickResolver::NickResolver(boost::shared_ptr<XMPPRoster> xmppRoster) { +NickResolver::NickResolver(const JID& ownJID, boost::shared_ptr<XMPPRoster> xmppRoster, VCardManager* vcardManager) : ownJID_(ownJID) { xmppRoster_ = xmppRoster; + vcardManager_ = vcardManager; + if (vcardManager_) { + vcardManager_->onOwnVCardChanged.connect(boost::bind(&NickResolver::handleOwnVCardReceived, this, _1)); + VCard::ref ownVCard = vcardManager_->getVCardAndRequestWhenNeeded(ownJID_); + handleOwnVCardReceived(ownVCard); + } mucRegistry_ = NULL; } @@ -23,6 +31,11 @@ void NickResolver::setMUCRegistry(MUCRegistry* mucRegistry) { } String NickResolver::jidToNick(const JID& jid) { + if (jid.toBare() == ownJID_) { + if (!ownNick_.isEmpty()) { + return ownNick_; + } + } String nick; if (mucRegistry_ && mucRegistry_->isMUC(jid.toBare()) ) { @@ -37,5 +50,22 @@ String NickResolver::jidToNick(const JID& jid) { return (it == map_.end()) ? jid.toBare() : it->second; } +void NickResolver::handleOwnVCardReceived(VCard::ref ownVCard) { + String initialNick = ownNick_; + ownNick_ = ownJID_.toString(); + if (ownVCard) { + if (!ownVCard->getNickname().isEmpty()) { + ownNick_ = ownVCard->getNickname(); + } else if (!ownVCard->getGivenName().isEmpty()) { + ownNick_ = ownVCard->getGivenName(); + } else if (!ownVCard->getFullName().isEmpty()) { + ownNick_ = ownVCard->getFullName(); + } + } + if (ownNick_ != initialNick) { + onOwnNickChanged(ownNick_); + } +} + } |