Update API scheme on layer 202.

This commit is contained in:
John Preston 2025-04-09 10:28:21 +04:00
parent a569495f5d
commit 2a7aac76d9
14 changed files with 104 additions and 145 deletions

View file

@ -353,11 +353,6 @@ void Panel::initControls() {
}
const auto call = _call;
const auto creating = std::make_shared<bool>();
const auto finish = [=](QString link) {
if (link.isEmpty()) {
*creating = false;
}
};
const auto create = [=](std::vector<InviteRequest> users) {
if (*creating) {
return;
@ -366,7 +361,7 @@ void Panel::initControls() {
const auto sharingLink = users.empty();
Group::MakeConferenceCall({
.show = sessionShow(),
.finished = finish,
.finished = [=](bool) { *creating = false; },
.joining = true,
.info = {
.invite = std::move(users),

View file

@ -1211,15 +1211,6 @@ std::shared_ptr<Data::GroupCall> GroupCall::conferenceCall() const {
return _conferenceCall;
}
QString GroupCall::existingConferenceLink() const {
Expects(!_conferenceLinkSlug.isEmpty());
const auto session = &_peer->session();
return !_conferenceLinkSlug.isEmpty()
? session->createInternalLinkFull("call/" + _conferenceLinkSlug)
: QString();
}
rpl::producer<not_null<Data::GroupCall*>> GroupCall::real() const {
if (const auto real = lookupReal()) {
return rpl::single(not_null{ real });
@ -1569,7 +1560,6 @@ void GroupCall::sendJoinRequest() {
| (wasVideoStopped
? Flag::f_video_stopped
: Flag(0))
| (_conferenceJoinMessageId ? Flag::f_invite_msg_id : Flag())
| (_e2e ? (Flag::f_public_key | Flag::f_block) : Flag());
_api.request(MTPphone_JoinGroupCall(
MTP_flags(flags),
@ -1578,7 +1568,6 @@ void GroupCall::sendJoinRequest() {
MTP_string(_joinHash),
(_e2e ? TdE2E::PublicKeyToMTP(_e2e->myKey()) : MTPint256()),
MTP_bytes(joinBlock),
MTP_int(_conferenceJoinMessageId.bare),
MTP_dataJSON(MTP_bytes(_joinState.payload.json))
)).done([=](
const MTPUpdates &updates,

View file

@ -260,7 +260,6 @@ public:
[[nodiscard]] Data::GroupCall *lookupReal() const;
[[nodiscard]] std::shared_ptr<Data::GroupCall> conferenceCall() const;
[[nodiscard]] QString existingConferenceLink() const;
[[nodiscard]] rpl::producer<not_null<Data::GroupCall*>> real() const;
[[nodiscard]] rpl::producer<QByteArray> emojiHashValue() const;

View file

@ -253,10 +253,10 @@ ConferenceCallLinkStyleOverrides DarkConferenceCallLinkStyle() {
void ShowConferenceCallLinkBox(
std::shared_ptr<Main::SessionShow> show,
std::shared_ptr<Data::GroupCall> call,
const QString &link,
ConferenceCallLinkArgs &&args) {
const ConferenceCallLinkArgs &args) {
const auto st = args.st;
const auto initial = args.initial;
const auto link = call->conferenceInviteLink();
show->showBox(Box([=](not_null<Ui::GenericBox*> box) {
struct State {
base::unique_qptr<Ui::PopupMenu> menu;
@ -285,30 +285,25 @@ void ShowConferenceCallLinkBox(
}
state->resetting = true;
using Flag = MTPphone_ToggleGroupCallSettings::Flag;
const auto weak = Ui::MakeWeak(box);
call->session().api().request(
MTPphone_ToggleGroupCallSettings(
MTP_flags(Flag::f_reset_invite_hash),
call->input(),
MTPbool()) // join_muted
).done([=] {
auto copy = args;
const auto weak = Ui::MakeWeak(box);
copy.finished = [=](QString link) {
if (const auto strong = weak.data()) {
strong->closeBox();
}
show->showToast({
.title = tr::lng_confcall_link_revoked_title(
tr::now),
.text = {
tr::lng_confcall_link_revoked_text(tr::now),
},
});
};
ExportConferenceCallLink(
show,
call,
std::move(copy));
).done([=](const MTPUpdates &result) {
call->session().api().applyUpdates(result);
ShowConferenceCallLinkBox(show, call, args);
if (const auto strong = weak.data()) {
strong->closeBox();
}
show->showToast({
.title = tr::lng_confcall_link_revoked_title(
tr::now),
.text = {
tr::lng_confcall_link_revoked_text(tr::now),
},
});
}).send();
};
toggle->setClickedCallback([=] {
@ -355,10 +350,7 @@ void ShowConferenceCallLinkBox(
Ui::AddSkip(box->verticalLayout(), st::defaultVerticalListSkip * 2);
const auto preview = box->addRow(
Info::BotStarRef::MakeLinkLabel(
box,
link,
st.linkPreview));
Info::BotStarRef::MakeLinkLabel(box, link, st.linkPreview));
Ui::AddSkip(box->verticalLayout());
const auto copyCallback = [=] {
@ -372,11 +364,11 @@ void ShowConferenceCallLinkBox(
st.shareBox ? *st.shareBox : ShareBoxStyleOverrides());
};
preview->setClickedCallback(copyCallback);
[[maybe_unused]] const auto share = box->addButton(
const auto share = box->addButton(
tr::lng_group_invite_share(),
shareCallback,
st::confcallLinkShareButton);
[[maybe_unused]] const auto copy = box->addButton(
const auto copy = box->addButton(
tr::lng_group_invite_copy(),
copyCallback,
st::confcallLinkCopyButton);
@ -457,21 +449,57 @@ void ShowConferenceCallLinkBox(
}));
}
void ExportConferenceCallLink(
std::shared_ptr<Main::SessionShow> show,
std::shared_ptr<Data::GroupCall> call,
ConferenceCallLinkArgs &&args) {
const auto session = &show->session();
const auto info = std::move(args.info);
void MakeConferenceCall(ConferenceFactoryArgs &&args) {
const auto show = std::move(args.show);
const auto finished = std::move(args.finished);
using Flag = MTPphone_ExportGroupCallInvite::Flag;
session->api().request(MTPphone_ExportGroupCallInvite(
MTP_flags(Flag::f_can_self_unmute),
call->input()
)).done([=](const MTPphone_ExportedGroupCallInvite &result) {
const auto link = qs(result.data().vlink());
if (args.joining) {
const auto joining = args.joining;
const auto info = std::move(args.info);
const auto session = &show->session();
const auto fail = [=](QString error) {
show->showToast(error);
if (const auto onstack = finished) {
onstack(false);
}
};
session->api().request(MTPphone_CreateConferenceCall(
MTP_flags(0),
MTP_int(base::RandomValue<int32>()),
MTPint256(), // public_key
MTPbytes(), // block
MTPDataJSON() // params
)).done([=](const MTPUpdates &result) {
session->api().applyUpdates(result);
const auto updates = result.match([&](const MTPDupdates &data) {
return &data.vupdates().v;
}, [&](const MTPDupdatesCombined &data) {
return &data.vupdates().v;
}, [](const auto &) {
return (const QVector<MTPUpdate>*)nullptr;
});
if (!updates) {
fail(u"Call not found!"_q);
return;
}
auto call = std::shared_ptr<Data::GroupCall>();
for (const auto &update : *updates) {
update.match([&](const MTPDupdateGroupCall &data) {
data.vcall().match([&](const auto &data) {
call = session->data().sharedConferenceCall(
data.vid().v,
data.vaccess_hash().v);
call->enqueueUpdate(update);
});
}, [](const auto &) {});
if (call) {
break;
}
}
const auto link = call ? call->conferenceInviteLink() : QString();
if (link.isEmpty()) {
fail(u"Call link not found!"_q);
return;
}
if (joining) {
if (auto slug = ExtractConferenceSlug(link); !slug.isEmpty()) {
auto copy = info;
copy.call = call;
@ -479,53 +507,17 @@ void ExportConferenceCallLink(
Core::App().calls().startOrJoinConferenceCall(
std::move(copy));
}
if (const auto onstack = finished) {
finished(QString());
}
return;
} else {
Calls::Group::ShowConferenceCallLinkBox(
show,
call,
{ .initial = true });
}
Calls::Group::ShowConferenceCallLinkBox(
show,
call,
link,
base::duplicate(args));
if (const auto onstack = finished) {
finished(link);
finished(true);
}
}).fail([=](const MTP::Error &error) {
show->showToast(error.type());
if (const auto onstack = finished) {
finished(QString());
}
}).send();
}
void MakeConferenceCall(ConferenceFactoryArgs &&args) {
const auto show = std::move(args.show);
const auto finished = std::move(args.finished);
const auto joining = args.joining;
const auto info = std::move(args.info);
const auto session = &show->session();
session->api().request(MTPphone_CreateConferenceCall(
MTP_int(base::RandomValue<int32>())
)).done([=](const MTPphone_GroupCall &result) {
result.data().vcall().match([&](const auto &data) {
const auto call = session->data().sharedConferenceCall(
data.vid().v,
data.vaccess_hash().v);
call->processFullCall(result);
Calls::Group::ExportConferenceCallLink(show, call, {
.initial = true,
.joining = joining,
.finished = finished,
.info = info,
});
});
}).fail([=](const MTP::Error &error) {
show->showToast(error.type());
if (const auto onstack = finished) {
onstack(QString());
}
fail(error.type());
}).send();
}

View file

@ -179,26 +179,17 @@ struct ConferenceCallLinkStyleOverrides {
[[nodiscard]] ConferenceCallLinkStyleOverrides DarkConferenceCallLinkStyle();
struct ConferenceCallLinkArgs {
bool initial = false;
bool joining = false;
Fn<void(QString)> finished;
StartConferenceInfo info;
ConferenceCallLinkStyleOverrides st;
bool initial = false;
};
void ShowConferenceCallLinkBox(
std::shared_ptr<Main::SessionShow> show,
std::shared_ptr<Data::GroupCall> call,
const QString &link,
ConferenceCallLinkArgs &&args);
void ExportConferenceCallLink(
std::shared_ptr<Main::SessionShow> show,
std::shared_ptr<Data::GroupCall> call,
ConferenceCallLinkArgs &&args);
const ConferenceCallLinkArgs &args);
struct ConferenceFactoryArgs {
std::shared_ptr<Main::SessionShow> show;
Fn<void(QString)> finished;
Fn<void(bool)> finished;
bool joining = false;
StartConferenceInfo info;
};

View file

@ -472,7 +472,7 @@ std::unique_ptr<PeerListRow> InviteContactsController::createRow(
object_ptr<Ui::BoxContent> PrepareInviteBox(
not_null<GroupCall*> call,
Fn<void(TextWithEntities&&)> showToast,
Fn<void(Fn<void(bool)> finished)> shareConferenceLink) {
Fn<void()> shareConferenceLink) {
const auto real = call->lookupReal();
if (!real) {
return nullptr;
@ -497,8 +497,10 @@ object_ptr<Ui::BoxContent> PrepareInviteBox(
if (conference) {
const auto close = std::make_shared<Fn<void()>>();
const auto shareLink = [=] {
Assert(shareConferenceLink != nullptr);
shareConferenceLink([=](bool ok) { if (ok) (*close)(); });
Expects(shareConferenceLink != nullptr);
shareConferenceLink();
(*close)();
};
auto controller = std::make_unique<ConfInviteController>(
&real->session(),

View file

@ -80,7 +80,7 @@ private:
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareInviteBox(
not_null<GroupCall*> call,
Fn<void(TextWithEntities&&)> showToast,
Fn<void(Fn<void(bool)> finished)> shareConferenceLink = nullptr);
Fn<void()> shareConferenceLink = nullptr);
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareInviteBox(
not_null<Call*> call,

View file

@ -905,9 +905,7 @@ void Panel::setupMembers() {
}, _callLifetime);
_members->shareLinkRequests(
) | rpl::start_with_next([cb = shareConferenceLinkCallback()] {
cb(nullptr);
}, _callLifetime);
) | rpl::start_with_next(shareConferenceLinkCallback(), _callLifetime);
_call->videoEndpointLargeValue(
) | rpl::start_with_next([=](const VideoEndpoint &large) {
@ -918,23 +916,11 @@ void Panel::setupMembers() {
}, _callLifetime);
}
Fn<void(Fn<void(bool)> finished)> Panel::shareConferenceLinkCallback() {
const auto exporting = std::make_shared<bool>();
return [=](Fn<void(bool)> finished) {
Fn<void()> Panel::shareConferenceLinkCallback() {
return [=] {
Expects(_call->conference());
if (*exporting) {
return;
}
*exporting = true;
const auto done = [=](QString link) {
*exporting = false;
if (const auto onstack = finished) {
onstack(!link.isEmpty());
}
};
ExportConferenceCallLink(sessionShow(), _call->conferenceCall(), {
.finished = done,
ShowConferenceCallLinkBox(sessionShow(), _call->conferenceCall(), {
.st = DarkConferenceCallLinkStyle(),
});
};
@ -945,7 +931,6 @@ void Panel::migrationShowShareLink() {
ShowConferenceCallLinkBox(
sessionShow(),
_call->conferenceCall(),
_call->existingConferenceLink(),
{ .st = DarkConferenceCallLinkStyle() });
}

View file

@ -170,8 +170,7 @@ private:
void toggleWideControls(bool shown);
void updateWideControlsVisibility();
[[nodiscard]] bool videoButtonInNarrowMode() const;
[[nodiscard]] auto shareConferenceLinkCallback()
-> Fn<void(Fn<void(bool)> finished)>;
[[nodiscard]] Fn<void()> shareConferenceLinkCallback();
void endCall();

View file

@ -295,6 +295,10 @@ rpl::producer<int> GroupCall::fullCountValue() const {
return _fullCount.value();
}
QString GroupCall::conferenceInviteLink() const {
return _conferenceInviteLink;
}
bool GroupCall::participantsLoaded() const {
return _allParticipantsLoaded;
}
@ -515,6 +519,7 @@ void GroupCall::applyCallFields(const MTPDgroupCall &data) {
_unmutedVideoLimit = data.vunmuted_video_limit().v;
_allParticipantsLoaded
= (_serverParticipantsCount == _participants.size());
_conferenceInviteLink = qs(data.vinvite_link().value_or_empty());
}
void GroupCall::applyLocalUpdate(

View file

@ -176,6 +176,7 @@ public:
[[nodiscard]] int fullCount() const;
[[nodiscard]] rpl::producer<int> fullCountValue() const;
[[nodiscard]] QString conferenceInviteLink() const;
void setInCall();
void reload();
@ -232,6 +233,7 @@ private:
mtpRequestId _reloadRequestId = 0;
crl::time _reloadLastFinished = 0;
rpl::variable<QString> _title;
QString _conferenceInviteLink;
base::flat_multi_map<
std::pair<int, QueuedType>,

View file

@ -116,7 +116,7 @@ int AppConfig::confcallSizeLimit() const {
bool AppConfig::confcallPrioritizeVP8() const {
AssertIsDebug();
return true;
return false;
return get<bool>(u"confcall_use_vp8"_q, false);
}

View file

@ -1342,7 +1342,7 @@ peerBlocked#e8fd8014 peer_id:Peer date:int = PeerBlocked;
stats.messageStats#7fe91c14 views_graph:StatsGraph reactions_by_emotion_graph:StatsGraph = stats.MessageStats;
groupCallDiscarded#7780bcb4 id:long access_hash:long duration:int = GroupCall;
groupCall#d597650c flags:# join_muted:flags.1?true can_change_join_muted:flags.2?true join_date_asc:flags.6?true schedule_start_subscribed:flags.8?true can_start_video:flags.9?true record_video_active:flags.11?true rtmp_stream:flags.12?true listeners_hidden:flags.13?true conference:flags.14?true creator:flags.15?true id:long access_hash:long participants_count:int title:flags.3?string stream_dc_id:flags.4?int record_start_date:flags.5?int schedule_date:flags.7?int unmuted_video_count:flags.10?int unmuted_video_limit:int version:int = GroupCall;
groupCall#553b0ba1 flags:# join_muted:flags.1?true can_change_join_muted:flags.2?true join_date_asc:flags.6?true schedule_start_subscribed:flags.8?true can_start_video:flags.9?true record_video_active:flags.11?true rtmp_stream:flags.12?true listeners_hidden:flags.13?true conference:flags.14?true creator:flags.15?true id:long access_hash:long participants_count:int title:flags.3?string stream_dc_id:flags.4?int record_start_date:flags.5?int schedule_date:flags.7?int unmuted_video_count:flags.10?int unmuted_video_limit:int version:int invite_link:flags.16?string = GroupCall;
inputGroupCall#d8aa840f id:long access_hash:long = InputGroupCall;
inputGroupCallSlug#fe06823f slug:string = InputGroupCall;
@ -2587,7 +2587,7 @@ phone.setCallRating#59ead627 flags:# user_initiative:flags.0?true peer:InputPhon
phone.saveCallDebug#277add7e peer:InputPhoneCall debug:DataJSON = Bool;
phone.sendSignalingData#ff7a9383 peer:InputPhoneCall data:bytes = Bool;
phone.createGroupCall#48cdc6d8 flags:# rtmp_stream:flags.2?true peer:InputPeer random_id:int title:flags.0?string schedule_date:flags.1?int = Updates;
phone.joinGroupCall#dac17b9e flags:# muted:flags.0?true video_stopped:flags.2?true call:InputGroupCall join_as:InputPeer invite_hash:flags.1?string public_key:flags.3?int256 block:flags.3?bytes invite_msg_id:flags.4?int params:DataJSON = Updates;
phone.joinGroupCall#8fb53057 flags:# muted:flags.0?true video_stopped:flags.2?true call:InputGroupCall join_as:InputPeer invite_hash:flags.1?string public_key:flags.3?int256 block:flags.3?bytes params:DataJSON = Updates;
phone.leaveGroupCall#500377f9 call:InputGroupCall source:int = Updates;
phone.inviteToGroupCall#7b393160 call:InputGroupCall users:Vector<InputUser> = Updates;
phone.discardGroupCall#7a777135 call:InputGroupCall = Updates;
@ -2608,7 +2608,7 @@ phone.leaveGroupCallPresentation#1c50d144 call:InputGroupCall = Updates;
phone.getGroupCallStreamChannels#1ab21940 call:InputGroupCall = phone.GroupCallStreamChannels;
phone.getGroupCallStreamRtmpUrl#deb3abbf peer:InputPeer revoke:Bool = phone.GroupCallStreamRtmpUrl;
phone.saveCallLog#41248786 peer:InputPhoneCall file:InputFile = Bool;
phone.createConferenceCall#fbcefee6 random_id:int = phone.GroupCall;
phone.createConferenceCall#7d0444bb flags:# muted:flags.0?true video_stopped:flags.2?true join:flags.3?true random_id:int public_key:flags.3?int256 block:flags.3?bytes params:flags.3?DataJSON = Updates;
phone.deleteConferenceCallParticipants#8ca60525 flags:# only_left:flags.0?true kick:flags.1?true call:InputGroupCall ids:Vector<long> block:bytes = Updates;
phone.sendConferenceCallBroadcast#c6701900 call:InputGroupCall block:bytes = Updates;
phone.inviteConferenceCallParticipant#bcf22685 flags:# video:flags.0?true call:InputGroupCall user_id:InputUser = Updates;

View file

@ -128,8 +128,8 @@ constexpr auto kPlayStatusLimit = 2;
return;
}
*creating = true;
const auto finished = [=](QString link) {
if (link.isEmpty()) {
const auto finished = [=](bool ok) {
if (!ok) {
*creating = false;
} else if (const auto onstack = done) {
onstack();