summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Burgess <pete.burgess@isode.com>2018-05-02 17:09:44 (GMT)
committerKevin Smith <kevin.smith@isode.com>2018-05-09 12:56:55 (GMT)
commit1fef8025841bd86eed4677eeb88ef4a2a2eda398 (patch)
treee7915d37aada64f38a589377da66ae5801c56b6a
parenta64be9c7bf9f9a69881e8fc66069363e6af4de26 (diff)
downloadswift-1fef8025841bd86eed4677eeb88ef4a2a2eda398.zip
swift-1fef8025841bd86eed4677eeb88ef4a2a2eda398.tar.bz2
Add timer for QtChatWindow focus to stop messages appearing unread
When a QtChatWindow's text input receives focus, it initiates a one second timer. When it times out, the QtChatWindow checks whether the QtChatWindow in general has focus. If so, it will reset the unread count to 0. If it doesn't still have focus, it will not alter the message count and the chat will still show as having unread messages. Test-Information: This is in the Qt user interface, so no unit tests have been written. Tested thoroughly on a test server on ubuntu 17.10. Tested what happens when the chat window is changed via both a click on the roster (both old and new) and a click on the tabs. All three scenarios produce the desired results when both keeping focus for the full second, or when losing focus before the second is up. Change-Id: Idfa66990545051cfe6c9853418b2138ee0f1f57c
-rw-r--r--Swift/QtUI/QtChatWindow.cpp19
-rw-r--r--Swift/QtUI/QtChatWindow.h3
2 files changed, 21 insertions, 1 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 1f8e7a7..e0881d5 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -719,7 +719,17 @@ void QtChatWindow::handleEmojiClicked(QString emoji) {
void QtChatWindow::handleTextInputReceivedFocus() {
lastLineTracker_.setHasFocus(true);
input_->setFocus();
- onAllMessagesRead();
+ if (focusTimer_) {
+ focusTimer_->stop();
+ }
+ else {
+ focusTimer_ = std::make_unique<QTimer>(this);
+ focusTimer_->setSingleShot(true);
+ focusTimer_->setTimerType(Qt::CoarseTimer);
+ connect(focusTimer_.get(), &QTimer::timeout, this, &QtChatWindow::handleFocusTimerTick);
+ }
+ focusTimer_->setInterval(1000);
+ focusTimer_->start();
}
void QtChatWindow::handleTextInputLostFocus() {
@@ -1029,4 +1039,11 @@ void QtChatWindow::removeChatSecurityMarking() {
securityMarkingLayout_ = nullptr;
}
+void QtChatWindow::handleFocusTimerTick() {
+ if (hasFocus()) {
+ onAllMessagesRead();
+ }
+ focusTimer_.reset();
+}
+
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 4e10053..1269165 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -34,6 +34,7 @@ class QComboBox;
class QLabel;
class QSplitter;
class QPushButton;
+class QTimer;
namespace Swift {
class QtChatView;
@@ -196,6 +197,7 @@ namespace Swift {
void setChatSecurityMarking(const std::string& markingValue, const std::string& markingForegroundColorValue, const std::string& markingBackgroundColorValue);
void removeChatSecurityMarking();
+ void handleFocusTimerTick();
private:
int unreadCount_;
@@ -246,5 +248,6 @@ namespace Swift {
QTimer* dayChangeTimer = nullptr;
QHBoxLayout* securityMarkingLayout_ = nullptr;
QLabel* securityMarkingDisplay_ = nullptr;
+ std::unique_ptr<QTimer> focusTimer_;
};
}