Add confirmation on create / anonymous admin join.

This commit is contained in:
John Preston 2021-03-19 13:59:35 +04:00
parent ba41da7b28
commit e22ecafc1d
2 changed files with 45 additions and 16 deletions

View File

@ -1939,6 +1939,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_group_call_leave_sure" = "Are you sure you want to leave this voice chat?"; "lng_group_call_leave_sure" = "Are you sure you want to leave this voice chat?";
"lng_group_call_leave_to_other_sure" = "Do you want to leave your active voice chat and join a voice chat in this group?"; "lng_group_call_leave_to_other_sure" = "Do you want to leave your active voice chat and join a voice chat in this group?";
"lng_group_call_create_sure" = "Do you really want to start a voice chat in this group?"; "lng_group_call_create_sure" = "Do you really want to start a voice chat in this group?";
"lng_group_call_create_sure_channel" = "Are you sure you want to start a voice chat in this channel as your personal account?";
"lng_group_call_join_sure_personal" = "Are you sure you want to join this voice chat as your personal account?";
"lng_group_call_also_end" = "End voice chat"; "lng_group_call_also_end" = "End voice chat";
"lng_group_call_settings_title" = "Settings"; "lng_group_call_settings_title" = "Settings";
"lng_group_call_invite" = "Invite Member"; "lng_group_call_invite" = "Invite Member";

View File

@ -163,6 +163,37 @@ void ChooseJoinAsBox(
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
} }
[[nodiscard]] TextWithEntities CreateOrJoinConfirmation(
not_null<PeerData*> peer,
ChooseJoinAsProcess::Context context,
bool joinAsAlreadyUsed) {
const auto existing = peer->groupCall();
if (!existing) {
return { peer->isBroadcast()
? tr::lng_group_call_create_sure_channel(tr::now)
: tr::lng_group_call_create_sure(tr::now) };
}
const auto channel = peer->asChannel();
const auto anonymouseAdmin = channel
&& ((channel->isMegagroup() && channel->amAnonymous())
|| (channel->isBroadcast()
&& (channel->amCreator()
|| channel->hasAdminRights())));
if (anonymouseAdmin && !joinAsAlreadyUsed) {
return { tr::lng_group_call_join_sure_personal(tr::now) };
} else if (context != ChooseJoinAsProcess::Context::JoinWithConfirm) {
return {};
}
const auto name = !existing->title().isEmpty()
? existing->title()
: peer->name;
return tr::lng_group_call_join_confirm(
tr::now,
lt_chat,
Ui::Text::Bold(name),
Ui::Text::WithEntities);
}
} // namespace } // namespace
ChooseJoinAsProcess::~ChooseJoinAsProcess() { ChooseJoinAsProcess::~ChooseJoinAsProcess() {
@ -257,31 +288,27 @@ void ChooseJoinAsProcess::start(
info.possibleJoinAs = std::move(list); info.possibleJoinAs = std::move(list);
const auto onlyByMe = (info.possibleJoinAs.size() == 1) const auto onlyByMe = (info.possibleJoinAs.size() == 1)
&& (info.possibleJoinAs.front() == self) && (info.possibleJoinAs.front() == self);
&& (!peer->isChannel()
|| !peer->asChannel()->amAnonymous()
|| (peer->isBroadcast() && !peer->canWrite()));
// We already joined this voice chat, just rejoin with the same. // We already joined this voice chat, just rejoin with the same.
const auto byAlreadyUsed = selectedId const auto byAlreadyUsed = selectedId
&& (info.joinAs->id == selectedId); && (info.joinAs->id == selectedId)
&& (peer->groupCall() != nullptr);
if (!changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) { if (!changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) {
if (context != Context::JoinWithConfirm) { const auto confirmation = CreateOrJoinConfirmation(
peer,
context,
byAlreadyUsed);
if (confirmation.text.isEmpty()) {
finish(info); finish(info);
return; return;
} }
const auto real = peer->groupCall();
const auto name = (real && !real->title().isEmpty())
? real->title()
: peer->name;
auto box = Box<::ConfirmBox>( auto box = Box<::ConfirmBox>(
tr::lng_group_call_join_confirm( confirmation,
tr::now, (peer->groupCall()
lt_chat, ? tr::lng_group_call_join(tr::now)
Ui::Text::Bold(name), : tr::lng_create_group_create(tr::now)),
Ui::Text::WithEntities),
tr::lng_group_call_join(tr::now),
crl::guard(&_request->guard, [=] { finish(info); })); crl::guard(&_request->guard, [=] { finish(info); }));
box->boxClosing( box->boxClosing(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {