Send typing notifications from ChatBar again
This commit is contained in:
committed by
Tobias Fella
parent
d1acb97fe2
commit
c804b9ce14
@@ -27,6 +27,7 @@ QQC2.Control {
|
|||||||
type: root.chatBarType
|
type: root.chatBarType
|
||||||
room: root.room
|
room: root.room
|
||||||
sendMessageWithEnter: NeoChatConfig.sendMessageWith === 0
|
sendMessageWithEnter: NeoChatConfig.sendMessageWith === 0
|
||||||
|
sendTypingNotifications: NeoChatConfig.typingNotifications
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property LibNeoChat.CompletionModel completionModel: LibNeoChat.CompletionModel {
|
readonly property LibNeoChat.CompletionModel completionModel: LibNeoChat.CompletionModel {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "chatbarmessagecontentmodel.h"
|
#include "chatbarmessagecontentmodel.h"
|
||||||
|
|
||||||
#include <QTextDocumentFragment>
|
#include <QTextDocumentFragment>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "chatbarcache.h"
|
#include "chatbarcache.h"
|
||||||
#include "chatkeyhelper.h"
|
#include "chatkeyhelper.h"
|
||||||
@@ -24,9 +25,13 @@ ChatBarMessageContentModel::ChatBarMessageContentModel(QObject *parent)
|
|||||||
: MessageContentModel(parent)
|
: MessageContentModel(parent)
|
||||||
, m_markdownHelper(new ChatMarkdownHelper(this))
|
, m_markdownHelper(new ChatMarkdownHelper(this))
|
||||||
, m_keyHelper(new ChatKeyHelper(this))
|
, m_keyHelper(new ChatKeyHelper(this))
|
||||||
|
, m_typingTimer(new QTimer(this))
|
||||||
{
|
{
|
||||||
m_editableActive = true;
|
m_editableActive = true;
|
||||||
|
|
||||||
|
m_typingTimer->setInterval(std::chrono::milliseconds(5000));
|
||||||
|
m_typingTimer->setSingleShot(true);
|
||||||
|
|
||||||
connect(this, &ChatBarMessageContentModel::roomChanged, this, [this](NeoChatRoom *oldRoom) {
|
connect(this, &ChatBarMessageContentModel::roomChanged, this, [this](NeoChatRoom *oldRoom) {
|
||||||
if (m_type == ChatBarType::None || !m_room) {
|
if (m_type == ChatBarType::None || !m_room) {
|
||||||
return;
|
return;
|
||||||
@@ -298,6 +303,7 @@ void ChatBarMessageContentModel::connectTextItem(ChatTextItemHelper *chattextite
|
|||||||
removeComponent(helper);
|
removeComponent(helper);
|
||||||
});
|
});
|
||||||
connect(chattextitemhelper, &ChatTextItemHelper::contentsChanged, this, &ChatBarMessageContentModel::hasAnyContentChanged);
|
connect(chattextitemhelper, &ChatTextItemHelper::contentsChanged, this, &ChatBarMessageContentModel::hasAnyContentChanged);
|
||||||
|
connect(chattextitemhelper, &ChatTextItemHelper::contentsChanged, this, &ChatBarMessageContentModel::handleTyping);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatTextItemHelper *ChatBarMessageContentModel::textItemForComponent(const MessageComponent &component) const
|
ChatTextItemHelper *ChatBarMessageContentModel::textItemForComponent(const MessageComponent &component) const
|
||||||
@@ -515,6 +521,15 @@ void ChatBarMessageContentModel::setSendMessageWithEnter(bool sendMessageWithEnt
|
|||||||
Q_EMIT sendMessageWithEnterChanged();
|
Q_EMIT sendMessageWithEnterChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatBarMessageContentModel::setSendTypingNotifications(bool sendTypingNotifications)
|
||||||
|
{
|
||||||
|
m_sendTypingNotifications = sendTypingNotifications;
|
||||||
|
if (!m_sendTypingNotifications && m_typingTimer->isActive()) {
|
||||||
|
m_typingTimer->stop();
|
||||||
|
m_room->sendTypingNotification(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ChatBarMessageContentModel::ComponentIt ChatBarMessageContentModel::removeComponent(ComponentIt it)
|
ChatBarMessageContentModel::ComponentIt ChatBarMessageContentModel::removeComponent(ComponentIt it)
|
||||||
{
|
{
|
||||||
if (it == m_components.end()) {
|
if (it == m_components.end()) {
|
||||||
@@ -658,4 +673,19 @@ void ChatBarMessageContentModel::clearModel()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatBarMessageContentModel::handleTyping()
|
||||||
|
{
|
||||||
|
if (m_type == ChatBarType::None || !m_room || !m_sendTypingNotifications) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_typingTimer->isActive() && hasAnyContent()) {
|
||||||
|
m_typingTimer->start();
|
||||||
|
m_room->sendTypingNotification(true);
|
||||||
|
} else if (m_typingTimer->isActive() && !hasAnyContent()) {
|
||||||
|
m_typingTimer->stop();
|
||||||
|
m_room->sendTypingNotification(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_chatbarmessagecontentmodel.cpp"
|
#include "moc_chatbarmessagecontentmodel.cpp"
|
||||||
|
|||||||
@@ -82,6 +82,11 @@ class ChatBarMessageContentModel : public MessageContentModel
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(bool hasAnyContent READ hasAnyContent NOTIFY hasAnyContentChanged)
|
Q_PROPERTY(bool hasAnyContent READ hasAnyContent NOTIFY hasAnyContentChanged)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Whether to send typing notifications to the server when the content changes.
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(bool sendTypingNotifications WRITE setSendTypingNotifications)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ChatBarMessageContentModel(QObject *parent = nullptr);
|
explicit ChatBarMessageContentModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -109,6 +114,8 @@ public:
|
|||||||
bool sendMessageWithEnter() const;
|
bool sendMessageWithEnter() const;
|
||||||
void setSendMessageWithEnter(bool sendMessageWithEnter);
|
void setSendMessageWithEnter(bool sendMessageWithEnter);
|
||||||
|
|
||||||
|
void setSendTypingNotifications(bool sendTypingNotifications);
|
||||||
|
|
||||||
Q_INVOKABLE void postMessage();
|
Q_INVOKABLE void postMessage();
|
||||||
|
|
||||||
bool hasAnyContent() const;
|
bool hasAnyContent() const;
|
||||||
@@ -152,6 +159,10 @@ private:
|
|||||||
void updateCache() const;
|
void updateCache() const;
|
||||||
|
|
||||||
bool m_sendMessageWithEnter = true;
|
bool m_sendMessageWithEnter = true;
|
||||||
|
bool m_sendTypingNotifications = false;
|
||||||
|
|
||||||
void clearModel();
|
void clearModel();
|
||||||
|
|
||||||
|
QTimer *m_typingTimer;
|
||||||
|
void handleTyping();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user