Fix leaving channels and supergroups.

Fixes #5838.
This commit is contained in:
John Preston 2019-03-25 15:49:57 +04:00
parent d7a67a6a1c
commit bb2e683dea
3 changed files with 23 additions and 16 deletions

View File

@ -2363,21 +2363,6 @@ void ApiWrap::clearHistory(not_null<PeerData*> peer, bool revoke) {
}
void ApiWrap::deleteConversation(not_null<PeerData*> 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<PeerData*> 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<PeerData*> peer, bool justClear, bool revoke) {

View File

@ -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<PeerData*> 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*> history,
not_null<UserData*> user,

View File

@ -125,6 +125,8 @@ public:
[[nodiscard]] not_null<History*> history(not_null<const PeerData*> peer);
[[nodiscard]] History *historyLoaded(const PeerData *peer);
void deleteConversationLocally(not_null<PeerData*> peer);
void registerSendAction(
not_null<History*> history,
not_null<UserData*> user,