summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Doukoudakis <thanos.doukoudakis@isode.com>2018-05-17 16:36:44 (GMT)
committerKevin Smith <kevin.smith@isode.com>2018-06-21 12:45:20 (GMT)
commit2bb40b14d3d7f5cebc56601dad066d5201040bd2 (patch)
tree5f208aa9a3b88c8fe0725aca1bd5d97451d45e2f /Swiften/MUC/MUCBookmarkManager.cpp
parent83434963a7b10b759ffe3fdc1312efdef282a450 (diff)
downloadswift-2bb40b14d3d7f5cebc56601dad066d5201040bd2.zip
swift-2bb40b14d3d7f5cebc56601dad066d5201040bd2.tar.bz2
Add a leave room option in MUC rooms
This patch will add a leave room option in the cog menu of a MUC room, allowing the user to leave the room and close the window. Additionally when joining or leaving a room the autojoin field will change to true or false respectively. This patch also fixes a minor issue with a gui option that was not identifying bookmarked rooms at the cog menu. The autojoin option on the Enter room, Bookmark room and Edit Bookmark menu has been removed, since the default behaviour will be to automatically bookmark every MUC room the user joins, setting autojoin to true. If the user chooses to leave the room, then the autojoin flag will be set to false and the bookmark will be updated. Test-Information: Tested the changes in the UI in Windows Qt 5.9. Updated the ChatsManagerTests unit tests to check the chattables and the behaviour of the bookmarks, when joining and leaving MUCs. Change-Id: Iad1f34480a1e0b9df25c73b49247acc7b7825e20
Diffstat (limited to 'Swiften/MUC/MUCBookmarkManager.cpp')
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index 9f8ae77..e394217 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -6,6 +6,7 @@
#include <Swiften/MUC/MUCBookmarkManager.h>
+#include <algorithm>
#include <memory>
#include <boost/bind.hpp>
@@ -30,6 +31,7 @@ void MUCBookmarkManager::handleBookmarksReceived(std::shared_ptr<Storage> payloa
}
ready_ = true;
+ handlingReceivedBookmarks_ = true;
onBookmarksReady();
storage = payload;
@@ -47,18 +49,25 @@ void MUCBookmarkManager::handleBookmarksReceived(std::shared_ptr<Storage> payloa
onBookmarkRemoved(oldBookmark);
}
}
-
+ std::vector<MUCBookmark> newAddedBookmarksToBeSignaled;
for (const auto& newBookmark : receivedBookmarks) {
if (!containsEquivalent(bookmarks_, newBookmark)) {
newBookmarks.push_back(newBookmark);
- onBookmarkAdded(newBookmark);
+ //If the bookmark does not exist in bookmark manager, after emmiting the signal, chatsmanager will try to join the room, if the bookmark has autojoin to true.
+ //The bookmark is not yet available in bookmark manager, therefore a new bookmark will be created which will be lost when newBookmarks replace bookmarks.
+ newAddedBookmarksToBeSignaled.push_back(newBookmark);
}
}
bookmarks_ = newBookmarks;
+ for (auto bookmark : newAddedBookmarksToBeSignaled) {
+ onBookmarkAdded(bookmark);
+ }
+
+ handlingReceivedBookmarks_ = false;
}
bool MUCBookmarkManager::containsEquivalent(const std::vector<MUCBookmark>& list, const MUCBookmark& bookmark) {
- return std::find(list.begin(), list.end(), bookmark) != list.end();
+ return std::find_if(list.begin(), list.end(), [&](const MUCBookmark& val) { return bookmark.getRoom() == val.getRoom(); }) != list.end();
}
void MUCBookmarkManager::replaceBookmark(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark) {
@@ -76,8 +85,15 @@ void MUCBookmarkManager::replaceBookmark(const MUCBookmark& oldBookmark, const M
void MUCBookmarkManager::addBookmark(const MUCBookmark& bookmark) {
if (!ready_) return;
- bookmarks_.push_back(bookmark);
- onBookmarkAdded(bookmark);
+ if (auto found = lookupBookmark(bookmark.getRoom())) {
+ if (found != bookmark) {
+ replaceBookmark(found.get(), bookmark);
+ }
+ }
+ else {
+ bookmarks_.push_back(bookmark);
+ onBookmarkAdded(bookmark);
+ }
flush();
}
@@ -96,6 +112,9 @@ void MUCBookmarkManager::removeBookmark(const MUCBookmark& bookmark) {
}
void MUCBookmarkManager::flush() {
+ if (handlingReceivedBookmarks_) {
+ return;
+ }
if (!storage) {
storage = std::make_shared<Storage>();
}
@@ -116,4 +135,12 @@ const std::vector<MUCBookmark>& MUCBookmarkManager::getBookmarks() const {
return bookmarks_;
}
+boost::optional<MUCBookmark> MUCBookmarkManager::lookupBookmark(const JID& bookmarkJID) const {
+ auto bookmarkIterator = std::find_if(bookmarks_.begin(), bookmarks_.end(), [&](const MUCBookmark& val) { return bookmarkJID == val.getRoom(); });
+ if (bookmarkIterator != bookmarks_.end()) {
+ return *bookmarkIterator;
+ }
+ return boost::none;
+}
+
}