| 114 | } |
| 115 | |
| 116 | void SubmitChatInvite( |
| 117 | base::weak_ptr<Window::SessionController> weak, |
| 118 | not_null<Main::Session*> session, |
| 119 | const QString &hash, |
| 120 | bool isGroup) { |
| 121 | session->api().request(MTPmessages_ImportChatInvite( |
| 122 | MTP_string(hash) |
| 123 | )).done([=](const MTPmessages_ChatInviteJoinResult &result) { |
| 124 | const auto strongController = weak.get(); |
| 125 | if (strongController) { |
| 126 | strongController->hideLayer(); |
| 127 | } |
| 128 | |
| 129 | ProcessChatInviteJoinResult( |
| 130 | session, |
| 131 | strongController ? strongController->uiShow() : nullptr, |
| 132 | result, |
| 133 | [=](const MTPUpdates &updates) { |
| 134 | session->api().applyUpdates(updates); |
| 135 | if (!strongController) { |
| 136 | return; |
| 137 | } |
| 138 | const auto handleChats = [&]( |
| 139 | const MTPVector<MTPChat> &chats) { |
| 140 | if (chats.v.isEmpty()) { |
| 141 | return; |
| 142 | } |
| 143 | const auto peerId = chats.v[0].match( |
| 144 | [](const MTPDchat &data) { |
| 145 | return peerFromChat(data.vid().v); |
| 146 | }, |
| 147 | [](const MTPDchannel &data) { |
| 148 | return peerFromChannel(data.vid().v); |
| 149 | }, |
| 150 | [](auto&&) { |
| 151 | return PeerId(0); |
| 152 | }); |
| 153 | if (const auto peer = session->data().peerLoaded(peerId)) { |
| 154 | strongController->showPeerHistory( |
| 155 | peer, |
| 156 | Window::SectionShow::Way::Forward); |
| 157 | } |
| 158 | }; |
| 159 | updates.match([&](const MTPDupdates &data) { |
| 160 | handleChats(data.vchats()); |
| 161 | }, [&](const MTPDupdatesCombined &data) { |
| 162 | handleChats(data.vchats()); |
| 163 | }, [&](auto &&) { |
| 164 | LOG(("API Error: unexpected update cons %1 " |
| 165 | "(ApiWrap::importChatInvite)").arg(updates.type())); |
| 166 | }); |
| 167 | }, |
| 168 | weak); |
| 169 | }).fail([=](const MTP::Error &error) { |
| 170 | const auto &type = error.type(); |
| 171 | |
| 172 | const auto strongController = weak.get(); |
| 173 | if (!strongController) { |
no test coverage detected