From bb2e683dea69544c99009ceded7b260aa5bdce40 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 25 Mar 2019 15:49:57 +0400 Subject: [PATCH] Fix leaving channels and supergroups. Fixes #5838. --- Telegram/SourceFiles/apiwrap.cpp | 17 +---------------- Telegram/SourceFiles/data/data_session.cpp | 20 ++++++++++++++++++++ Telegram/SourceFiles/data/data_session.h | 2 ++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 19a732615..b9ac8d42b 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2363,21 +2363,6 @@ void ApiWrap::clearHistory(not_null peer, bool revoke) { } void ApiWrap::deleteConversation(not_null peer, bool revoke) { - if (const auto history = _session->data().historyLoaded(peer->id)) { - _session->data().setPinnedDialog(history, false); - App::main()->removeDialog(history); - history->clear(); - if (const auto channel = peer->asMegagroup()) { - channel->addFlags(MTPDchannel::Flag::f_left); - if (const auto from = channel->getMigrateFromChat()) { - if (const auto migrated = _session->data().historyLoaded(from)) { - migrated->updateChatListExistence(); - } - } - } else { - history->markFullyLoaded(); - } - } if (const auto chat = peer->asChat()) { request(MTPmessages_DeleteChatUser( chat->inputChat, @@ -2388,13 +2373,13 @@ void ApiWrap::deleteConversation(not_null peer, bool revoke) { }).fail([=](const RPCError &error) { deleteHistory(peer, false, revoke); }).send(); - return; } else if (const auto channel = peer->asChannel()) { channel->ptsWaitingForShortPoll(-1); leaveChannel(channel); } else { deleteHistory(peer, false, revoke); } + _session->data().deleteConversationLocally(peer); } void ApiWrap::deleteHistory(not_null peer, bool justClear, bool revoke) { diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index adc15335e..8fb194ed4 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "observer_peer.h" #include "auth_session.h" #include "apiwrap.h" +#include "mainwidget.h" #include "core/application.h" #include "core/crash_reports.h" // for CrashReports::SetAnnotation #include "ui/image/image.h" @@ -717,6 +718,25 @@ History *Session::historyLoaded(const PeerData *peer) { return peer ? historyLoaded(peer->id) : nullptr; } +void Session::deleteConversationLocally(not_null peer) { + const auto history = historyLoaded(peer); + if (history) { + setPinnedDialog(history, false); + App::main()->removeDialog(history); + history->clear(); + } + if (const auto channel = peer->asMegagroup()) { + channel->addFlags(MTPDchannel::Flag::f_left); + if (const auto from = channel->getMigrateFromChat()) { + if (const auto migrated = historyLoaded(from)) { + migrated->updateChatListExistence(); + } + } + } else if (history) { + history->markFullyLoaded(); + } +} + void Session::registerSendAction( not_null history, not_null user, diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 1aef19fa1..24b504d54 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -125,6 +125,8 @@ public: [[nodiscard]] not_null history(not_null peer); [[nodiscard]] History *historyLoaded(const PeerData *peer); + void deleteConversationLocally(not_null peer); + void registerSendAction( not_null history, not_null user,