From 921379a4cc3bc6381c4562bfdb9ce0dcde6b1f2c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 17 Nov 2020 02:37:43 +0100 Subject: Send typing updates from QML --- src/timeline/InputBar.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/timeline/InputBar.h | 16 +++++++++++++++- src/timeline/TimelineModel.cpp | 1 - 3 files changed, 56 insertions(+), 2 deletions(-) (limited to 'src/timeline') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index dc287f94..6603287b 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -114,6 +114,11 @@ InputBar::paste(bool fromMouse) void InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, QString text_) { + if (text_.isEmpty()) + stopTyping(); + else + startTyping(); + selectionStart = selectionStart_; selectionEnd = selectionEnd_; cursorPosition = cursorPosition_; @@ -556,3 +561,39 @@ InputBar::callButton() } } } + +void +InputBar::startTyping() +{ + if (!typingRefresh_.isActive()) { + typingRefresh_.start(); + + if (ChatPage::instance()->userSettings()->typingNotifications()) { + http::client()->start_typing( + room->roomId().toStdString(), 10'000, [](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn( + "failed to send typing notification: {}", + err->matrix_error.error); + } + }); + } + } + typingTimeout_.start(); +} +void +InputBar::stopTyping() +{ + typingRefresh_.stop(); + typingTimeout_.stop(); + + if (!ChatPage::instance()->userSettings()->typingNotifications()) + return; + + http::client()->stop_typing(room->roomId().toStdString(), [](mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to stop typing notifications: {}", + err->matrix_error.error); + } + }); +} diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index a52a3904..0e9ef592 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -19,7 +20,14 @@ public: InputBar(TimelineModel *parent) : QObject() , room(parent) - {} + { + typingRefresh_.setInterval(10'000); + typingRefresh_.setSingleShot(true); + typingTimeout_.setInterval(5'000); + typingTimeout_.setSingleShot(true); + connect(&typingRefresh_, &QTimer::timeout, this, &InputBar::startTyping); + connect(&typingTimeout_, &QTimer::timeout, this, &InputBar::stopTyping); + } public slots: void send(); @@ -29,6 +37,10 @@ public slots: bool uploading() const { return uploading_; } void callButton(); +private slots: + void startTyping(); + void stopTyping(); + signals: void insertText(QString text); void uploadingChanged(bool value); @@ -69,6 +81,8 @@ private: } } + QTimer typingRefresh_; + QTimer typingTimeout_; TimelineModel *room; QString text; std::deque history_; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 8b80ea51..4cbd5777 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -800,7 +800,6 @@ void TimelineModel::replyAction(QString id) { setReply(id); - ChatPage::instance()->focusMessageInput(); } RelatedInfo -- cgit 1.5.1