Send typing updates from QML

This commit is contained in:
Nicolas Werner 2020-11-17 02:37:43 +01:00
parent 82c441dddd
commit 921379a4cc
7 changed files with 56 additions and 93 deletions

View file

@ -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_,
@ -435,12 +409,6 @@ ChatPage::resetUI()
emit unreadMessages(0);
}
void
ChatPage::focusMessageInput()
{
this->text_input_->focusLineEdit();
}
void
ChatPage::deleteConfigs()
{
@ -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
{