Add schedule voice chat link in ConfirmBox.

This commit is contained in:
John Preston 2021-04-07 11:21:59 +04:00
parent 27fc61c676
commit 96bc4858c1
7 changed files with 87 additions and 49 deletions

View file

@ -1995,8 +1995,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_group_call_leave_title" = "Leave voice chat";
"lng_group_call_leave_sure" = "Are you sure you want to leave this voice chat?";
"lng_group_call_close" = "Close";
"lng_group_call_close_sure" = "Voice chat is scheduled. You can cancel it or just close this panel.";
"lng_group_call_also_cancel" = "Cancel voice chat";
"lng_group_call_close_sure" = "Voice chat is scheduled. You can abort it or just close this panel.";
"lng_group_call_also_cancel" = "Abort 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_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?";
@ -2027,7 +2027,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_group_call_copy_speaker_link" = "Copy Speaker Link";
"lng_group_call_copy_listener_link" = "Copy Listener Link";
"lng_group_call_end" = "End Voice Chat";
"lng_group_call_cancel" = "Cancel Voice Chat";
"lng_group_call_cancel" = "Abort Voice Chat";
"lng_group_call_join" = "Join";
"lng_group_call_join_confirm" = "Do you want to join the voice chat {chat}?";
"lng_group_call_invite_done_user" = "You invited {user} to the voice chat.";
@ -2062,8 +2062,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_group_call_join_as_header" = "Join Voice Chat as...";
"lng_group_call_display_as_header" = "Display me as...";
"lng_group_call_join_as_about" = "Choose whether you want to be displayed as your personal account or as your channel.";
"lng_group_call_or_schedule" = "Or you can {link}.";
"lng_group_call_schedule" = "Schedule Voice Chat";
"lng_group_call_or_schedule" = "You can also {link}.";
"lng_group_call_schedule" = "schedule a voice chat";
"lng_group_call_schedule_title" = "Schedule Voice Chat";
"lng_group_call_schedule_notified_group" = "The members of the group will be notified that the voice chat will start in {duration}.";
"lng_group_call_schedule_notified_channel" = "The subscribers of the channel will be notified that the voice chat will start in {duration}.";

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "calls/calls_choose_join_as.h"
#include "calls/calls_group_common.h"
#include "calls/calls_group_menu.h"
#include "data/data_peer.h"
#include "data/data_user.h"
#include "data/data_channel.h"
@ -21,10 +22,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/boxes/choose_date_time.h"
#include "ui/text/text_utilities.h"
#include "boxes/peer_list_box.h"
#include "boxes/confirm_box.h"
#include "base/unixtime.h"
#include "base/timer_rpl.h"
#include "styles/style_boxes.h"
#include "styles/style_layers.h"
#include "styles/style_calls.h"
namespace Calls::Group {
@ -230,10 +231,8 @@ void ChooseJoinAsBox(
label->setClickHandlerFilter([=](const auto&...) {
auto withJoinAs = info;
withJoinAs.joinAs = controller->selected();
box->getDelegate()->show(Box(
ScheduleGroupCallBox,
withJoinAs,
done));
box->getDelegate()->show(
Box(ScheduleGroupCallBox, withJoinAs, done));
return false;
});
}
@ -378,7 +377,7 @@ void ChooseJoinAsProcess::start(
&& (peer->groupCall() != nullptr);
if (!changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) {
const auto confirmation = CreateOrJoinConfirmation(
auto confirmation = CreateOrJoinConfirmation(
peer,
context,
byAlreadyUsed);
@ -386,12 +385,36 @@ void ChooseJoinAsProcess::start(
finish(info);
return;
}
auto box = Box<::ConfirmBox>(
confirmation,
(peer->groupCall()
? tr::lng_group_call_join(tr::now)
: tr::lng_create_group_create(tr::now)),
crl::guard(&_request->guard, [=] { finish(info); }));
const auto creating = !peer->groupCall();
if (creating) {
confirmation
.append("\n\n")
.append(tr::lng_group_call_or_schedule(
tr::now,
lt_link,
Ui::Text::Link(tr::lng_group_call_schedule(tr::now)),
Ui::Text::WithEntities));
}
const auto guard = base::make_weak(&_request->guard);
const auto safeFinish = crl::guard(guard, [=] { finish(info); });
const auto filter = [=](const auto &...) {
if (guard) {
_request->showBox(Box(
ScheduleGroupCallBox,
info,
crl::guard(guard, finish)));
}
return false;
};
auto box = ConfirmBox({
.text = confirmation,
.button = (creating
? tr::lng_create_group_create()
: tr::lng_group_call_join()),
.callback = crl::guard(guard, [=] { finish(info); }),
.st = &st::boxLabel,
.filter = filter,
});
box->boxClosing(
) | rpl::start_with_next([=] {
_request = nullptr;

View file

@ -395,12 +395,7 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) {
_id = data.vid().v;
_accessHash = data.vaccess_hash().v;
});
if (_scheduleDate) {
setState(State::Waiting);
return;
}
setState(State::Joining);
setState(_scheduleDate ? State::Waiting : State::Joining);
if (const auto chat = _peer->asChat()) {
chat->setGroupCall(inputCall);
} else if (const auto group = _peer->asChannel()) {
@ -408,6 +403,10 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) {
} else {
Unexpected("Peer type in GroupCall::join.");
}
if (_scheduleDate) {
return;
}
rejoin();
using Update = Data::GroupCall::ParticipantUpdate;

View file

@ -568,19 +568,20 @@ void LeaveBox(
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
}
void ConfirmBox(
void ConfirmBoxBuilder(
not_null<Ui::GenericBox*> box,
const TextWithEntities &text,
rpl::producer<QString> button,
Fn<void()> callback) {
box->addRow(
ConfirmBoxArgs &&args) {
const auto label = box->addRow(
object_ptr<Ui::FlatLabel>(
box.get(),
rpl::single(text),
st::groupCallBoxLabel),
rpl::single(args.text),
args.st ? *args.st : st::groupCallBoxLabel),
st::boxPadding);
if (callback) {
box->addButton(std::move(button), callback);
if (args.callback) {
box->addButton(std::move(args.button), std::move(args.callback));
}
if (args.filter) {
label->setClickHandlerFilter(std::move(args.filter));
}
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
}

View file

@ -9,6 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/object_ptr.h"
#include "base/unique_qptr.h"
#include "ui/layers/generic_box.h"
namespace style {
struct FlatLabel;
} // namespace style
namespace Ui {
class DropdownMenu;
@ -38,11 +43,19 @@ void LeaveBox(
bool discardChecked,
BoxContext context);
void ConfirmBox(
not_null<Ui::GenericBox*> box,
const TextWithEntities &text,
rpl::producer<QString> button,
Fn<void()> callback);
struct ConfirmBoxArgs {
TextWithEntities text;
rpl::producer<QString> button;
Fn<void()> callback;
const style::FlatLabel *st = nullptr;
Fn<bool(const ClickHandlerPtr&, Qt::MouseButton)> filter;
};
void ConfirmBoxBuilder(not_null<Ui::GenericBox*> box, ConfirmBoxArgs &&args);
inline auto ConfirmBox(ConfirmBoxArgs &&args) {
return Box(ConfirmBoxBuilder, std::move(args));
}
void FillMenu(
not_null<Ui::DropdownMenu*> menu,

View file

@ -556,11 +556,11 @@ void Panel::startScheduledNow() {
}
_call->startScheduledNow();
};
auto owned = Box(
ConfirmBox,
TextWithEntities{ tr::lng_group_call_start_now_sure(tr::now) },
tr::lng_group_call_start_now(),
done);
auto owned = ConfirmBox({
.text = { tr::lng_group_call_start_now_sure(tr::now) },
.button = tr::lng_group_call_start_now(),
.callback = done,
});
*box = owned.data();
_layerBg->showBox(std::move(owned));
}
@ -1153,11 +1153,14 @@ void Panel::addMembers() {
}
finish();
};
auto box = Box(
ConfirmBox,
TextWithEntities{ text },
tr::lng_participant_invite(),
[=] { inviteWithAdd(users, nonMembers, finishWithConfirm); });
const auto done = [=] {
inviteWithAdd(users, nonMembers, finishWithConfirm);
};
auto box = ConfirmBox({
.text = { text },
.button = tr::lng_participant_invite(),
.callback = done,
});
*shared = box.data();
_layerBg->showBox(std::move(box));
};

View file

@ -149,8 +149,7 @@ object_ptr<ShareBox> ShareInviteLinkBox(
}
text.append(error.first);
if (const auto weak = *box) {
weak->getDelegate()->show(
Box(ConfirmBox, text, nullptr, nullptr));
weak->getDelegate()->show(ConfirmBox({ .text = text }));
}
return;
}