From 808a8047237d663e770cb8aec45c7978862b09ac Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Thu, 26 Nov 2009 14:26:18 +0000
Subject: Plugin Avatars into MUCs.

Provides the extra plumbing needed for the MUC faux-roster to be populated with Avatars. This is adding yet another linear time roster operation, and these are going to start adding up eventually.

Resolves: #251

diff --git a/Swift/Controllers/MUCController.cpp b/Swift/Controllers/MUCController.cpp
index da7a9e7..4d0acca 100644
--- a/Swift/Controllers/MUCController.cpp
+++ b/Swift/Controllers/MUCController.cpp
@@ -5,9 +5,11 @@
 #include "Swiften/Base/foreach.h"
 #include "Swift/Controllers/ChatWindow.h"
 #include "Swift/Controllers/ChatWindowFactory.h"
+#include "Swiften/Avatars/AvatarManager.h"
 #include "Swiften/MUC/MUC.h"
 #include "Swiften/Client/StanzaChannel.h"
 #include "Swiften/Roster/Roster.h"
+#include "Swiften/Roster/SetAvatar.h"
 #include "Swiften/Roster/SetPresence.h"
 #include "Swiften/Roster/TreeWidgetFactory.h"
 
@@ -39,6 +41,9 @@ MUCController::MUCController (
 	muc_->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
 	chatWindow_->convertToMUC();
 	chatWindow_->show();
+	if (avatarManager_ != NULL) {
+		avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1, _2));
+	} 
 }
 
 MUCController::~MUCController() {
@@ -46,12 +51,21 @@ MUCController::~MUCController() {
 	delete roster_;
 }
 
+void MUCController::handleAvatarChanged(const JID& jid, const String&) {
+	String path = avatarManager_->getAvatarPath(jid).string();
+	roster_->applyOnItems(SetAvatar(jid, path, JID::WithResource));
+}
+
 void MUCController::handleWindowClosed() {
 	muc_->part();
 }
 
 void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {
-	roster_->addContact(JID(toJID_.getNode(), toJID_.getDomain(), occupant.getNick()), occupant.getNick(), "Occupants");
+	JID jid(JID(toJID_.getNode(), toJID_.getDomain(), occupant.getNick()));
+	roster_->addContact(jid, occupant.getNick(), "Occupants");
+	if (avatarManager_ != NULL) {
+		handleAvatarChanged(jid, "dummy");
+	}
 }
 
 void MUCController::handleOccupantLeft(const MUCOccupant& occupant, MUC::LeavingType, const String& /*reason*/) {
diff --git a/Swift/Controllers/MUCController.h b/Swift/Controllers/MUCController.h
index 7ee6e81..aa5a274 100644
--- a/Swift/Controllers/MUCController.h
+++ b/Swift/Controllers/MUCController.h
@@ -32,6 +32,7 @@ namespace Swift {
 
 		private:
 			void handleWindowClosed();
+			void handleAvatarChanged(const JID& jid, const String&);
 			void handleOccupantJoined(const MUCOccupant& occupant);
 			void handleOccupantLeft(const MUCOccupant& occupant, MUC::LeavingType type, const String& reason);
 			void handleOccupantPresenceChange(boost::shared_ptr<Presence> presence);
-- 
cgit v0.10.2-6-g49f6