From a8ac900bfd39f36749b25d97b55f5a08a1020de5 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Mon, 5 Apr 2010 21:44:58 +0100
Subject: Resolve MUC nicks.

Resolves: #245

diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 8aeca97..8c43921 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -143,6 +143,7 @@ void MainController::handleConnected() {
 		rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this));
 
 		chatsManager_ = new ChatsManager(jid_, client_, client_, eventController_, chatWindowFactory_, treeWidgetFactory_, nickResolver_, presenceOracle_, serverDiscoInfo_, presenceSender_, uiEventStream_, chatListWindowFactory_);
+		nickResolver_->setMUCRegistry(chatsManager_);
 		client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1));
 		chatsManager_->setAvatarManager(avatarManager_);
 		rosterController_->onStartChatRequest.connect(boost::bind(&ChatsManager::handleChatRequest, chatsManager_, _1));
diff --git a/Swift/Controllers/NickResolver.cpp b/Swift/Controllers/NickResolver.cpp
index 0886079..5198069 100644
--- a/Swift/Controllers/NickResolver.cpp
+++ b/Swift/Controllers/NickResolver.cpp
@@ -2,16 +2,27 @@
 
 #include <boost/shared_ptr.hpp>
 
+#include "Swiften/MUC/MUCRegistry.h"
 #include "Swiften/Roster/XMPPRoster.h"
 
 namespace Swift {
 
 NickResolver::NickResolver(boost::shared_ptr<XMPPRoster> xmppRoster) {
 	xmppRoster_ = xmppRoster;
+	mucRegistry_ = NULL;
+}
+
+void NickResolver::setMUCRegistry(MUCRegistry* mucRegistry) {
+	mucRegistry_ = mucRegistry;
 }
 
 String NickResolver::jidToNick(const JID& jid) {
 	String nick;
+
+	if (mucRegistry_ && mucRegistry_->isMUC(jid.toBare()) ) {
+		return jid.getResource();
+	}
+
 	if (xmppRoster_->containsJID(jid) && xmppRoster_->getNameForJID(jid) != "") {
 		return xmppRoster_->getNameForJID(jid);
 	}
diff --git a/Swift/Controllers/NickResolver.h b/Swift/Controllers/NickResolver.h
index b7dc005..cf6104d 100644
--- a/Swift/Controllers/NickResolver.h
+++ b/Swift/Controllers/NickResolver.h
@@ -9,14 +9,16 @@
 
 namespace Swift {
 	class XMPPRoster;
+	class MUCRegistry;
 	class NickResolver {
 		public:
 			NickResolver(boost::shared_ptr<XMPPRoster> xmppRoster);
 			String jidToNick(const JID& jid);
-		
+			void setMUCRegistry(MUCRegistry* registry);
 		private:
 			std::map<JID, String> map_;
 			boost::shared_ptr<XMPPRoster> xmppRoster_;
+			MUCRegistry* mucRegistry_;
 	};
 }
 #endif
-- 
cgit v0.10.2-6-g49f6