diff options
author | Kevin Smith <git@kismith.co.uk> | 2010-09-12 20:36:48 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2010-09-12 20:36:48 (GMT) |
commit | 0da93507bea788cf6bd8f327478caddf3ea679e5 (patch) | |
tree | 1e0e0609eea3a594b78fdad401282354db640fa6 /Swiften/MUC | |
parent | 536df08ad0646a95ab1352fb9e2b49b00aaaaf2b (diff) | |
download | swift-contrib-0da93507bea788cf6bd8f327478caddf3ea679e5.zip swift-contrib-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')
-rw-r--r-- | Swiften/MUC/MUCBookmarkManager.cpp | 8 | ||||
-rw-r--r-- | Swiften/MUC/MUCBookmarkManager.h | 5 |
2 files changed, 13 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) { diff --git a/Swiften/MUC/MUCBookmarkManager.h b/Swiften/MUC/MUCBookmarkManager.h index a942595..8067b4b 100644 --- a/Swiften/MUC/MUCBookmarkManager.h +++ b/Swiften/MUC/MUCBookmarkManager.h @@ -32,6 +32,10 @@ namespace Swift { public: boost::signal<void (const MUCBookmark&)> onBookmarkAdded; boost::signal<void (const MUCBookmark&)> onBookmarkRemoved; + /** + * When server bookmarks are ready to be used (request response has been received). + */ + boost::signal<void ()> onBookmarksReady; private: bool containsEquivalent(const std::vector<MUCBookmark>& list, const MUCBookmark& bookmark); @@ -39,6 +43,7 @@ namespace Swift { void flush(); private: + bool ready_; std::vector<MUCBookmark> bookmarks_; IQRouter* iqRouter_; boost::shared_ptr<Storage> storage; |