mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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->showBox = std::move(showBox);
|
||||||
_request->showToast = std::move(showToast);
|
_request->showToast = std::move(showToast);
|
||||||
_request->done = std::move(done);
|
_request->done = std::move(done);
|
||||||
|
_request->changingJoinAsFrom = changingJoinAsFrom;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
session->api().request(_request->id).cancel();
|
session->api().request(_request->id).cancel();
|
||||||
|
@ -345,21 +346,14 @@ void ChooseJoinAsProcess::start(
|
||||||
_request = nullptr;
|
_request = nullptr;
|
||||||
}, _request->lifetime);
|
}, _request->lifetime);
|
||||||
|
|
||||||
const auto finish = [=](JoinInfo info) {
|
requestList();
|
||||||
const auto done = std::move(_request->done);
|
}
|
||||||
const auto box = _request->box;
|
|
||||||
_request = nullptr;
|
void ChooseJoinAsProcess::requestList() {
|
||||||
done(std::move(info));
|
const auto session = &_request->peer->session();
|
||||||
if (const auto strong = box.data()) {
|
|
||||||
strong->closeBox();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
_request->id = session->api().request(MTPphone_GetGroupCallJoinAs(
|
_request->id = session->api().request(MTPphone_GetGroupCallJoinAs(
|
||||||
_request->peer->input
|
_request->peer->input
|
||||||
)).done([=](const MTPphone_JoinAsPeers &result) {
|
)).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) {
|
auto list = result.match([&](const MTPDphone_joinAsPeers &data) {
|
||||||
session->data().processUsers(data.vusers());
|
session->data().processUsers(data.vusers());
|
||||||
session->data().processChats(data.vchats());
|
session->data().processChats(data.vchats());
|
||||||
|
@ -376,97 +370,7 @@ void ChooseJoinAsProcess::start(
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
const auto selectedId = peer->groupCallDefaultJoinAs();
|
processList(std::move(list));
|
||||||
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));
|
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
finish({
|
finish({
|
||||||
.peer = _request->peer,
|
.peer = _request->peer,
|
||||||
|
@ -475,4 +379,114 @@ void ChooseJoinAsProcess::start(
|
||||||
}).send();
|
}).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
|
} // namespace Calls::Group
|
||||||
|
|
|
@ -41,6 +41,10 @@ public:
|
||||||
PeerData *changingJoinAsFrom = nullptr);
|
PeerData *changingJoinAsFrom = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void requestList();
|
||||||
|
void processList(std::vector<not_null<PeerData*>> &&list);
|
||||||
|
void finish(JoinInfo info);
|
||||||
|
|
||||||
struct ChannelsListRequest {
|
struct ChannelsListRequest {
|
||||||
not_null<PeerData*> peer;
|
not_null<PeerData*> peer;
|
||||||
Fn<void(object_ptr<Ui::BoxContent>)> showBox;
|
Fn<void(object_ptr<Ui::BoxContent>)> showBox;
|
||||||
|
@ -51,6 +55,7 @@ private:
|
||||||
rpl::lifetime lifetime;
|
rpl::lifetime lifetime;
|
||||||
Context context = Context();
|
Context context = Context();
|
||||||
mtpRequestId id = 0;
|
mtpRequestId id = 0;
|
||||||
|
PeerData *changingJoinAsFrom = nullptr;
|
||||||
};
|
};
|
||||||
std::unique_ptr<ChannelsListRequest> _request;
|
std::unique_ptr<ChannelsListRequest> _request;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue