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 <QObject>
+#include <QTimer>
#include <deque>
#include <mtx/common.hpp>
@@ -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<QString> 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
|