Opening and closing chat officially on entering/leaving page

This commit is contained in:
Sebastian J. Wolf 2020-08-21 14:47:08 +02:00
parent a7b8dc54bd
commit b42a8e4181
3 changed files with 27 additions and 0 deletions

View file

@ -33,6 +33,7 @@ Page {
property variant chatInformation; property variant chatInformation;
function initializePage() { function initializePage() {
tdLibWrapper.openChat(chatInformation.id);
chatPage.loading = false; chatPage.loading = false;
} }
@ -40,6 +41,12 @@ Page {
initializePage(); initializePage();
} }
onStatusChanged: {
if (status === PageStatus.Deactivating) {
tdLibWrapper.closeChat(chatInformation.id);
}
}
SilicaFlickable { SilicaFlickable {
id: chatContainer id: chatContainer
contentHeight: parent.height contentHeight: parent.height

View file

@ -130,6 +130,24 @@ void TDLibWrapper::downloadFile(const QString &fileId)
this->sendRequest(requestObject); 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() QVariantMap TDLibWrapper::getUserInformation()
{ {
return this->userInformation; return this->userInformation;

View file

@ -72,6 +72,8 @@ public:
Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode); Q_INVOKABLE void setAuthenticationCode(const QString &authenticationCode);
Q_INVOKABLE void getChats(); Q_INVOKABLE void getChats();
Q_INVOKABLE void downloadFile(const QString &fileId); Q_INVOKABLE void downloadFile(const QString &fileId);
Q_INVOKABLE void openChat(const QString &chatId);
Q_INVOKABLE void closeChat(const QString &chatId);
signals: signals:
void versionDetected(const QString &version); void versionDetected(const QString &version);