Implemented sending of typing notifications (#105)
This commit is contained in:
parent
91b8427795
commit
287b5aa4c0
6 changed files with 130 additions and 6 deletions
|
|
@ -122,6 +122,9 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||
contentLayout_->addWidget(typingDisplay_);
|
||||
contentLayout_->addWidget(text_input_);
|
||||
|
||||
typingRefresher_ = new QTimer(this);
|
||||
typingRefresher_->setInterval(TYPING_REFRESH_TIMEOUT);
|
||||
|
||||
user_info_widget_ = new UserInfoWidget(sideBarTopWidget_);
|
||||
sideBarTopWidgetLayout_->addWidget(user_info_widget_);
|
||||
|
||||
|
|
@ -139,6 +142,7 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||
|
||||
typingDisplay_->setUsers(users);
|
||||
});
|
||||
connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::stopTyping);
|
||||
|
||||
connect(room_list_, &RoomList::roomChanged, this, &ChatPage::changeTopRoomInfo);
|
||||
connect(room_list_, &RoomList::roomChanged, text_input_, &TextInputWidget::focusLineEdit);
|
||||
|
|
@ -159,6 +163,20 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
|||
room_list_->updateUnreadMessageCount(roomid, count);
|
||||
});
|
||||
|
||||
connect(text_input_, &TextInputWidget::startedTyping, this, [=]() {
|
||||
typingRefresher_->start();
|
||||
client_->sendTypingNotification(current_room_);
|
||||
});
|
||||
|
||||
connect(text_input_, &TextInputWidget::stoppedTyping, this, [=]() {
|
||||
typingRefresher_->stop();
|
||||
client_->removeTypingNotification(current_room_);
|
||||
});
|
||||
|
||||
connect(typingRefresher_, &QTimer::timeout, this, [=]() {
|
||||
client_->sendTypingNotification(current_room_);
|
||||
});
|
||||
|
||||
connect(view_manager_,
|
||||
&TimelineViewManager::updateRoomsLastMessage,
|
||||
room_list_,
|
||||
|
|
@ -600,13 +618,20 @@ ChatPage::updateTypingUsers(const QString &roomid, const QList<QString> &user_id
|
|||
{
|
||||
QStringList users;
|
||||
|
||||
for (const auto uid : user_ids)
|
||||
QSettings settings;
|
||||
QString user_id = settings.value("auth/user_id").toString();
|
||||
|
||||
for (const auto uid : user_ids) {
|
||||
if (uid == user_id)
|
||||
continue;
|
||||
users.append(TimelineViewManager::displayName(uid));
|
||||
}
|
||||
|
||||
users.sort();
|
||||
|
||||
if (current_room_ == roomid)
|
||||
if (current_room_ == roomid) {
|
||||
typingDisplay_->setUsers(users);
|
||||
}
|
||||
|
||||
typingUsers_.insert(roomid, users);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -794,3 +794,53 @@ MatrixClient::leaveRoom(const QString &roomId)
|
|||
emit leftRoom(roomId);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
MatrixClient::sendTypingNotification(const QString &roomid, int timeoutInMillis)
|
||||
{
|
||||
QSettings settings;
|
||||
QString user_id = settings.value("auth/user_id").toString();
|
||||
|
||||
QUrlQuery query;
|
||||
query.addQueryItem("access_token", token_);
|
||||
|
||||
QUrl endpoint(server_);
|
||||
endpoint.setPath(clientApiUrl_ + QString("/rooms/%1/typing/%2").arg(roomid).arg(user_id));
|
||||
|
||||
endpoint.setQuery(query);
|
||||
|
||||
QString msgType("");
|
||||
QJsonObject body;
|
||||
|
||||
body = { { "typing", true }, { "timeout", timeoutInMillis } };
|
||||
|
||||
QNetworkRequest request(QString(endpoint.toEncoded()));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
put(request, QJsonDocument(body).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
||||
void
|
||||
MatrixClient::removeTypingNotification(const QString &roomid)
|
||||
{
|
||||
QSettings settings;
|
||||
QString user_id = settings.value("auth/user_id").toString();
|
||||
|
||||
QUrlQuery query;
|
||||
query.addQueryItem("access_token", token_);
|
||||
|
||||
QUrl endpoint(server_);
|
||||
endpoint.setPath(clientApiUrl_ + QString("/rooms/%1/typing/%2").arg(roomid).arg(user_id));
|
||||
|
||||
endpoint.setQuery(query);
|
||||
|
||||
QString msgType("");
|
||||
QJsonObject body;
|
||||
|
||||
body = { { "typing", false } };
|
||||
|
||||
QNetworkRequest request(QString(endpoint.toEncoded()));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
put(request, QJsonDocument(body).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,15 +29,37 @@ FilteredTextEdit::FilteredTextEdit(QWidget *parent)
|
|||
: QTextEdit(parent)
|
||||
{
|
||||
setAcceptRichText(false);
|
||||
|
||||
typingTimer_ = new QTimer(this);
|
||||
typingTimer_->setInterval(1000);
|
||||
typingTimer_->setSingleShot(true);
|
||||
|
||||
connect(typingTimer_, &QTimer::timeout, this, &FilteredTextEdit::stopTyping);
|
||||
}
|
||||
|
||||
void
|
||||
FilteredTextEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
|
||||
if (!typingTimer_->isActive()) {
|
||||
emit startedTyping();
|
||||
}
|
||||
|
||||
typingTimer_->start();
|
||||
|
||||
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
|
||||
stopTyping();
|
||||
|
||||
emit enterPressed();
|
||||
else
|
||||
} else {
|
||||
QTextEdit::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FilteredTextEdit::stopTyping()
|
||||
{
|
||||
typingTimer_->stop();
|
||||
emit stoppedTyping();
|
||||
}
|
||||
|
||||
TextInputWidget::TextInputWidget(QWidget *parent)
|
||||
|
|
@ -104,6 +126,10 @@ TextInputWidget::TextInputWidget(QWidget *parent)
|
|||
SIGNAL(emojiSelected(const QString &)),
|
||||
this,
|
||||
SLOT(addSelectedEmoji(const QString &)));
|
||||
|
||||
connect(input_, &FilteredTextEdit::startedTyping, this, &TextInputWidget::startedTyping);
|
||||
|
||||
connect(input_, &FilteredTextEdit::stoppedTyping, this, &TextInputWidget::stoppedTyping);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -227,3 +253,9 @@ TextInputWidget::hideUploadSpinner()
|
|||
}
|
||||
|
||||
TextInputWidget::~TextInputWidget() {}
|
||||
|
||||
void
|
||||
TextInputWidget::stopTyping()
|
||||
{
|
||||
input_->stopTyping();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue