mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support sharing only listener invite link.
This commit is contained in:
parent
7430fbacfd
commit
4d4a349f09
1 changed files with 59 additions and 31 deletions
|
@ -100,17 +100,21 @@ object_ptr<ShareBox> ShareInviteLinkBox(
|
||||||
const auto sending = std::make_shared<bool>();
|
const auto sending = std::make_shared<bool>();
|
||||||
const auto box = std::make_shared<QPointer<ShareBox>>();
|
const auto box = std::make_shared<QPointer<ShareBox>>();
|
||||||
|
|
||||||
auto bottom = object_ptr<Ui::PaddingWrap<Ui::Checkbox>>(
|
auto bottom = linkSpeaker.isEmpty()
|
||||||
nullptr,
|
? nullptr
|
||||||
object_ptr<Ui::Checkbox>(
|
: object_ptr<Ui::PaddingWrap<Ui::Checkbox>>(
|
||||||
nullptr,
|
nullptr,
|
||||||
tr::lng_group_call_share_listener(tr::now),
|
object_ptr<Ui::Checkbox>(
|
||||||
true,
|
nullptr,
|
||||||
st::groupCallCheckbox),
|
tr::lng_group_call_share_listener(tr::now),
|
||||||
st::groupCallShareMutedMargin);
|
true,
|
||||||
const auto listenerCheckbox = bottom->entity();
|
st::groupCallCheckbox),
|
||||||
|
st::groupCallShareMutedMargin);
|
||||||
|
const auto listenerCheckbox = bottom ? bottom->entity() : nullptr;
|
||||||
const auto currentLink = [=] {
|
const auto currentLink = [=] {
|
||||||
return listenerCheckbox->checked() ? linkListener : linkSpeaker;
|
return (!listenerCheckbox || listenerCheckbox->checked())
|
||||||
|
? linkListener
|
||||||
|
: linkSpeaker;
|
||||||
};
|
};
|
||||||
auto copyCallback = [=] {
|
auto copyCallback = [=] {
|
||||||
QGuiApplication::clipboard()->setText(currentLink());
|
QGuiApplication::clipboard()->setText(currentLink());
|
||||||
|
@ -206,6 +210,14 @@ void SettingsBox(
|
||||||
const auto weakBox = Ui::MakeWeak(box);
|
const auto weakBox = Ui::MakeWeak(box);
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
|
State(not_null<Main::Session*> session) : session(session) {
|
||||||
|
}
|
||||||
|
~State() {
|
||||||
|
session->api().request(linkListenerRequestId).cancel();
|
||||||
|
session->api().request(linkSpeakerRequestId).cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
not_null<Main::Session*> session;
|
||||||
rpl::event_stream<QString> outputNameStream;
|
rpl::event_stream<QString> outputNameStream;
|
||||||
rpl::event_stream<QString> inputNameStream;
|
rpl::event_stream<QString> inputNameStream;
|
||||||
std::unique_ptr<Webrtc::AudioInputTester> micTester;
|
std::unique_ptr<Webrtc::AudioInputTester> micTester;
|
||||||
|
@ -213,13 +225,14 @@ void SettingsBox(
|
||||||
float micLevel = 0.;
|
float micLevel = 0.;
|
||||||
Ui::Animations::Simple micLevelAnimation;
|
Ui::Animations::Simple micLevelAnimation;
|
||||||
base::Timer levelUpdateTimer;
|
base::Timer levelUpdateTimer;
|
||||||
QString linkSpeaker;
|
std::optional<QString> linkSpeaker;
|
||||||
QString linkListener;
|
QString linkListener;
|
||||||
bool generatingLink = false;
|
bool generatingLink = false;
|
||||||
|
mtpRequestId linkListenerRequestId = 0;
|
||||||
|
mtpRequestId linkSpeakerRequestId = 0;
|
||||||
};
|
};
|
||||||
const auto state = box->lifetime().make_state<State>();
|
|
||||||
|
|
||||||
const auto peer = call->peer();
|
const auto peer = call->peer();
|
||||||
|
const auto state = box->lifetime().make_state<State>(&peer->session());
|
||||||
const auto real = peer->groupCall();
|
const auto real = peer->groupCall();
|
||||||
const auto id = call->id();
|
const auto id = call->id();
|
||||||
const auto goodReal = (real && real->id() == id);
|
const auto goodReal = (real && real->id() == id);
|
||||||
|
@ -519,14 +532,17 @@ void SettingsBox(
|
||||||
//AddDivider(layout);
|
//AddDivider(layout);
|
||||||
//AddSkip(layout);
|
//AddSkip(layout);
|
||||||
|
|
||||||
|
if (!peer->canManageGroupCall()) {
|
||||||
|
state->linkSpeaker = QString();
|
||||||
|
}
|
||||||
|
|
||||||
auto shareLink = Fn<void()>();
|
auto shareLink = Fn<void()>();
|
||||||
if (peer->isChannel()
|
if (peer->isChannel()
|
||||||
&& peer->asChannel()->hasUsername()
|
&& peer->asChannel()->hasUsername()
|
||||||
&& peer->canManageGroupCall()
|
|
||||||
&& goodReal) {
|
&& goodReal) {
|
||||||
const auto input = real->input();
|
const auto input = real->input();
|
||||||
const auto shareReady = [=] {
|
const auto shareReady = [=] {
|
||||||
if (state->linkSpeaker.isEmpty()
|
if (!state->linkSpeaker.has_value()
|
||||||
|| state->linkListener.isEmpty()) {
|
|| state->linkListener.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -537,7 +553,7 @@ void SettingsBox(
|
||||||
});
|
});
|
||||||
box->getDelegate()->show(ShareInviteLinkBox(
|
box->getDelegate()->show(ShareInviteLinkBox(
|
||||||
peer,
|
peer,
|
||||||
state->linkSpeaker,
|
*state->linkSpeaker,
|
||||||
state->linkListener,
|
state->linkListener,
|
||||||
showToast));
|
showToast));
|
||||||
return true;
|
return true;
|
||||||
|
@ -547,30 +563,42 @@ void SettingsBox(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state->generatingLink = true;
|
state->generatingLink = true;
|
||||||
// #TODO calls cancel requests on box close
|
|
||||||
peer->session().api().request(MTPphone_ExportGroupCallInvite(
|
state->linkListenerRequestId = peer->session().api().request(
|
||||||
MTP_flags(0),
|
MTPphone_ExportGroupCallInvite(
|
||||||
input
|
MTP_flags(0),
|
||||||
)).done(crl::guard(box, [=](
|
input
|
||||||
|
)
|
||||||
|
).done(crl::guard(box, [=](
|
||||||
const MTPphone_ExportedGroupCallInvite &result) {
|
const MTPphone_ExportedGroupCallInvite &result) {
|
||||||
|
state->linkListenerRequestId = 0;
|
||||||
result.match([&](
|
result.match([&](
|
||||||
const MTPDphone_exportedGroupCallInvite &data) {
|
const MTPDphone_exportedGroupCallInvite &data) {
|
||||||
state->linkListener = qs(data.vlink());
|
state->linkListener = qs(data.vlink());
|
||||||
shareReady();
|
shareReady();
|
||||||
});
|
});
|
||||||
})).send();
|
})).send();
|
||||||
peer->session().api().request(MTPphone_ExportGroupCallInvite(
|
|
||||||
MTP_flags(
|
if (!state->linkSpeaker.has_value()) {
|
||||||
MTPphone_ExportGroupCallInvite::Flag::f_can_self_unmute),
|
using Flag = MTPphone_ExportGroupCallInvite::Flag;
|
||||||
input
|
state->linkSpeakerRequestId = peer->session().api().request(
|
||||||
)).done(crl::guard(box, [=](
|
MTPphone_ExportGroupCallInvite(
|
||||||
const MTPphone_ExportedGroupCallInvite &result) {
|
MTP_flags(Flag::f_can_self_unmute),
|
||||||
result.match([&](
|
input
|
||||||
const MTPDphone_exportedGroupCallInvite &data) {
|
)).done(crl::guard(box, [=](
|
||||||
state->linkSpeaker = qs(data.vlink());
|
const MTPphone_ExportedGroupCallInvite &result) {
|
||||||
|
state->linkSpeakerRequestId = 0;
|
||||||
|
result.match([&](
|
||||||
|
const MTPDphone_exportedGroupCallInvite &data) {
|
||||||
|
state->linkSpeaker = qs(data.vlink());
|
||||||
|
shareReady();
|
||||||
|
});
|
||||||
|
})).fail([=] {
|
||||||
|
state->linkSpeakerRequestId = 0;
|
||||||
|
state->linkSpeaker = QString();
|
||||||
shareReady();
|
shareReady();
|
||||||
});
|
}).send();
|
||||||
})).send();
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const auto lookupLink = [=] {
|
const auto lookupLink = [=] {
|
||||||
|
|
Loading…
Add table
Reference in a new issue