summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/MUC')
-rw-r--r--Swiften/MUC/MUCBookmark.h71
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp25
-rw-r--r--Swiften/MUC/MUCBookmarkManager.h2
3 files changed, 75 insertions, 23 deletions
diff --git a/Swiften/MUC/MUCBookmark.h b/Swiften/MUC/MUCBookmark.h
index 7afbe76..c6c22bf 100644
--- a/Swiften/MUC/MUCBookmark.h
+++ b/Swiften/MUC/MUCBookmark.h
@@ -10,21 +10,70 @@
#include "Swiften/Base/String.h"
#include "Swiften/JID/JID.h"
+#include "Swiften/Elements/Storage.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_;};
-
- bool operator==(const MUCBookmark& rhs) const {return rhs.room_ == room_ && rhs.name_ == name_ && rhs.nick_ == nick_ && rhs.password_ == password_ && rhs.autojoin_ == autojoin_;};
+ MUCBookmark(const Storage::Room& room) {
+ name_ = room.name;
+ room_ = room.jid;
+ nick_ = room.nick;
+ password_ = room.password;
+ }
+
+ MUCBookmark(const JID& room, const String& bookmarkName) : room_(room), name_(bookmarkName) {
+ }
+
+ void setAutojoin(bool enabled) {
+ autojoin_ = enabled;
+ }
+
+ bool getAutojoin() const {
+ return autojoin_;
+ }
+
+ void setNick(const boost::optional<String>& nick) {
+ nick_ = nick;
+ }
+
+ void setPassword(const boost::optional<String>& password) {
+ password_ = password;
+ }
+
+ 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_;
+ }
+
+ bool operator==(const MUCBookmark& rhs) const {
+ return rhs.room_ == room_ && rhs.name_ == name_ && rhs.nick_ == nick_ && rhs.password_ == password_ && rhs.autojoin_ == autojoin_;
+ }
+
+ Storage::Room toStorage() const {
+ Storage::Room room;
+ room.name = name_;
+ room.jid = room_;
+ if (nick_) {
+ room.nick = *nick_;
+ }
+ if (password_) {
+ room.password = *password_;
+ }
+ return room;
+ }
+
private:
JID room_;
String name_;
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index 3675635..cc1c8d6 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -10,6 +10,8 @@
#include <iostream>
#include "Swiften/Queries/IQRouter.h"
+#include "Swiften/Queries/Requests/GetPrivateStorageRequest.h"
+#include "Swiften/Queries/Requests/SetPrivateStorageRequest.h"
namespace Swift {
@@ -29,16 +31,7 @@ void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payl
std::vector<MUCBookmark> receivedBookmarks;
foreach (Storage::Room room, payload->getRooms()) {
- String name = (!room.name.isEmpty()) ? room.name : room.jid.getNode();
- MUCBookmark bookmark(room.jid, name);
- bookmark.setAutojoin(room.autoJoin);
- if (!room.nick.isEmpty()) {
- bookmark.setNick(room.nick);
- }
- if (!room.password.isEmpty()) {
- bookmark.setPassword(room.password);
- }
- receivedBookmarks.push_back(bookmark);
+ receivedBookmarks.push_back(MUCBookmark(room));
}
std::vector<MUCBookmark> newBookmarks;
@@ -95,7 +88,17 @@ void MUCBookmarkManager::removeBookmark(const MUCBookmark& bookmark) {
}
void MUCBookmarkManager::flush() {
- //FIXME: some code may be useful
+ // Update the storage element
+ storage->clearRooms();
+ foreach(const MUCBookmark& bookmark, bookmarks_) {
+ storage->addRoom(bookmark.toStorage());
+ }
+
+ // Send an iq to save the storage element
+ boost::shared_ptr<SetPrivateStorageRequest<Storage> > request(new SetPrivateStorageRequest<Storage>(storage, iqRouter_));
+ // FIXME: We should care about the result
+ //request->onResponse.connect(boost::bind(&MUCBookmarkManager::handleBookmarksSet, this, _1, _2));
+ request->send();
}
const std::vector<MUCBookmark>& MUCBookmarkManager::getBookmarks() const {
diff --git a/Swiften/MUC/MUCBookmarkManager.h b/Swiften/MUC/MUCBookmarkManager.h
index 594a805..136c76f 100644
--- a/Swiften/MUC/MUCBookmarkManager.h
+++ b/Swiften/MUC/MUCBookmarkManager.h
@@ -14,7 +14,7 @@
#include "Swiften/MUC/MUCBookmark.h"
#include "Swiften/Elements/Storage.h"
-#include "Swiften/Queries/Requests/GetPrivateStorageRequest.h"
+#include "Swiften/Elements/ErrorPayload.h"
namespace Swift {
class IQRouter;