mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Update API scheme.
This commit is contained in:
@@ -163,20 +163,18 @@ void ChooseJoinAsProcess::start(
|
||||
not_null<PeerData*> peer,
|
||||
Context context,
|
||||
Fn<void(object_ptr<Ui::BoxContent>)> showBox,
|
||||
Fn<void(QString)> showToast,
|
||||
Fn<void(JoinInfo)> done,
|
||||
PeerData *currentJoinAs) {
|
||||
Expects(done != nullptr);
|
||||
|
||||
const auto session = &peer->session();
|
||||
if (_request) {
|
||||
const auto already = _request->peer;
|
||||
_request->context = context;
|
||||
_request->showBox = std::move(showBox);
|
||||
_request->done = std::move(done);
|
||||
if (already == peer) {
|
||||
return;
|
||||
} else if (&already->session() == session) {
|
||||
_request->peer = peer;
|
||||
if (_request->peer == peer) {
|
||||
_request->context = context;
|
||||
_request->showBox = std::move(showBox);
|
||||
_request->showToast = std::move(showToast);
|
||||
_request->done = std::move(done);
|
||||
return;
|
||||
}
|
||||
session->api().request(_request->id).cancel();
|
||||
@@ -186,6 +184,7 @@ void ChooseJoinAsProcess::start(
|
||||
ChannelsListRequest{
|
||||
.peer = peer,
|
||||
.showBox = std::move(showBox),
|
||||
.showToast = std::move(showToast),
|
||||
.done = std::move(done),
|
||||
.context = context });
|
||||
session->account().sessionChanges(
|
||||
@@ -204,39 +203,52 @@ void ChooseJoinAsProcess::start(
|
||||
}
|
||||
};
|
||||
using Flag = MTPchannels_GetAdminedPublicChannels::Flag;
|
||||
_request->id = session->api().request(
|
||||
MTPchannels_GetAdminedPublicChannels(
|
||||
MTP_flags(Flag::f_for_groupcall))
|
||||
).done([=](const MTPmessages_Chats &result) {
|
||||
const auto &chats = result.match([](const auto &data) {
|
||||
return data.vchats().v;
|
||||
});
|
||||
_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 };
|
||||
if (chats.size() == 1) {
|
||||
auto list = result.match([&](const MTPDphone_joinAsPeers &data) {
|
||||
session->data().processUsers(data.vusers());
|
||||
session->data().processChats(data.vchats());
|
||||
const auto &peers = data.vpeers().v;
|
||||
auto list = std::vector<not_null<PeerData*>>();
|
||||
list.reserve(peers.size());
|
||||
for (const auto &peer : peers) {
|
||||
const auto peerId = peerFromMTP(peer);
|
||||
if (const auto peer = session->data().peerLoaded(peerId)) {
|
||||
if (!ranges::contains(list, not_null{ peer })) {
|
||||
list.push_back(peer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
});
|
||||
if (list.empty()) {
|
||||
_request->showToast("No way to join this voice chat :(");
|
||||
return;
|
||||
} else if (list.size() == 1 && list.front() == self) {
|
||||
info.possibleJoinAs = std::move(list);
|
||||
finish(info);
|
||||
return;
|
||||
}
|
||||
auto list = std::vector<not_null<PeerData*>>();
|
||||
list.reserve(chats.size() + 1);
|
||||
list.push_back(self);
|
||||
for (const auto &chat : chats) {
|
||||
list.push_back(session->data().processChat(chat));
|
||||
}
|
||||
const auto selected = [&]() -> PeerData* {
|
||||
info.joinAs = [&]() -> not_null<PeerData*> {
|
||||
const auto selectedId = peer->groupCallDefaultJoinAs();
|
||||
if (!selectedId) {
|
||||
return self;
|
||||
}
|
||||
const auto loaded = session->data().peerLoaded(selectedId);
|
||||
return (loaded && ranges::contains(list, not_null{ loaded }))
|
||||
return (currentJoinAs && ranges::contains(list, not_null{ currentJoinAs }))
|
||||
? not_null(currentJoinAs)
|
||||
: (loaded && ranges::contains(list, not_null{ loaded }))
|
||||
? not_null(loaded)
|
||||
: self;
|
||||
: ranges::contains(list, self)
|
||||
? self
|
||||
: list.front();
|
||||
}();
|
||||
|
||||
info.joinAs = currentJoinAs ? currentJoinAs : selected;
|
||||
info.possibleJoinAs = std::move(list);
|
||||
|
||||
auto box = Box(
|
||||
ChooseJoinAsBox,
|
||||
context,
|
||||
|
@@ -35,6 +35,7 @@ public:
|
||||
not_null<PeerData*> peer,
|
||||
Context context,
|
||||
Fn<void(object_ptr<Ui::BoxContent>)> showBox,
|
||||
Fn<void(QString)> showToast,
|
||||
Fn<void(JoinInfo)> done,
|
||||
PeerData *currentJoinAs = nullptr);
|
||||
|
||||
@@ -42,6 +43,7 @@ private:
|
||||
struct ChannelsListRequest {
|
||||
not_null<PeerData*> peer;
|
||||
Fn<void(object_ptr<Ui::BoxContent>)> showBox;
|
||||
Fn<void(QString)> showToast;
|
||||
Fn<void(JoinInfo)> done;
|
||||
base::has_weak_ptr guard;
|
||||
QPointer<Ui::BoxContent> box;
|
||||
|
@@ -164,13 +164,18 @@ void GroupCallSettingsBox(
|
||||
const auto callback = [=](Group::JoinInfo info) {
|
||||
call->rejoinAs(info);
|
||||
};
|
||||
auto showBox = [=](object_ptr<Ui::BoxContent> next) {
|
||||
const auto showBox = [=](object_ptr<Ui::BoxContent> next) {
|
||||
box->getDelegate()->show(std::move(next));
|
||||
};
|
||||
const auto showToast = [=](QString text) {
|
||||
const auto container = box->getDelegate()->outerContainer();
|
||||
Ui::Toast::Show(container, text);
|
||||
};
|
||||
state->joinAsProcess.start(
|
||||
peer,
|
||||
context,
|
||||
showBox,
|
||||
showToast,
|
||||
callback,
|
||||
call->joinAs());
|
||||
});
|
||||
|
@@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_session.h"
|
||||
#include "media/audio/media_audio_track.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "mainwidget.h"
|
||||
#include "mtproto/mtproto_config.h"
|
||||
@@ -66,6 +67,8 @@ void Instance::startOrJoinGroupCall(not_null<PeerData*> peer) {
|
||||
: Group::ChooseJoinAsProcess::Context::Create;
|
||||
_chooseJoinAs.start(peer, context, [=](object_ptr<Ui::BoxContent> box) {
|
||||
Ui::show(std::move(box), Ui::LayerOption::KeepOther);
|
||||
}, [=](QString text) {
|
||||
Ui::Toast::Show(text);
|
||||
}, [=](Group::JoinInfo info) {
|
||||
const auto call = info.peer->groupCall();
|
||||
createGroupCall(
|
||||
|
Reference in New Issue
Block a user