summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-08-27 11:58:06 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-08-27 11:58:06 (GMT)
commit0571ecb72660dbdbe06d524eb62e5398dca45586 (patch)
treef3d525ea5450f49c1e06c407f1d7607aad6590a9 /Swift/Controllers/NickResolver.cpp
parent7ff89853f825f0601ac4ec2adfca19edd7863edf (diff)
downloadswift-0571ecb72660dbdbe06d524eb62e5398dca45586.zip
swift-0571ecb72660dbdbe06d524eb62e5398dca45586.tar.bz2
Use own nick at top of roster.
Currently doesn't work because onOwnVCardChanged isn't plumbed in.
Diffstat (limited to 'Swift/Controllers/NickResolver.cpp')
-rw-r--r--Swift/Controllers/NickResolver.cpp32
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_);
+ }
+}
+
}