summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp36
-rw-r--r--Swiften/MUC/MUCBookmarkManager.h5
2 files changed, 40 insertions, 1 deletions
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index f9295e2..c91612d 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -1,11 +1,47 @@
#include "MUCBookmarkManager.h"
+#include <boost/bind.hpp>
+
#include "Swiften/Queries/IQRouter.h"
+
namespace Swift {
MUCBookmarkManager::MUCBookmarkManager(IQRouter* iqRouter) {
iqRouter_ = iqRouter;
+ boost::shared_ptr<GetPrivateStorageRequest<Storage> > request(new GetPrivateStorageRequest<Storage>(iqRouter_));
+ request->onResponse.connect(boost::bind(&MUCBookmarkManager::handleBookmarksReceived, this, _1, _2));
+ request->send();
+}
+
+void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payload, const boost::optional<ErrorPayload>& error) {
+ if (error) {
+ return;
+ }
+ std::vector<boost::shared_ptr<MUCBookmark> > newBookmarks;
+ foreach (Storage::Conference conference, payload->getConferences()) {
+ String name = (!conference.name.isEmpty()) ? conference.name : conference.jid.getNode();
+ boost::shared_ptr<MUCBookmark> bookmark(new MUCBookmark(conference.jid, name));
+ bookmark->setAutojoin(conference.autoJoin);
+ if (!conference.nick.isEmpty()) {
+ bookmark->setNick(conference.nick);
+ }
+ if (!conference.password.isEmpty()) {
+ bookmark->setPassword(conference.password);
+ }
+ newBookmarks.push_back(bookmark);
+ }
+
+ //FIXME: This needs to be fixed before we start doing anything supporting updates
+ foreach (boost::shared_ptr<MUCBookmark> oldBookmark, bookmarks_) {
+ onBookmarkRemoved(oldBookmark);
+ }
+
+ foreach (boost::shared_ptr<MUCBookmark> newBookmark, newBookmarks) {
+ onBookmarkAdded(newBookmark);
+ }
+
+
}
void MUCBookmarkManager::addBookmark(boost::shared_ptr<MUCBookmark> bookmark) {
diff --git a/Swiften/MUC/MUCBookmarkManager.h b/Swiften/MUC/MUCBookmarkManager.h
index ade2e3e..a74bb1e 100644
--- a/Swiften/MUC/MUCBookmarkManager.h
+++ b/Swiften/MUC/MUCBookmarkManager.h
@@ -4,8 +4,11 @@
#include <boost/shared_ptr.hpp>
#include <boost/signals.hpp>
+#include <boost/optional.hpp>
#include "Swiften/MUC/MUCBookmark.h"
+#include "Swiften/Elements/Storage.h"
+#include "Swiften/Queries/Requests/GetPrivateStorageRequest.h"
namespace Swift {
class IQRouter;
@@ -21,7 +24,7 @@ namespace Swift {
boost::signal<void (boost::shared_ptr<MUCBookmark>)> onBookmarkAdded;
boost::signal<void (boost::shared_ptr<MUCBookmark>)> onBookmarkRemoved;
private:
-
+ void handleBookmarksReceived(boost::shared_ptr<Storage> payload, const boost::optional<ErrorPayload>& error);
std::vector<boost::shared_ptr<MUCBookmark> > bookmarks_;
IQRouter* iqRouter_;
};