summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-09-12 20:36:48 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-09-12 20:36:48 (GMT)
commit0da93507bea788cf6bd8f327478caddf3ea679e5 (patch)
tree1e0e0609eea3a594b78fdad401282354db640fa6 /Swiften/MUC/MUCBookmarkManager.cpp
parent536df08ad0646a95ab1352fb9e2b49b00aaaaf2b (diff)
downloadswift-0da93507bea788cf6bd8f327478caddf3ea679e5.zip
swift-0da93507bea788cf6bd8f327478caddf3ea679e5.tar.bz2
Block MUC bookmarks until the server has responded.
Else there could be bookmarks overwritten in an infeasibly unlikely race condition. Resolves: #340
Diffstat (limited to 'Swiften/MUC/MUCBookmarkManager.cpp')
-rw-r--r--Swiften/MUC/MUCBookmarkManager.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp
index 77921e9..64615e4 100644
--- a/Swiften/MUC/MUCBookmarkManager.cpp
+++ b/Swiften/MUC/MUCBookmarkManager.cpp
@@ -18,6 +18,7 @@ namespace Swift {
MUCBookmarkManager::MUCBookmarkManager(IQRouter* iqRouter) {
iqRouter_ = iqRouter;
+ ready_ = false;
boost::shared_ptr<GetPrivateStorageRequest<Storage> > request(new GetPrivateStorageRequest<Storage>(iqRouter_));
request->onResponse.connect(boost::bind(&MUCBookmarkManager::handleBookmarksReceived, this, _1, _2));
request->send();
@@ -27,6 +28,10 @@ void MUCBookmarkManager::handleBookmarksReceived(boost::shared_ptr<Storage> payl
if (error) {
return;
}
+
+ ready_ = true;
+ onBookmarksReady();
+
storage = payload;
std::vector<MUCBookmark> receivedBookmarks;
@@ -57,6 +62,7 @@ bool MUCBookmarkManager::containsEquivalent(const std::vector<MUCBookmark>& list
}
void MUCBookmarkManager::replaceBookmark(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark) {
+ if (!ready_) return;
for (size_t i = 0; i < bookmarks_.size(); i++) {
if (bookmarks_[i] == oldBookmark) {
bookmarks_[i] = newBookmark;
@@ -69,6 +75,7 @@ void MUCBookmarkManager::replaceBookmark(const MUCBookmark& oldBookmark, const M
}
void MUCBookmarkManager::addBookmark(const MUCBookmark& bookmark) {
+ if (!ready_) return;
bookmarks_.push_back(bookmark);
onBookmarkAdded(bookmark);
flush();
@@ -76,6 +83,7 @@ void MUCBookmarkManager::addBookmark(const MUCBookmark& bookmark) {
void MUCBookmarkManager::removeBookmark(const MUCBookmark& bookmark) {
+ if (!ready_) return;
std::vector<MUCBookmark>::iterator it;
for (it = bookmarks_.begin(); it != bookmarks_.end(); it++) {
if ((*it) == bookmark) {