From 7f8cdf85d57f0da7952a3f6d75fc5938458980e4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 8 Nov 2017 14:45:09 +0400 Subject: [PATCH] Grow history stack following joinchat links. --- Telegram/SourceFiles/mainwidget.cpp | 42 ++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e9e656458f..f2ad4e059f 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -4377,7 +4377,7 @@ void MainWidget::inviteCheckDone(QString hash, const MTPChatInvite &invite) { case mtpc_chatInvite: { auto &d = invite.c_chatInvite(); - QVector participants; + auto participants = QVector(); if (d.has_participants()) { auto &v = d.vparticipants.v; participants.reserve(v.size()); @@ -4388,15 +4388,21 @@ void MainWidget::inviteCheckDone(QString hash, const MTPChatInvite &invite) { } } _inviteHash = hash; - auto isChannel = d.is_channel() && !d.is_megagroup(); - Ui::show(Box(qs(d.vtitle), isChannel, d.vphoto, d.vparticipants_count.v, participants)); + auto box = Box( + qs(d.vtitle), + d.is_channel() && !d.is_megagroup(), + d.vphoto, + d.vparticipants_count.v, + participants); + Ui::show(std::move(box)); } break; case mtpc_chatInviteAlready: { - const auto &d(invite.c_chatInviteAlready()); - PeerData *chat = App::feedChats(MTP_vector(1, d.vchat)); - if (chat) { - Ui::showPeerHistory(chat->id, ShowAtUnreadMsgId); + auto &d = invite.c_chatInviteAlready(); + if (auto chat = App::feedChat(d.vchat)) { + _controller->showPeerHistory( + chat, + SectionShow::Way::Forward); } } break; } @@ -4413,7 +4419,10 @@ bool MainWidget::inviteCheckFail(const RPCError &error) { void MainWidget::onInviteImport() { if (_inviteHash.isEmpty()) return; - MTP::send(MTPmessages_ImportChatInvite(MTP_string(_inviteHash)), rpcDone(&MainWidget::inviteImportDone), rpcFail(&MainWidget::inviteImportFail)); + MTP::send( + MTPmessages_ImportChatInvite(MTP_string(_inviteHash)), + rpcDone(&MainWidget::inviteImportDone), + rpcFail(&MainWidget::inviteImportFail)); } void MainWidget::inviteImportDone(const MTPUpdates &updates) { @@ -4427,10 +4436,19 @@ void MainWidget::inviteImportDone(const MTPUpdates &updates) { default: LOG(("API Error: unexpected update cons %1 (MainWidget::inviteImportDone)").arg(updates.type())); break; } if (v && !v->isEmpty()) { - if (v->front().type() == mtpc_chat) { - Ui::showPeerHistory(peerFromChat(v->front().c_chat().vid.v), ShowAtTheEndMsgId); - } else if (v->front().type() == mtpc_channel) { - Ui::showPeerHistory(peerFromChannel(v->front().c_channel().vid.v), ShowAtTheEndMsgId); + auto &mtpChat = v->front(); + auto peerId = [&] { + if (mtpChat.type() == mtpc_chat) { + return peerFromChat(mtpChat.c_chat().vid.v); + } else if (mtpChat.type() == mtpc_channel) { + return peerFromChannel(mtpChat.c_channel().vid.v); + } + return PeerId(0); + }(); + if (auto peer = App::peerLoaded(peerId)) { + _controller->showPeerHistory( + peer, + SectionShow::Way::Forward); } } }