summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp14
-rw-r--r--Swift/Controllers/Chat/ChatsManager.h3
-rw-r--r--Swiften/MUC/MUCBookmark.h28
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp37
-rw-r--r--Swiften/MUC/MUCBookmarkManager.h27
-rw-r--r--Swiften/SConscript1
6 files changed, 110 insertions, 0 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index 250f02d..ac03f8a 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -10,6 +10,7 @@
#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"
#include "Swiften/Presence/PresenceSender.h"
#include "Swiften/Elements/ChatState.h"
+#include "Swiften/MUC/MUCBookmarkManager.h"
namespace Swift {
@@ -28,6 +29,8 @@ ChatsManager::ChatsManager(JID jid, StanzaChannel* stanzaChannel, IQRouter* iqRo
serverDiscoInfo_ = serverDiscoInfo;
presenceSender_ = presenceSender;
uiEventStream_ = uiEventStream;
+ mucBookmarkManager_ = new MUCBookmarkManager(iqRouter);
+ mucBookmarkManager_->onBookmarksChanged.connect(boost::bind(&ChatsManager::handleMUCBookmarksChanged, this));
presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1, _2));
uiEventStream_->onUIEvent.connect(boost::bind(&ChatsManager::handleUIEvent, this, _1));
}
@@ -39,7 +42,18 @@ ChatsManager::~ChatsManager() {
foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
delete controllerPair.second;
}
+ delete mucBookmarkManager_;
+}
+void ChatsManager::handleMUCBookmarksChanged() {
+ foreach (boost::shared_ptr<MUCBookmark> bookmark, mucBookmarkManager_->getBookmarks()) {
+ std::map<JID, MUCController*>::iterator it = mucControllers_.find(bookmark->getRoom());
+ if (it == mucControllers_.end()) {
+ //FIXME: need vcard stuff here to get a nick
+ String nick = bookmark->getNick() ? bookmark->getNick().get() : "Swift user";
+ handleJoinMUCRequest(bookmark->getRoom(), nick);
+ }
+ }
}
void ChatsManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h
index 04d9330..bef766b 100644
--- a/Swift/Controllers/Chat/ChatsManager.h
+++ b/Swift/Controllers/Chat/ChatsManager.h
@@ -24,6 +24,7 @@ namespace Swift {
class StanzaChannel;
class IQRouter;
class PresenceSender;
+ class MUCBookmarkManager;
class ChatsManager : public MUCRegistry {
public:
@@ -39,6 +40,7 @@ namespace Swift {
void rebindControllerJID(const JID& from, const JID& to);
void handlePresenceChange(boost::shared_ptr<Presence> newPresence, boost::shared_ptr<Presence> lastPresence);
void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ void handleMUCBookmarksChanged();
ChatController* getChatController(const JID &contact);
virtual bool isMUC(const JID& muc) const;
@@ -55,6 +57,7 @@ namespace Swift {
AvatarManager* avatarManager_;
PresenceSender* presenceSender_;
UIEventStream* uiEventStream_;
+ MUCBookmarkManager* mucBookmarkManager_;
boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
};
}
diff --git a/Swiften/MUC/MUCBookmark.h b/Swiften/MUC/MUCBookmark.h
new file mode 100644
index 0000000..439e716
--- /dev/null
+++ b/Swiften/MUC/MUCBookmark.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <boost/optional.hpp>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/JID/JID.h"
+
+namespace Swift {
+ class MUCBookmark {
+ public:
+ MUCBookmark(const JID& room, const String& bookmarkName) : room_(room), name_(bookmarkName){};
+ void setAutojoin(bool enabled) {autojoin_ = enabled;};
+ void setNick(const boost::optional<String>& nick) {nick_ = nick;};
+ void setPassword(const boost::optional<String>& password) {password_ = password;};
+ bool getAutojoin() const {return autojoin_;};
+ const boost::optional<String>& getNick() const {return nick_;};
+ const boost::optional<String>& getPassword() const {return password_;};
+ const String& getName() const {return name_;};
+ const JID& getRoom() const {return room_;};
+ private:
+ JID room_;
+ String name_;
+ boost::optional<String> nick_;
+ boost::optional<String> password_;
+ bool autojoin_;
+ };
+}
+
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
new file mode 100644
index 0000000..f789300
--- /dev/null
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -0,0 +1,37 @@
+#include "MUCBookmarkManager.h"
+
+#include "Swiften/Queries/IQRouter.h"
+
+namespace Swift {
+
+MUCBookmarkManager::MUCBookmarkManager(IQRouter* iqRouter) {
+ iqRouter_ = iqRouter;
+}
+
+void MUCBookmarkManager::addBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
+ bookmarks_.push_back(bookmark);
+ flush();
+}
+
+
+void MUCBookmarkManager::removeBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
+ std::vector<boost::shared_ptr<MUCBookmark> >::iterator it;
+ for (it = bookmarks_.begin(); it != bookmarks_.end(); it++) {
+ if ((*it).get() == bookmark.get()) {
+ bookmarks_.erase(it);
+ return;
+ }
+ }
+ assert(false);
+ flush();
+}
+
+void MUCBookmarkManager::flush() {
+ //FIXME: some code may be useful
+}
+
+const std::vector<boost::shared_ptr<MUCBookmark> >& MUCBookmarkManager::getBookmarks() {
+ return bookmarks_;
+}
+
+}
diff --git a/Swiften/MUC/MUCBookmarkManager.h b/Swiften/MUC/MUCBookmarkManager.h
new file mode 100644
index 0000000..e1f8708
--- /dev/null
+++ b/Swiften/MUC/MUCBookmarkManager.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <vector>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/signals.hpp>
+
+#include "Swiften/MUC/MUCBookmark.h"
+
+namespace Swift {
+ class IQRouter;
+ class MUCBookmarkManager {
+ public:
+ MUCBookmarkManager(IQRouter* iqRouter);
+ void addBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ void removeBookmark(boost::shared_ptr<MUCBookmark> bookmark);
+ /** Call flush after editing an existing bookmark. */
+ void flush();
+ /** Returns pointers to the bookmarks. These can be edited, and then flush()ed.*/
+ const std::vector<boost::shared_ptr<MUCBookmark> >& getBookmarks();
+ boost::signal<void ()> onBookmarksChanged;
+ private:
+
+ std::vector<boost::shared_ptr<MUCBookmark> > bookmarks_;
+ IQRouter* iqRouter_;
+ };
+}
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 3f82bfe..e7a3329 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -33,6 +33,7 @@ sources = [
"MUC/MUC.cpp",
"MUC/MUCOccupant.cpp",
"MUC/MUCRegistry.cpp",
+ "MUC/MUCBookmarkManager.cpp",
"Notifier/Notifier.cpp",
"Presence/PresenceOracle.cpp",
"Presence/PresenceSender.cpp",