From 59a7c8381da49fbf2f064d9ae048807155091334 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Sat, 22 Aug 2020 23:05:45 +0200 Subject: [PATCH] Mark display messages as read --- qml/pages/ChatPage.qml | 16 ++++++++++++++++ src/tdlibwrapper.cpp | 13 +++++++++++++ src/tdlibwrapper.h | 1 + 3 files changed, 30 insertions(+) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index f5498d0..08d7af4 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -239,6 +239,20 @@ Page { clip: true visible: count > 0 + onMovementEnded: { + tdLibWrapper.viewMessage(chatInformation.id, chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin )).myMessage.id); + } + + onQuickScrollAnimatingChanged: { + if (!quickScrollAnimating) { + tdLibWrapper.viewMessage(chatInformation.id, chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin )).myMessage.id); + } + } + + onCurrentIndexChanged: { + tdLibWrapper.viewMessage(chatInformation.id, currentItem.myMessage.id); + } + model: chatModel delegate: ListItem { @@ -246,6 +260,8 @@ Page { contentHeight: messageTextItem.height + Theme.paddingMedium contentWidth: parent.width + property variant myMessage: display + Column { id: messageTextItem diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 9afd2d6..c5000eb 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -166,6 +166,19 @@ void TDLibWrapper::getChatHistory(const QString &chatId, const qlonglong &fromMe this->sendRequest(requestObject); } +void TDLibWrapper::viewMessage(const QString &chatId, const QString &messageId) +{ + qDebug() << "[TDLibWrapper] Mark message as viewed " << chatId << messageId; + QVariantMap requestObject; + requestObject.insert("@type", "viewMessages"); + requestObject.insert("chat_id", chatId); + requestObject.insert("force_read", false); + QVariantList messageIds; + messageIds.append(messageId); + requestObject.insert("message_ids", messageIds); + this->sendRequest(requestObject); +} + QVariantMap TDLibWrapper::getUserInformation() { return this->userInformation; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index d9515fa..98b974c 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -77,6 +77,7 @@ public: Q_INVOKABLE void openChat(const QString &chatId); Q_INVOKABLE void closeChat(const QString &chatId); Q_INVOKABLE void getChatHistory(const QString &chatId, const qlonglong &fromMessageId = 0, const int &offset = 0, const int &limit = 50, const bool &onlyLocal = false); + Q_INVOKABLE void viewMessage(const QString &chatId, const QString &messageId); signals: void versionDetected(const QString &version);