mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Divided ChooseJoinAsProcess::start into methods.
This commit is contained in:
parent
40ed4559c4
commit
f2f4f9b24b
2 changed files with 122 additions and 103 deletions
|
@ -328,6 +328,7 @@ void ChooseJoinAsProcess::start(
|
|||
_request->showBox = std::move(showBox);
|
||||
_request->showToast = std::move(showToast);
|
||||
_request->done = std::move(done);
|
||||
_request->changingJoinAsFrom = changingJoinAsFrom;
|
||||
return;
|
||||
}
|
||||
session->api().request(_request->id).cancel();
|
||||
|
@ -345,21 +346,14 @@ void ChooseJoinAsProcess::start(
|
|||
_request = nullptr;
|
||||
}, _request->lifetime);
|
||||
|
||||
const auto finish = [=](JoinInfo info) {
|
||||
const auto done = std::move(_request->done);
|
||||
const auto box = _request->box;
|
||||
_request = nullptr;
|
||||
done(std::move(info));
|
||||
if (const auto strong = box.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
};
|
||||
requestList();
|
||||
}
|
||||
|
||||
void ChooseJoinAsProcess::requestList() {
|
||||
const auto session = &_request->peer->session();
|
||||
_request->id = session->api().request(MTPphone_GetGroupCallJoinAs(
|
||||
_request->peer->input
|
||||
)).done([=](const MTPphone_JoinAsPeers &result) {
|
||||
const auto peer = _request->peer;
|
||||
const auto self = peer->session().user();
|
||||
auto info = JoinInfo{ .peer = peer, .joinAs = self };
|
||||
auto list = result.match([&](const MTPDphone_joinAsPeers &data) {
|
||||
session->data().processUsers(data.vusers());
|
||||
session->data().processChats(data.vchats());
|
||||
|
@ -376,97 +370,7 @@ void ChooseJoinAsProcess::start(
|
|||
}
|
||||
return list;
|
||||
});
|
||||
const auto selectedId = peer->groupCallDefaultJoinAs();
|
||||
if (list.empty()) {
|
||||
_request->showToast(Lang::Hard::ServerError());
|
||||
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);
|
||||
|
||||
const auto onlyByMe = (info.possibleJoinAs.size() == 1)
|
||||
&& (info.possibleJoinAs.front() == self);
|
||||
|
||||
// We already joined this voice chat, just rejoin with the same.
|
||||
const auto byAlreadyUsed = selectedId
|
||||
&& (info.joinAs->id == selectedId)
|
||||
&& (peer->groupCall() != nullptr);
|
||||
|
||||
if (!changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) {
|
||||
auto confirmation = CreateOrJoinConfirmation(
|
||||
peer,
|
||||
context,
|
||||
byAlreadyUsed);
|
||||
if (confirmation.text.isEmpty()) {
|
||||
finish(info);
|
||||
return;
|
||||
}
|
||||
const auto livestream = peer->isBroadcast();
|
||||
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((livestream
|
||||
? tr::lng_group_call_schedule_channel
|
||||
: 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;
|
||||
}, _request->lifetime);
|
||||
|
||||
_request->box = box.data();
|
||||
_request->showBox(std::move(box));
|
||||
return;
|
||||
}
|
||||
auto box = Box(
|
||||
ChooseJoinAsBox,
|
||||
context,
|
||||
std::move(info),
|
||||
crl::guard(&_request->guard, finish));
|
||||
box->boxClosing(
|
||||
) | rpl::start_with_next([=] {
|
||||
_request = nullptr;
|
||||
}, _request->lifetime);
|
||||
|
||||
_request->box = box.data();
|
||||
_request->showBox(std::move(box));
|
||||
processList(std::move(list));
|
||||
}).fail([=] {
|
||||
finish({
|
||||
.peer = _request->peer,
|
||||
|
@ -475,4 +379,114 @@ void ChooseJoinAsProcess::start(
|
|||
}).send();
|
||||
}
|
||||
|
||||
void ChooseJoinAsProcess::finish(JoinInfo info) {
|
||||
const auto done = std::move(_request->done);
|
||||
const auto box = _request->box;
|
||||
_request = nullptr;
|
||||
done(std::move(info));
|
||||
if (const auto strong = box.data()) {
|
||||
strong->closeBox();
|
||||
}
|
||||
}
|
||||
|
||||
void ChooseJoinAsProcess::processList(
|
||||
std::vector<not_null<PeerData*>> &&list) {
|
||||
const auto session = &_request->peer->session();
|
||||
const auto peer = _request->peer;
|
||||
const auto self = peer->session().user();
|
||||
auto info = JoinInfo{ .peer = peer, .joinAs = self };
|
||||
const auto selectedId = peer->groupCallDefaultJoinAs();
|
||||
if (list.empty()) {
|
||||
_request->showToast(Lang::Hard::ServerError());
|
||||
return;
|
||||
}
|
||||
info.joinAs = [&]() -> not_null<PeerData*> {
|
||||
const auto loaded = selectedId
|
||||
? session->data().peerLoaded(selectedId)
|
||||
: nullptr;
|
||||
const auto changingJoinAsFrom = _request->changingJoinAsFrom;
|
||||
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);
|
||||
|
||||
// We already joined this voice chat, just rejoin with the same.
|
||||
const auto byAlreadyUsed = selectedId
|
||||
&& (info.joinAs->id == selectedId)
|
||||
&& (peer->groupCall() != nullptr);
|
||||
|
||||
if (!_request->changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) {
|
||||
auto confirmation = CreateOrJoinConfirmation(
|
||||
peer,
|
||||
_request->context,
|
||||
byAlreadyUsed);
|
||||
if (confirmation.text.isEmpty()) {
|
||||
finish(info);
|
||||
return;
|
||||
}
|
||||
const auto livestream = peer->isBroadcast();
|
||||
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((livestream
|
||||
? tr::lng_group_call_schedule_channel
|
||||
: 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, [=](auto info) { finish(info); })));
|
||||
}
|
||||
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;
|
||||
}, _request->lifetime);
|
||||
|
||||
_request->box = box.data();
|
||||
_request->showBox(std::move(box));
|
||||
return;
|
||||
}
|
||||
auto box = Box(
|
||||
ChooseJoinAsBox,
|
||||
_request->context,
|
||||
std::move(info),
|
||||
crl::guard(&_request->guard, [=](auto info) { finish(info); }));
|
||||
box->boxClosing(
|
||||
) | rpl::start_with_next([=] {
|
||||
_request = nullptr;
|
||||
}, _request->lifetime);
|
||||
|
||||
_request->box = box.data();
|
||||
_request->showBox(std::move(box));
|
||||
}
|
||||
|
||||
} // namespace Calls::Group
|
||||
|
|
|
@ -41,6 +41,10 @@ public:
|
|||
PeerData *changingJoinAsFrom = nullptr);
|
||||
|
||||
private:
|
||||
void requestList();
|
||||
void processList(std::vector<not_null<PeerData*>> &&list);
|
||||
void finish(JoinInfo info);
|
||||
|
||||
struct ChannelsListRequest {
|
||||
not_null<PeerData*> peer;
|
||||
Fn<void(object_ptr<Ui::BoxContent>)> showBox;
|
||||
|
@ -51,6 +55,7 @@ private:
|
|||
rpl::lifetime lifetime;
|
||||
Context context = Context();
|
||||
mtpRequestId id = 0;
|
||||
PeerData *changingJoinAsFrom = nullptr;
|
||||
};
|
||||
std::unique_ptr<ChannelsListRequest> _request;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue