From 4a349f3a0e2715ee1d0701ef0c715cf8bea58ce5 Mon Sep 17 00:00:00 2001 From: Kevin Smith <git@kismith.co.uk> Date: Sun, 28 Nov 2010 15:14:53 +0000 Subject: Change Chat Window titles when contacts are renamed. Resolves: #630 Release-Notes: Chat window titles will be updated when contacts are renamed. diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 4247109..ea21aa9 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -34,6 +34,7 @@ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQ presenceOracle_->onPresenceChange.connect(boost::bind(&ChatController::handlePresenceChange, this, _1)); chatStateTracker_->onChatStateChange.connect(boost::bind(&ChatWindow::setContactChatState, chatWindow_, _1)); stanzaChannel_->onStanzaAcked.connect(boost::bind(&ChatController::handleStanzaAcked, this, _1)); + nickResolver_->onNickChanged.connect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2)); String nick = nickResolver_->jidToNick(toJID_); chatWindow_->setName(nick); String startMessage("Starting chat with " + nick); @@ -57,7 +58,14 @@ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQ } +void ChatController::handleContactNickChanged(const JID& jid, const String& /*oldNick*/) { + if (jid.toBare() == toJID_.toBare()) { + chatWindow_->setName(nickResolver_->jidToNick(jid)); + } +} + ChatController::~ChatController() { + nickResolver_->onNickChanged.disconnect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2)); delete chatStateNotifier_; delete chatStateTracker_; } diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h index d7a01c4..f9c686b 100644 --- a/Swift/Controllers/Chat/ChatController.h +++ b/Swift/Controllers/Chat/ChatController.h @@ -33,6 +33,7 @@ namespace Swift { virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const; void handleStanzaAcked(boost::shared_ptr<Stanza> stanza); void dayTicked() {lastWasPresence_ = false;} + void handleContactNickChanged(const JID& jid, const String& /*oldNick*/); private: NickResolver* nickResolver_; diff --git a/Swiften/Client/NickResolver.cpp b/Swiften/Client/NickResolver.cpp index d06a94d..c151dfa 100644 --- a/Swiften/Client/NickResolver.cpp +++ b/Swiften/Client/NickResolver.cpp @@ -26,6 +26,11 @@ NickResolver::NickResolver(const JID& ownJID, XMPPRoster* xmppRoster, VCardManag vcardManager_->onVCardChanged.connect(boost::bind(&NickResolver::handleVCardReceived, this, _1, _2)); } mucRegistry_ = mucRegistry; + xmppRoster_->onJIDUpdated.connect(boost::bind(&NickResolver::handleJIDUpdated, this, _1, _2, _3)); +} + +void NickResolver::handleJIDUpdated(const JID& jid, const String& previousNick, const std::vector<String>& /*groups*/) { + onNickChanged(jid, previousNick); } String NickResolver::jidToNick(const JID& jid) { diff --git a/Swiften/Client/NickResolver.h b/Swiften/Client/NickResolver.h index 7f00acd..806afb8 100644 --- a/Swiften/Client/NickResolver.h +++ b/Swiften/Client/NickResolver.h @@ -23,8 +23,10 @@ namespace Swift { String jidToNick(const JID& jid); boost::signal<void (const String&)> onOwnNickChanged; + boost::signal<void (const JID&, const String& /*previousNick*/)> onNickChanged; private: void handleVCardReceived(const JID& jid, VCard::ref vCard); + void handleJIDUpdated(const JID& jid, const String& previousNick, const std::vector<String>& groups); private: JID ownJID_; -- cgit v0.10.2-6-g49f6