mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +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;
|
|
||||||
done(std::move(info));
|
|
||||||
if (const auto strong = box.data()) {
|
|
||||||
strong->closeBox();
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
void ChooseJoinAsProcess::requestList() {
|
||||||
|
const auto session = &_request->peer->session();
|
||||||
_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,6 +370,31 @@ void ChooseJoinAsProcess::start(
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
|
processList(std::move(list));
|
||||||
|
}).fail([=] {
|
||||||
|
finish({
|
||||||
|
.peer = _request->peer,
|
||||||
|
.joinAs = _request->peer->session().user(),
|
||||||
|
});
|
||||||
|
}).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();
|
const auto selectedId = peer->groupCallDefaultJoinAs();
|
||||||
if (list.empty()) {
|
if (list.empty()) {
|
||||||
_request->showToast(Lang::Hard::ServerError());
|
_request->showToast(Lang::Hard::ServerError());
|
||||||
|
@ -385,6 +404,7 @@ void ChooseJoinAsProcess::start(
|
||||||
const auto loaded = selectedId
|
const auto loaded = selectedId
|
||||||
? session->data().peerLoaded(selectedId)
|
? session->data().peerLoaded(selectedId)
|
||||||
: nullptr;
|
: nullptr;
|
||||||
|
const auto changingJoinAsFrom = _request->changingJoinAsFrom;
|
||||||
return (changingJoinAsFrom
|
return (changingJoinAsFrom
|
||||||
&& ranges::contains(list, not_null{ changingJoinAsFrom }))
|
&& ranges::contains(list, not_null{ changingJoinAsFrom }))
|
||||||
? not_null(changingJoinAsFrom)
|
? not_null(changingJoinAsFrom)
|
||||||
|
@ -404,10 +424,10 @@ void ChooseJoinAsProcess::start(
|
||||||
&& (info.joinAs->id == selectedId)
|
&& (info.joinAs->id == selectedId)
|
||||||
&& (peer->groupCall() != nullptr);
|
&& (peer->groupCall() != nullptr);
|
||||||
|
|
||||||
if (!changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) {
|
if (!_request->changingJoinAsFrom && (onlyByMe || byAlreadyUsed)) {
|
||||||
auto confirmation = CreateOrJoinConfirmation(
|
auto confirmation = CreateOrJoinConfirmation(
|
||||||
peer,
|
peer,
|
||||||
context,
|
_request->context,
|
||||||
byAlreadyUsed);
|
byAlreadyUsed);
|
||||||
if (confirmation.text.isEmpty()) {
|
if (confirmation.text.isEmpty()) {
|
||||||
finish(info);
|
finish(info);
|
||||||
|
@ -433,7 +453,7 @@ void ChooseJoinAsProcess::start(
|
||||||
_request->showBox(Box(
|
_request->showBox(Box(
|
||||||
ScheduleGroupCallBox,
|
ScheduleGroupCallBox,
|
||||||
info,
|
info,
|
||||||
crl::guard(guard, finish)));
|
crl::guard(guard, [=](auto info) { finish(info); })));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -457,9 +477,9 @@ void ChooseJoinAsProcess::start(
|
||||||
}
|
}
|
||||||
auto box = Box(
|
auto box = Box(
|
||||||
ChooseJoinAsBox,
|
ChooseJoinAsBox,
|
||||||
context,
|
_request->context,
|
||||||
std::move(info),
|
std::move(info),
|
||||||
crl::guard(&_request->guard, finish));
|
crl::guard(&_request->guard, [=](auto info) { finish(info); }));
|
||||||
box->boxClosing(
|
box->boxClosing(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
_request = nullptr;
|
_request = nullptr;
|
||||||
|
@ -467,12 +487,6 @@ void ChooseJoinAsProcess::start(
|
||||||
|
|
||||||
_request->box = box.data();
|
_request->box = box.data();
|
||||||
_request->showBox(std::move(box));
|
_request->showBox(std::move(box));
|
||||||
}).fail([=] {
|
|
||||||
finish({
|
|
||||||
.peer = _request->peer,
|
|
||||||
.joinAs = _request->peer->session().user(),
|
|
||||||
});
|
|
||||||
}).send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // 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