From c804b9ce14b8b2df4bd13fc5220a71f79082f375 Mon Sep 17 00:00:00 2001 From: Azhar Momin Date: Tue, 24 Feb 2026 17:59:27 +0530 Subject: [PATCH] Send typing notifications from ChatBar again --- src/chatbar/ChatBarCore.qml | 1 + .../models/chatbarmessagecontentmodel.cpp | 30 +++++++++++++++++++ .../models/chatbarmessagecontentmodel.h | 11 +++++++ 3 files changed, 42 insertions(+) diff --git a/src/chatbar/ChatBarCore.qml b/src/chatbar/ChatBarCore.qml index 9eab4534c..aca4315a8 100644 --- a/src/chatbar/ChatBarCore.qml +++ b/src/chatbar/ChatBarCore.qml @@ -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 { diff --git a/src/messagecontent/models/chatbarmessagecontentmodel.cpp b/src/messagecontent/models/chatbarmessagecontentmodel.cpp index 8dcb5ab48..bd9ac8b3b 100644 --- a/src/messagecontent/models/chatbarmessagecontentmodel.cpp +++ b/src/messagecontent/models/chatbarmessagecontentmodel.cpp @@ -4,6 +4,7 @@ #include "chatbarmessagecontentmodel.h" #include +#include #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" diff --git a/src/messagecontent/models/chatbarmessagecontentmodel.h b/src/messagecontent/models/chatbarmessagecontentmodel.h index 5b2e98384..ff927294e 100644 --- a/src/messagecontent/models/chatbarmessagecontentmodel.h +++ b/src/messagecontent/models/chatbarmessagecontentmodel.h @@ -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(); };