Fix confirmation when joining by link.

This commit is contained in:
John Preston 2021-03-16 21:06:36 +04:00
parent 1db1328a91
commit 5708b5e849

View file

@ -240,15 +240,34 @@ void ChooseJoinAsProcess::start(
if (list.empty()) { if (list.empty()) {
_request->showToast(Lang::Hard::ServerError()); _request->showToast(Lang::Hard::ServerError());
return; return;
} else if (!changingJoinAsFrom }
&& list.size() == 1 info.joinAs = [&]() -> not_null<PeerData*> {
&& list.front() == self const auto loaded = selectedId
? session->data().peerLoaded(selectedId)
: nullptr;
return (changingJoinAsFrom
&& ranges::contains(list, not_null{ changingJoinAsFrom }))
? not_null(changingJoinAsFrom)
: (loaded && ranges::contains(list, not_null{ loaded }))
? not_null(loaded)
: ranges::contains(list, self)
? self
: list.front();
}();
info.possibleJoinAs = std::move(list);
const auto onlyByMe = (info.possibleJoinAs.size() == 1)
&& (info.possibleJoinAs.front() == self)
&& (!peer->isChannel() && (!peer->isChannel()
|| !peer->asChannel()->amAnonymous() || !peer->asChannel()->amAnonymous()
|| (peer->isBroadcast() && !peer->canWrite()))) { || (peer->isBroadcast() && !peer->canWrite()));
info.possibleJoinAs = std::move(list);
if (context != Context::JoinWithConfirm // We already joined this voice chat, just rejoin with the same.
|| (selectedId && self->id == selectedId)) { const auto byAlreadyUsed = selectedId
&& (info.joinAs->id == selectedId);
if (!changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) {
if (context != Context::JoinWithConfirm) {
finish(info); finish(info);
return; return;
} }
@ -273,28 +292,6 @@ void ChooseJoinAsProcess::start(
_request->showBox(std::move(box)); _request->showBox(std::move(box));
return; return;
} }
info.joinAs = [&]() -> not_null<PeerData*> {
const auto loaded = selectedId
? session->data().peerLoaded(selectedId)
: nullptr;
return (changingJoinAsFrom
&& ranges::contains(list, not_null{ changingJoinAsFrom }))
? not_null(changingJoinAsFrom)
: (loaded && ranges::contains(list, not_null{ loaded }))
? not_null(loaded)
: ranges::contains(list, self)
? self
: list.front();
}();
info.possibleJoinAs = std::move(list);
if (!changingJoinAsFrom
&& selectedId
&& info.joinAs->id == selectedId) {
// We already joined this voice chat, just rejoin with the same.
finish(info);
return;
}
auto box = Box( auto box = Box(
ChooseJoinAsBox, ChooseJoinAsBox,
context, context,