diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index c703d95f..1b235a95 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -141,9 +141,6 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
text_input_ = new TextInputWidget(this);
contentLayout_->addWidget(text_input_);
- typingRefresher_ = new QTimer(this);
- typingRefresher_->setInterval(TYPING_REFRESH_TIMEOUT);
-
connect(this, &ChatPage::connectionLost, this, [this]() {
nhlog::net()->info("connectivity lost");
isConnected_ = false;
@@ -221,9 +218,7 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
connect(room_list_, &RoomList::roomChanged, this, [this](QString room_id) {
this->current_room_ = room_id;
});
- connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::stopTyping);
connect(room_list_, &RoomList::roomChanged, splitter, &Splitter::showChatView);
- connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::focusLineEdit);
connect(
room_list_, &RoomList::roomChanged, view_manager_, &TimelineViewManager::setHistoryView);
@@ -237,27 +232,6 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
room_list_->removeRoom(room_id, currentRoom() == room_id);
});
- connect(
- text_input_, &TextInputWidget::startedTyping, this, &ChatPage::sendTypingNotifications);
- connect(typingRefresher_, &QTimer::timeout, this, &ChatPage::sendTypingNotifications);
- connect(text_input_, &TextInputWidget::stoppedTyping, this, [this]() {
- if (!userSettings_->typingNotifications())
- return;
-
- typingRefresher_->stop();
-
- if (current_room_.isEmpty())
- return;
-
- http::client()->stop_typing(
- current_room_.toStdString(), [](mtx::http::RequestErr err) {
- if (err) {
- nhlog::net()->warn("failed to stop typing notifications: {}",
- err->matrix_error.error);
- }
- });
- });
-
connect(view_manager_,
&TimelineViewManager::updateRoomsLastMessage,
room_list_,
@@ -436,12 +410,6 @@ ChatPage::resetUI()
}
void
-ChatPage::focusMessageInput()
-{
- this->text_input_->focusLineEdit();
-}
-
-void
ChatPage::deleteConfigs()
{
QSettings settings;
@@ -1099,21 +1067,6 @@ ChatPage::receivedSessionKey(const std::string &room_id, const std::string &sess
view_manager_->receivedSessionKey(room_id, session_id);
}
-void
-ChatPage::sendTypingNotifications()
-{
- if (!userSettings_->typingNotifications())
- return;
-
- http::client()->start_typing(
- current_room_.toStdString(), 10'000, [](mtx::http::RequestErr err) {
- if (err) {
- nhlog::net()->warn("failed to send typing notification: {}",
- err->matrix_error.error);
- }
- });
-}
-
QString
ChatPage::status() const
{
diff --git a/src/ChatPage.h b/src/ChatPage.h
index 7eb37f04..37abafa0 100644
--- a/src/ChatPage.h
+++ b/src/ChatPage.h
@@ -100,7 +100,6 @@ public:
//! Show the room/group list (if it was visible).
void showSideBars();
void initiateLogout();
- void focusMessageInput();
QString status() const;
void setStatus(const QString &status);
@@ -191,7 +190,6 @@ private slots:
void removeRoom(const QString &room_id);
void dropToLoginPage(const QString &msg);
- void sendTypingNotifications();
void handleSyncResponse(const mtx::responses::Sync &res);
private:
@@ -265,8 +263,6 @@ private:
popups::UserMentions *user_mentions_popup_;
- QTimer *typingRefresher_;
-
// Global user settings.
QSharedPointer<UserSettings> userSettings_;
diff --git a/src/TextInputWidget.cpp b/src/TextInputWidget.cpp
index 92449231..30589b61 100644
--- a/src/TextInputWidget.cpp
+++ b/src/TextInputWidget.cpp
@@ -83,12 +83,6 @@ FilteredTextEdit::FilteredTextEdit(QWidget *parent)
insertCompletion(emoji);
});
- typingTimer_ = new QTimer(this);
- typingTimer_->setInterval(1000);
- typingTimer_->setSingleShot(true);
-
- connect(typingTimer_, &QTimer::timeout, this, &FilteredTextEdit::stopTyping);
-
connect(this, &FilteredTextEdit::resultsRetrieved, this, &FilteredTextEdit::showResults);
connect(
&suggestionsPopup_, &SuggestionsPopup::itemSelected, this, [this](const QString &text) {
@@ -164,13 +158,6 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event)
if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_U)
QTextEdit::setText("");
- if (!isModifier) {
- if (!typingTimer_->isActive())
- emit startedTyping();
-
- typingTimer_->start();
- }
-
// calculate the new query
if (textCursor().position() < atTriggerPosition_ || !isAnchorValid()) {
resetAnchor();
@@ -264,7 +251,6 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event)
}
if (!(event->modifiers() & Qt::ShiftModifier)) {
- stopTyping();
submit();
} else {
QTextEdit::keyPressEvent(event);
@@ -351,13 +337,6 @@ FilteredTextEdit::keyPressEvent(QKeyEvent *event)
}
}
-void
-FilteredTextEdit::stopTyping()
-{
- typingTimer_->stop();
- emit stoppedTyping();
-}
-
QRect
FilteredTextEdit::completerRect()
{
@@ -494,15 +473,6 @@ TextInputWidget::TextInputWidget(QWidget *parent)
connect(sendMessageBtn_, &FlatButton::clicked, input_, &FilteredTextEdit::submit);
connect(sendFileBtn_, SIGNAL(clicked()), this, SLOT(openFileSelection()));
- connect(input_, &FilteredTextEdit::startedTyping, this, &TextInputWidget::startedTyping);
-
- connect(input_, &FilteredTextEdit::stoppedTyping, this, &TextInputWidget::stoppedTyping);
-}
-
-void
-TextInputWidget::stopTyping()
-{
- input_->stopTyping();
}
void
diff --git a/src/TextInputWidget.h b/src/TextInputWidget.h
index afd29439..c62a98be 100644
--- a/src/TextInputWidget.h
+++ b/src/TextInputWidget.h
@@ -43,8 +43,6 @@ class FilteredTextEdit : public QTextEdit
public:
explicit FilteredTextEdit(QWidget *parent = nullptr);
- void stopTyping();
-
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
@@ -52,8 +50,6 @@ public:
signals:
void heightChanged(int height);
- void startedTyping();
- void stoppedTyping();
void startedUpload();
//! Trigger the suggestion popup.
@@ -81,7 +77,6 @@ private:
int trigger_pos_; // Where emoji completer was triggered
size_t history_index_;
QCompleter *completer_;
- QTimer *typingTimer_;
SuggestionsPopup suggestionsPopup_;
@@ -136,8 +131,6 @@ class TextInputWidget : public QWidget
public:
TextInputWidget(QWidget *parent = nullptr);
- void stopTyping();
-
QColor borderColor() const { return borderColor_; }
void setBorderColor(QColor &color) { borderColor_ = color; }
void disableInput()
@@ -164,9 +157,6 @@ signals:
void sendUnbanRoomRequest(const QString &userid, const QString &reason);
void changeRoomNick(const QString &displayname);
- void startedTyping();
- void stoppedTyping();
-
protected:
void focusInEvent(QFocusEvent *event) override;
void paintEvent(QPaintEvent *) override;
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
|