summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-07-22 10:00:15 (GMT)
committerSwift Review <review@swift.im>2014-07-28 10:37:27 (GMT)
commitcc379dcf8aeba3c7f259b7e40c9ea2d7a137aa7a (patch)
tree2ca9904e9ac300f97b8046170a4d8cad42e0fab1 /Swift/Controllers
parentdeddde461018ec2b47d1b3e3776550cdd3ea714d (diff)
downloadswift-cc379dcf8aeba3c7f259b7e40c9ea2d7a137aa7a.zip
swift-cc379dcf8aeba3c7f259b7e40c9ea2d7a137aa7a.tar.bz2
Fix displaying blocked user warning with bound JID chats. Support multiple alert messages.
Test-Information: Block a user while the JID is unbound and verify that the yellow warning bar is displayed. Send bidirectional messages to bind the JID then repeat the block request and confirm that the yellow warning bar is displayed and that the user is indeed blocked. Open several alert messages, check that each one can be individually closed via cancelAlert. Change-Id: I120e393c028d15fd5f92154b44a8817cbc41edc9
Diffstat (limited to 'Swift/Controllers')
-rw-r--r--Swift/Controllers/Chat/ChatController.cpp37
-rw-r--r--Swift/Controllers/Chat/ChatController.h6
-rw-r--r--Swift/Controllers/UIInterfaces/ChatWindow.h11
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.h4
4 files changed, 28 insertions, 30 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 9b65c9f..786b4e9 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -169,8 +169,8 @@ void ChatController::setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> inf
boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
- blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&ChatController::handleBlockingItemAdded, this, _1));
- blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&ChatController::handleBlockingItemRemoved, this, _1));
+ blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
+ blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&ChatController::handleBlockingStateChanged, this));
handleBlockingStateChanged();
}
@@ -248,11 +248,14 @@ void ChatController::handleSettingChanged(const std::string& settingPath) {
void ChatController::checkForDisplayingDisplayReceiptsAlert() {
if (userWantsReceipts_ && (contactSupportsReceipts_ == ChatWindow::No)) {
- chatWindow_->setAlert(QT_TRANSLATE_NOOP("", "This chat doesn't support delivery receipts."));
+ deliveryReceiptAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat doesn't support delivery receipts."));
} else if (userWantsReceipts_ && (contactSupportsReceipts_ == ChatWindow::Maybe)) {
- chatWindow_->setAlert(QT_TRANSLATE_NOOP("", "This chat may not support delivery receipts. You might not receive delivery receipts for the messages you sent."));
+ deliveryReceiptAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "This chat may not support delivery receipts. You might not receive delivery receipts for the messages you sent."));
} else {
- chatWindow_->cancelAlert();
+ if (deliveryReceiptAlert_) {
+ chatWindow_->removeAlert(*deliveryReceiptAlert_);
+ deliveryReceiptAlert_.reset();
+ }
}
}
@@ -260,32 +263,20 @@ void ChatController::handleBlockingStateChanged() {
boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList();
if (blockList->getState() == BlockList::Available) {
if (isInMUC_ ? blockList->isBlocked(toJID_) : blockList->isBlocked(toJID_.toBare())) {
- chatWindow_->setAlert(QT_TRANSLATE_NOOP("", "You've currently blocked this contact. To continue your conversation you have to unblock the contact first."));
+ blockedContactAlert_ = chatWindow_->addAlert(QT_TRANSLATE_NOOP("", "You've currently blocked this contact. To continue your conversation you have to unblock the contact first."));
chatWindow_->setInputEnabled(false);
chatWindow_->setBlockingState(ChatWindow::IsBlocked);
} else {
+ if (blockedContactAlert_) {
+ chatWindow_->removeAlert(*blockedContactAlert_);
+ blockedContactAlert_.reset();
+ }
+ chatWindow_->setInputEnabled(true);
chatWindow_->setBlockingState(ChatWindow::IsUnblocked);
}
}
}
-void ChatController::handleBlockingItemAdded(const JID& jid) {
- if (toJID_ == (isInMUC_ ? jid: jid.toBare())) {
- chatWindow_->setAlert(QT_TRANSLATE_NOOP("", "You've currently blocked this contact. To continue your conversation you have to unblock the contact first."));
- chatWindow_->setInputEnabled(false);
- chatWindow_->setBlockingState(ChatWindow::IsBlocked);
- }
-}
-
-void ChatController::handleBlockingItemRemoved(const JID& jid) {
- if (toJID_ == (isInMUC_ ? jid: jid.toBare())) {
- // FIXME: Support for different types of alerts.
- chatWindow_->cancelAlert();
- chatWindow_->setInputEnabled(true);
- chatWindow_->setBlockingState(ChatWindow::IsUnblocked);
- }
-}
-
void ChatController::handleBlockUserRequest() {
if (isInMUC_) {
eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, toJID_));
diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h
index 2e92be7..998b437 100644
--- a/Swift/Controllers/Chat/ChatController.h
+++ b/Swift/Controllers/Chat/ChatController.h
@@ -72,9 +72,6 @@ namespace Swift {
void checkForDisplayingDisplayReceiptsAlert();
void handleBlockingStateChanged();
- void handleBlockingItemAdded(const JID&);
- void handleBlockingItemRemoved(const JID&);
-
void handleBlockUserRequest();
void handleUnblockUserRequest();
@@ -108,6 +105,9 @@ namespace Swift {
boost::bsignals::scoped_connection blockingOnStateChangedConnection_;
boost::bsignals::scoped_connection blockingOnItemAddedConnection_;
boost::bsignals::scoped_connection blockingOnItemRemovedConnection_;
+
+ boost::optional<ChatWindow::AlertID> deliveryReceiptAlert_;
+ boost::optional<ChatWindow::AlertID> blockedContactAlert_;
};
}
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
index 81d26c8..f2f5f76 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -153,16 +153,23 @@ namespace Swift {
virtual void setBlockingState(BlockingState state) = 0;
virtual void setCanInitiateImpromptuChats(bool supportsImpromptu) = 0;
virtual void showBookmarkWindow(const MUCBookmark& bookmark) = 0;
+
+ /**
+ * A handle that uniquely identities an alert message.
+ */
+ typedef int AlertID;
/**
* Set an alert on the window.
* @param alertText Description of alert (required).
* @param buttonText Button text to use (optional, no button is shown if empty).
+ * @return A handle to the alert message.
*/
- virtual void setAlert(const std::string& alertText, const std::string& buttonText = "") = 0;
+ virtual AlertID addAlert(const std::string& alertText, const std::string& buttonText = "") = 0;
/**
* Removes an alert.
+ * @param id An alert ID previously returned from setAlert
*/
- virtual void cancelAlert() = 0;
+ virtual void removeAlert(const AlertID id) = 0;
/**
* Actions that can be performed on the selected occupant.
diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h
index 5e6606b..ef7216b 100644
--- a/Swift/Controllers/UnitTest/MockChatWindow.h
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -56,8 +56,8 @@ namespace Swift {
void setAckState(const std::string& /*id*/, AckState /*state*/) {}
virtual void flash() {}
- virtual void setAlert(const std::string& /*alertText*/, const std::string& /*buttonText*/) {}
- virtual void cancelAlert() {}
+ virtual AlertID addAlert(const std::string& /*alertText*/, const std::string& /*buttonText*/) { return 0; }
+ virtual void removeAlert(const AlertID /*id*/) {}
virtual void setCorrectionEnabled(Tristate /*enabled*/) {}
virtual void setFileTransferEnabled(Tristate /*enabled*/) {}
void setAvailableOccupantActions(const std::vector<OccupantAction>&/* actions*/) {}