summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-26 13:42:19 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-26 13:42:19 (GMT)
commit42cf17e614f0c490ea214e36ac4e7ded2d0495b7 (patch)
treed29dd06d1942c89a9e7cfb2243359b4460df01af /Swift/Controllers/Chat
parentfd6e929a54514d5c3f77956429d5ab5fb4271ff2 (diff)
downloadswift-42cf17e614f0c490ea214e36ac4e7ded2d0495b7.zip
swift-42cf17e614f0c490ea214e36ac4e7ded2d0495b7.tar.bz2
Remove MUCs from the ChatsManager's list once you leave them.
Resolves: #292
Diffstat (limited to 'Swift/Controllers/Chat')
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp17
-rw-r--r--Swift/Controllers/Chat/ChatsManager.h1
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp8
-rw-r--r--Swift/Controllers/Chat/MUCController.h5
4 files changed, 28 insertions, 3 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index ac03f8a..104df22 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -56,6 +56,17 @@ void ChatsManager::handleMUCBookmarksChanged() {
}
}
+void ChatsManager::handleUserLeftMUC(MUCController* mucController) {
+ std::map<JID, MUCController*>::iterator it;
+ for (it = mucControllers_.begin(); it != mucControllers_.end(); it++) {
+ if ((*it).second == mucController) {
+ mucControllers_.erase(it);
+ delete mucController;
+ return;
+ }
+ }
+}
+
void ChatsManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
boost::shared_ptr<RequestChatUIEvent> chatEvent = boost::dynamic_pointer_cast<RequestChatUIEvent>(event);
if (chatEvent) {
@@ -150,8 +161,10 @@ void ChatsManager::handleJoinMUCRequest(const JID &muc, const String &nick) {
if (it != mucControllers_.end()) {
//FIXME: What's correct behaviour here?
} else {
- mucControllers_[muc] = new MUCController(jid_, muc, nick, stanzaChannel_, presenceSender_, iqRouter_, chatWindowFactory_, treeWidgetFactory_, presenceOracle_, avatarManager_);
- mucControllers_[muc]->setAvailableServerFeatures(serverDiscoInfo_);
+ MUCController* controller = new MUCController(jid_, muc, nick, stanzaChannel_, presenceSender_, iqRouter_, chatWindowFactory_, treeWidgetFactory_, presenceOracle_, avatarManager_);
+ mucControllers_[muc] = controller;
+ controller->setAvailableServerFeatures(serverDiscoInfo_);
+ controller->onUserLeft.connect(boost::bind(&ChatsManager::handleUserLeftMUC, this, controller));
}
mucControllers_[muc]->activateChatWindow();
}
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index bef766b..a1614f8 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -41,6 +41,7 @@ namespace Swift {
void handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> lastPresence);
void handleUIEvent(boost::shared_ptr<UIEvent> event);
void handleMUCBookmarksChanged();
+ void handleUserLeftMUC(MUCController* mucController);
ChatController* getChatController(const JID &contact);
virtual bool isMUC(const JID& muc) const;
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 7736aec..0ec8c28 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -33,6 +33,7 @@ MUCController::MUCController (
muc_(new MUC(stanzaChannel, presenceSender, muc)),
nick_(nick),
treeWidgetFactory_(treeWidgetFactory) {
+ parting_ = false;
roster_ = new Roster(chatWindow_->getTreeWidget(), treeWidgetFactory_);
chatWindow_->onClosed.connect(boost::bind(&MUCController::handleWindowClosed, this));
muc_->joinAs(nick);
@@ -42,7 +43,7 @@ MUCController::MUCController (
chatWindow_->convertToMUC();
chatWindow_->show();
if (avatarManager_ != NULL) {
- avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1, _2));
+ avatarChangedConnection_ = (avatarManager_->onAvatarChanged.connect(boost::bind(&MUCController::handleAvatarChanged, this, _1, _2)));
}
}
@@ -52,12 +53,17 @@ MUCController::~MUCController() {
}
void MUCController::handleAvatarChanged(const JID& jid, const String&) {
+ if (parting_) {
+ return;
+ }
String path = avatarManager_->getAvatarPath(jid).string();
roster_->applyOnItems(SetAvatar(jid, path, JID::WithResource));
}
void MUCController::handleWindowClosed() {
+ parting_ = true;
muc_->part();
+ onUserLeft();
}
void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {
diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h
index bafe3db..aae2150 100644
--- a/Swift/Controllers/Chat/MUCController.h
+++ b/Swift/Controllers/Chat/MUCController.h
@@ -2,6 +2,8 @@
#define SWIFTEN_MUCController_H
#include <boost/shared_ptr.hpp>
+#include <boost/signals.hpp>
+#include <boost/signals/connection.hpp>
#include "Swiften/Base/String.h"
#include "Swift/Controllers/Chat/ChatControllerBase.h"
@@ -24,6 +26,7 @@ namespace Swift {
public:
MUCController(const JID& self, const JID &muc, const String &nick, StanzaChannel* stanzaChannel, PresenceSender* presenceSender, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, TreeWidgetFactory *treeWidgetFactory, PresenceOracle* presenceOracle, AvatarManager* avatarManager);
~MUCController();
+ boost::signal<void ()> onUserLeft;
protected:
void preSendMessageRequest(boost::shared_ptr<Message> message);
@@ -42,6 +45,8 @@ namespace Swift {
String nick_;
TreeWidgetFactory *treeWidgetFactory_;
Roster *roster_;
+ bool parting_;
+ boost::bsignals::scoped_connection avatarChangedConnection_;
};
}
#endif