From b42a8e418106df13ed4e2b42e7e8c79f69c26597 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Fri, 21 Aug 2020 14:47:08 +0200 Subject: [PATCH] Opening and closing chat officially on entering/leaving page --- qml/pages/ChatPage.qml | 7 +++++++ src/tdlibwrapper.cpp | 18 ++++++++++++++++++ src/tdlibwrapper.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 8be1c91..084162b 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -33,6 +33,7 @@ Page { property variant chatInformation; function initializePage() { + tdLibWrapper.openChat(chatInformation.id); chatPage.loading = false; } @@ -40,6 +41,12 @@ Page { initializePage(); } + onStatusChanged: { + if (status === PageStatus.Deactivating) { + tdLibWrapper.closeChat(chatInformation.id); + } + } + SilicaFlickable { id: chatContainer contentHeight: parent.height diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 4d5c788..3bb76a8 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -130,6 +130,24 @@ void TDLibWrapper::downloadFile(const QString &fileId) this->sendRequest(requestObject); } +void TDLibWrapper::openChat(const QString &chatId) +{ + qDebug() << "[TDLibWrapper] Opening chat " << chatId; + QVariantMap requestObject; + requestObject.insert("@type", "openChat"); + requestObject.insert("chat_id", chatId); + this->sendRequest(requestObject); +} + +void TDLibWrapper::closeChat(const QString &chatId) +{ + qDebug() << "[TDLibWrapper] Closing chat " << chatId; + QVariantMap requestObject; + requestObject.insert("@type", "closeChat"); + requestObject.insert("chat_id", chatId); + this->sendRequest(requestObject); +} + QVariantMap TDLibWrapper::getUserInformation() { return this->userInformation; diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index a9bc2cc..e8535d5 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -72,6 +72,8 @@ public: Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); Q_INVOKABLE void getChats(); Q_INVOKABLE void downloadFile(const QString &fileId); + Q_INVOKABLE void openChat(const QString &chatId); + Q_INVOKABLE void closeChat(const QString &chatId); signals: void versionDetected(const QString &version);