Send typing notifications from ChatBar again

This commit is contained in:
Azhar Momin
2026-02-24 17:59:27 +05:30
committed by Tobias Fella
parent d1acb97fe2
commit c804b9ce14
3 changed files with 42 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ QQC2.Control {
type: root.chatBarType
room: root.room
sendMessageWithEnter: NeoChatConfig.sendMessageWith === 0
sendTypingNotifications: NeoChatConfig.typingNotifications
}
readonly property LibNeoChat.CompletionModel completionModel: LibNeoChat.CompletionModel {

View File

@@ -4,6 +4,7 @@
#include "chatbarmessagecontentmodel.h"
#include <QTextDocumentFragment>
#include <QTimer>
#include "chatbarcache.h"
#include "chatkeyhelper.h"
@@ -24,9 +25,13 @@ ChatBarMessageContentModel::ChatBarMessageContentModel(QObject *parent)
: MessageContentModel(parent)
, m_markdownHelper(new ChatMarkdownHelper(this))
, m_keyHelper(new ChatKeyHelper(this))
, m_typingTimer(new QTimer(this))
{
m_editableActive = true;
m_typingTimer->setInterval(std::chrono::milliseconds(5000));
m_typingTimer->setSingleShot(true);
connect(this, &ChatBarMessageContentModel::roomChanged, this, [this](NeoChatRoom *oldRoom) {
if (m_type == ChatBarType::None || !m_room) {
return;
@@ -298,6 +303,7 @@ void ChatBarMessageContentModel::connectTextItem(ChatTextItemHelper *chattextite
removeComponent(helper);
});
connect(chattextitemhelper, &ChatTextItemHelper::contentsChanged, this, &ChatBarMessageContentModel::hasAnyContentChanged);
connect(chattextitemhelper, &ChatTextItemHelper::contentsChanged, this, &ChatBarMessageContentModel::handleTyping);
}
ChatTextItemHelper *ChatBarMessageContentModel::textItemForComponent(const MessageComponent &component) const
@@ -515,6 +521,15 @@ void ChatBarMessageContentModel::setSendMessageWithEnter(bool sendMessageWithEnt
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)
{
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"

View File

@@ -82,6 +82,11 @@ class ChatBarMessageContentModel : public MessageContentModel
*/
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:
explicit ChatBarMessageContentModel(QObject *parent = nullptr);
@@ -109,6 +114,8 @@ public:
bool sendMessageWithEnter() const;
void setSendMessageWithEnter(bool sendMessageWithEnter);
void setSendTypingNotifications(bool sendTypingNotifications);
Q_INVOKABLE void postMessage();
bool hasAnyContent() const;
@@ -152,6 +159,10 @@ private:
void updateCache() const;
bool m_sendMessageWithEnter = true;
bool m_sendTypingNotifications = false;
void clearModel();
QTimer *m_typingTimer;
void handleTyping();
};