2020-11-28 14:07:36 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "calls/calls_group_settings.h"
|
|
|
|
|
2020-11-28 16:18:51 +00:00
|
|
|
#include "calls/calls_group_call.h"
|
|
|
|
#include "calls/calls_group_panel.h" // LeaveGroupCallBox.
|
|
|
|
#include "calls/calls_instance.h"
|
|
|
|
#include "ui/widgets/level_meter.h"
|
2020-12-06 12:44:20 +00:00
|
|
|
#include "ui/widgets/continuous_sliders.h"
|
2020-12-03 18:17:15 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2020-12-07 11:47:39 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2020-11-28 16:18:51 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2020-11-28 14:07:36 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2020-12-07 11:47:39 +00:00
|
|
|
#include "base/timer_rpl.h"
|
2020-12-03 22:28:52 +00:00
|
|
|
#include "base/event_filter.h"
|
2020-12-06 08:41:45 +00:00
|
|
|
#include "base/global_shortcuts.h"
|
2020-12-07 11:47:39 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2020-11-28 16:18:51 +00:00
|
|
|
#include "data/data_channel.h"
|
2020-12-14 12:52:18 +00:00
|
|
|
#include "data/data_chat.h"
|
2020-11-28 16:18:51 +00:00
|
|
|
#include "data/data_group_call.h"
|
2021-01-14 13:13:43 +00:00
|
|
|
#include "data/data_changes.h"
|
2020-11-28 16:18:51 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "boxes/single_choice_box.h"
|
|
|
|
#include "webrtc/webrtc_audio_input_tester.h"
|
|
|
|
#include "webrtc/webrtc_media_devices.h"
|
|
|
|
#include "settings/settings_common.h"
|
|
|
|
#include "settings/settings_calls.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "apiwrap.h"
|
2021-01-14 13:13:43 +00:00
|
|
|
#include "api/api_invite_links.h"
|
2020-11-28 14:07:36 +00:00
|
|
|
#include "styles/style_layers.h"
|
2020-11-28 16:18:51 +00:00
|
|
|
#include "styles/style_calls.h"
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
|
|
|
|
#include <QtGui/QGuiApplication>
|
2020-11-28 14:07:36 +00:00
|
|
|
|
|
|
|
namespace Calls {
|
2020-11-28 16:18:51 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-12-06 12:44:20 +00:00
|
|
|
constexpr auto kDelaysCount = 201;
|
2020-12-07 11:47:39 +00:00
|
|
|
constexpr auto kCheckAccessibilityInterval = crl::time(500);
|
2020-12-06 12:44:20 +00:00
|
|
|
|
2020-11-28 16:18:51 +00:00
|
|
|
void SaveCallJoinMuted(
|
2020-12-14 12:52:18 +00:00
|
|
|
not_null<PeerData*> peer,
|
2020-11-28 16:18:51 +00:00
|
|
|
uint64 callId,
|
|
|
|
bool joinMuted) {
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto call = peer->groupCall();
|
2020-11-28 16:18:51 +00:00
|
|
|
if (!call
|
|
|
|
|| call->id() != callId
|
2020-12-14 12:52:18 +00:00
|
|
|
|| !peer->canManageGroupCall()
|
2020-11-28 16:18:51 +00:00
|
|
|
|| !call->canChangeJoinMuted()
|
|
|
|
|| call->joinMuted() == joinMuted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
call->setJoinMutedLocally(joinMuted);
|
2020-12-14 12:52:18 +00:00
|
|
|
peer->session().api().request(MTPphone_ToggleGroupCallSettings(
|
2020-11-28 16:18:51 +00:00
|
|
|
MTP_flags(MTPphone_ToggleGroupCallSettings::Flag::f_join_muted),
|
|
|
|
call->input(),
|
|
|
|
MTP_bool(joinMuted)
|
|
|
|
)).send();
|
|
|
|
}
|
|
|
|
|
2020-12-06 12:44:20 +00:00
|
|
|
[[nodiscard]] crl::time DelayByIndex(int index) {
|
|
|
|
return index * crl::time(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QString FormatDelay(crl::time delay) {
|
|
|
|
return (delay < crl::time(1000))
|
|
|
|
? tr::lng_group_call_ptt_delay_ms(
|
|
|
|
tr::now,
|
|
|
|
lt_amount,
|
|
|
|
QString::number(delay))
|
|
|
|
: tr::lng_group_call_ptt_delay_s(
|
|
|
|
tr::now,
|
|
|
|
lt_amount,
|
|
|
|
QString::number(delay / 1000., 'f', 2));
|
|
|
|
}
|
|
|
|
|
2020-11-28 16:18:51 +00:00
|
|
|
} // namespace
|
2020-11-28 14:07:36 +00:00
|
|
|
|
|
|
|
void GroupCallSettingsBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
2020-11-28 16:18:51 +00:00
|
|
|
not_null<GroupCall*> call) {
|
|
|
|
using namespace Settings;
|
|
|
|
|
|
|
|
const auto weakCall = base::make_weak(call.get());
|
|
|
|
const auto weakBox = Ui::MakeWeak(box);
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
rpl::event_stream<QString> outputNameStream;
|
|
|
|
rpl::event_stream<QString> inputNameStream;
|
|
|
|
std::unique_ptr<Webrtc::AudioInputTester> micTester;
|
|
|
|
Ui::LevelMeter *micTestLevel = nullptr;
|
|
|
|
float micLevel = 0.;
|
|
|
|
Ui::Animations::Simple micLevelAnimation;
|
|
|
|
base::Timer levelUpdateTimer;
|
|
|
|
bool generatingLink = false;
|
|
|
|
};
|
|
|
|
const auto state = box->lifetime().make_state<State>();
|
|
|
|
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto peer = call->peer();
|
|
|
|
const auto real = peer->groupCall();
|
2020-11-28 16:18:51 +00:00
|
|
|
const auto id = call->id();
|
|
|
|
const auto goodReal = (real && real->id() == id);
|
|
|
|
|
|
|
|
const auto layout = box->verticalLayout();
|
|
|
|
const auto &settings = Core::App().settings();
|
|
|
|
|
|
|
|
const auto joinMuted = goodReal ? real->joinMuted() : false;
|
|
|
|
const auto canChangeJoinMuted = (goodReal && real->canChangeJoinMuted());
|
2020-12-14 12:52:18 +00:00
|
|
|
const auto addCheck = (peer->canManageGroupCall() && canChangeJoinMuted);
|
2020-11-30 08:00:25 +00:00
|
|
|
if (addCheck) {
|
|
|
|
AddSkip(layout);
|
|
|
|
}
|
|
|
|
const auto muteJoined = addCheck
|
2020-12-03 18:17:15 +00:00
|
|
|
? AddButton(
|
|
|
|
layout,
|
2020-11-28 16:18:51 +00:00
|
|
|
tr::lng_group_call_new_muted(),
|
2020-12-03 18:17:15 +00:00
|
|
|
st::groupCallSettingsButton)->toggleOn(rpl::single(joinMuted))
|
2020-11-28 16:18:51 +00:00
|
|
|
: nullptr;
|
2020-11-30 08:00:25 +00:00
|
|
|
if (addCheck) {
|
2020-11-28 16:18:51 +00:00
|
|
|
AddSkip(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddButtonWithLabel(
|
|
|
|
layout,
|
|
|
|
tr::lng_group_call_speakers(),
|
|
|
|
rpl::single(
|
|
|
|
CurrentAudioOutputName()
|
|
|
|
) | rpl::then(
|
|
|
|
state->outputNameStream.events()
|
|
|
|
),
|
2020-11-29 18:26:49 +00:00
|
|
|
st::groupCallSettingsButton
|
2020-11-28 16:18:51 +00:00
|
|
|
)->addClickHandler([=] {
|
2020-11-30 15:51:04 +00:00
|
|
|
box->getDelegate()->show(ChooseAudioOutputBox(crl::guard(box, [=](
|
2020-11-28 16:18:51 +00:00
|
|
|
const QString &id,
|
|
|
|
const QString &name) {
|
|
|
|
state->outputNameStream.fire_copy(name);
|
2020-11-29 18:26:49 +00:00
|
|
|
}), &st::groupCallCheckbox, &st::groupCallRadio));
|
2020-11-28 16:18:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddButtonWithLabel(
|
|
|
|
layout,
|
|
|
|
tr::lng_group_call_microphone(),
|
|
|
|
rpl::single(
|
|
|
|
CurrentAudioInputName()
|
|
|
|
) | rpl::then(
|
|
|
|
state->inputNameStream.events()
|
|
|
|
),
|
2020-11-29 18:26:49 +00:00
|
|
|
st::groupCallSettingsButton
|
2020-11-28 16:18:51 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
box->getDelegate()->show(ChooseAudioInputBox(crl::guard(box, [=](
|
|
|
|
const QString &id,
|
|
|
|
const QString &name) {
|
|
|
|
state->inputNameStream.fire_copy(name);
|
2020-11-30 18:08:27 +00:00
|
|
|
if (state->micTester) {
|
|
|
|
state->micTester->setDeviceId(id);
|
|
|
|
}
|
2020-11-29 18:26:49 +00:00
|
|
|
}), &st::groupCallCheckbox, &st::groupCallRadio));
|
2020-11-28 16:18:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
state->micTestLevel = box->addRow(
|
|
|
|
object_ptr<Ui::LevelMeter>(
|
|
|
|
box.get(),
|
2020-11-29 18:26:49 +00:00
|
|
|
st::groupCallLevelMeter),
|
2020-11-28 16:18:51 +00:00
|
|
|
st::settingsLevelMeterPadding);
|
|
|
|
state->micTestLevel->resize(QSize(0, st::defaultLevelMeter.height));
|
|
|
|
|
|
|
|
state->levelUpdateTimer.setCallback([=] {
|
|
|
|
const auto was = state->micLevel;
|
|
|
|
state->micLevel = state->micTester->getAndResetLevel();
|
|
|
|
state->micLevelAnimation.start([=] {
|
|
|
|
state->micTestLevel->setValue(
|
|
|
|
state->micLevelAnimation.value(state->micLevel));
|
|
|
|
}, was, state->micLevel, kMicTestAnimationDuration);
|
2020-11-28 14:07:36 +00:00
|
|
|
});
|
2020-11-28 16:18:51 +00:00
|
|
|
|
|
|
|
AddSkip(layout);
|
2020-12-03 18:17:15 +00:00
|
|
|
//AddDivider(layout);
|
|
|
|
//AddSkip(layout);
|
|
|
|
|
2020-12-06 08:41:45 +00:00
|
|
|
using GlobalShortcut = base::GlobalShortcut;
|
2020-12-03 18:17:15 +00:00
|
|
|
struct PushToTalkState {
|
|
|
|
rpl::variable<QString> recordText = tr::lng_group_call_ptt_shortcut();
|
|
|
|
rpl::variable<QString> shortcutText;
|
2020-12-07 11:47:39 +00:00
|
|
|
rpl::event_stream<bool> pushToTalkToggles;
|
|
|
|
std::shared_ptr<base::GlobalShortcutManager> manager;
|
2020-12-03 18:17:15 +00:00
|
|
|
GlobalShortcut shortcut;
|
2020-12-06 12:44:20 +00:00
|
|
|
crl::time delay = 0;
|
2020-12-03 18:17:15 +00:00
|
|
|
bool recording = false;
|
|
|
|
};
|
2020-12-07 11:47:39 +00:00
|
|
|
if (base::GlobalShortcutsAvailable()) {
|
2020-12-03 18:17:15 +00:00
|
|
|
const auto state = box->lifetime().make_state<PushToTalkState>();
|
2020-12-07 11:47:39 +00:00
|
|
|
if (!base::GlobalShortcutsAllowed()) {
|
|
|
|
Core::App().settings().setGroupCallPushToTalk(false);
|
|
|
|
}
|
|
|
|
const auto tryFillFromManager = [=] {
|
|
|
|
state->shortcut = state->manager
|
|
|
|
? state->manager->shortcutFromSerialized(
|
|
|
|
Core::App().settings().groupCallPushToTalkShortcut())
|
|
|
|
: nullptr;
|
|
|
|
state->shortcutText = state->shortcut
|
|
|
|
? state->shortcut->toDisplayString()
|
|
|
|
: QString();
|
|
|
|
};
|
|
|
|
state->manager = settings.groupCallPushToTalk()
|
|
|
|
? call->ensureGlobalShortcutManager()
|
|
|
|
: nullptr;
|
|
|
|
tryFillFromManager();
|
|
|
|
|
2020-12-06 12:44:20 +00:00
|
|
|
state->delay = settings.groupCallPushToTalkDelay();
|
2020-12-03 18:17:15 +00:00
|
|
|
const auto pushToTalk = AddButton(
|
|
|
|
layout,
|
|
|
|
tr::lng_group_call_push_to_talk(),
|
|
|
|
st::groupCallSettingsButton
|
2020-12-07 11:47:39 +00:00
|
|
|
)->toggleOn(rpl::single(
|
|
|
|
settings.groupCallPushToTalk()
|
|
|
|
) | rpl::then(state->pushToTalkToggles.events()));
|
2020-12-06 15:13:18 +00:00
|
|
|
const auto pushToTalkWrap = layout->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
2020-12-03 18:17:15 +00:00
|
|
|
layout,
|
2020-12-06 15:13:18 +00:00
|
|
|
object_ptr<Ui::VerticalLayout>(layout)));
|
|
|
|
const auto pushToTalkInner = pushToTalkWrap->entity();
|
|
|
|
const auto recording = pushToTalkInner->add(
|
|
|
|
object_ptr<Button>(
|
|
|
|
layout,
|
|
|
|
state->recordText.value(),
|
|
|
|
st::groupCallSettingsButton));
|
2020-12-03 18:17:15 +00:00
|
|
|
CreateRightLabel(
|
|
|
|
recording,
|
|
|
|
state->shortcutText.value(),
|
|
|
|
st::groupCallSettingsButton,
|
|
|
|
state->recordText.value());
|
2020-12-06 15:13:18 +00:00
|
|
|
|
|
|
|
const auto applyAndSave = [=] {
|
|
|
|
call->applyGlobalShortcutChanges();
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
};
|
2020-12-07 11:47:39 +00:00
|
|
|
const auto showPrivacyRequest = [=] {
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
if (!Platform::IsMac10_14OrGreater()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto requestInputMonitoring = Platform::IsMac10_15OrGreater();
|
|
|
|
box->getDelegate()->show(Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
box->addRow(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
box.get(),
|
|
|
|
rpl::combine(
|
|
|
|
tr::lng_group_call_mac_access(),
|
|
|
|
(requestInputMonitoring
|
|
|
|
? tr::lng_group_call_mac_input()
|
|
|
|
: tr::lng_group_call_mac_accessibility())
|
|
|
|
) | rpl::map([](QString a, QString b) {
|
|
|
|
auto result = Ui::Text::RichLangValue(a);
|
|
|
|
result.append("\n\n").append(Ui::Text::RichLangValue(b));
|
|
|
|
return result;
|
|
|
|
}),
|
|
|
|
st::groupCallBoxLabel),
|
|
|
|
style::margins(
|
|
|
|
st::boxRowPadding.left(),
|
|
|
|
st::boxPadding.top(),
|
|
|
|
st::boxRowPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
box->addButton(tr::lng_group_call_mac_settings(), [=] {
|
|
|
|
if (requestInputMonitoring) {
|
|
|
|
Platform::OpenInputMonitoringPrivacySettings();
|
|
|
|
} else {
|
|
|
|
Platform::OpenAccessibilityPrivacySettings();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
|
|
|
|
if (!requestInputMonitoring) {
|
|
|
|
// Accessibility is enabled without app restart, so short-poll it.
|
|
|
|
base::timer_each(
|
|
|
|
kCheckAccessibilityInterval
|
|
|
|
) | rpl::filter([] {
|
|
|
|
return base::GlobalShortcutsAllowed();
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
box->closeBox();
|
|
|
|
}, box->lifetime());
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
#endif // Q_OS_MAC
|
|
|
|
};
|
|
|
|
const auto ensureManager = [=] {
|
|
|
|
if (state->manager) {
|
|
|
|
return true;
|
|
|
|
} else if (base::GlobalShortcutsAllowed()) {
|
|
|
|
state->manager = call->ensureGlobalShortcutManager();
|
|
|
|
tryFillFromManager();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
showPrivacyRequest();
|
|
|
|
return false;
|
|
|
|
};
|
2020-12-06 15:13:18 +00:00
|
|
|
const auto stopRecording = [=] {
|
|
|
|
state->recording = false;
|
|
|
|
state->recordText = tr::lng_group_call_ptt_shortcut();
|
|
|
|
state->shortcutText = state->shortcut
|
|
|
|
? state->shortcut->toDisplayString()
|
|
|
|
: QString();
|
|
|
|
recording->setColorOverride(std::nullopt);
|
2020-12-07 11:47:39 +00:00
|
|
|
if (state->manager) {
|
|
|
|
state->manager->stopRecording();
|
|
|
|
}
|
2020-12-06 15:13:18 +00:00
|
|
|
};
|
2020-12-03 18:17:15 +00:00
|
|
|
const auto startRecording = [=] {
|
2020-12-07 11:47:39 +00:00
|
|
|
if (!ensureManager()) {
|
|
|
|
state->pushToTalkToggles.fire(false);
|
|
|
|
pushToTalkWrap->hide(anim::type::instant);
|
|
|
|
return;
|
|
|
|
}
|
2020-12-03 18:17:15 +00:00
|
|
|
state->recording = true;
|
|
|
|
state->recordText = tr::lng_group_call_ptt_recording();
|
2020-12-06 15:13:18 +00:00
|
|
|
recording->setColorOverride(
|
|
|
|
st::groupCallSettingsAttentionButton.textFg->c);
|
2020-12-03 22:01:14 +00:00
|
|
|
auto progress = crl::guard(box, [=](GlobalShortcut shortcut) {
|
2020-12-03 18:17:15 +00:00
|
|
|
state->shortcutText = shortcut->toDisplayString();
|
2020-12-03 22:01:14 +00:00
|
|
|
});
|
|
|
|
auto done = crl::guard(box, [=](GlobalShortcut shortcut) {
|
2020-12-03 18:17:15 +00:00
|
|
|
state->shortcut = shortcut;
|
|
|
|
Core::App().settings().setGroupCallPushToTalkShortcut(shortcut
|
|
|
|
? shortcut->serialize()
|
|
|
|
: QByteArray());
|
2020-12-06 15:13:18 +00:00
|
|
|
applyAndSave();
|
|
|
|
stopRecording();
|
2020-12-03 18:17:15 +00:00
|
|
|
});
|
2020-12-07 11:47:39 +00:00
|
|
|
state->manager->startRecording(std::move(progress), std::move(done));
|
2020-12-03 18:17:15 +00:00
|
|
|
};
|
|
|
|
recording->addClickHandler([=] {
|
|
|
|
if (state->recording) {
|
|
|
|
stopRecording();
|
|
|
|
} else {
|
|
|
|
startRecording();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-06 15:13:18 +00:00
|
|
|
const auto label = pushToTalkInner->add(
|
|
|
|
object_ptr<Ui::LabelSimple>(
|
|
|
|
pushToTalkInner,
|
|
|
|
st::groupCallDelayLabel),
|
2020-12-06 12:44:20 +00:00
|
|
|
st::groupCallDelayLabelMargin);
|
|
|
|
const auto value = std::clamp(
|
|
|
|
state->delay,
|
|
|
|
crl::time(0),
|
|
|
|
DelayByIndex(kDelaysCount - 1));
|
|
|
|
const auto callback = [=](crl::time delay) {
|
|
|
|
state->delay = delay;
|
|
|
|
label->setText(tr::lng_group_call_ptt_delay(
|
|
|
|
tr::now,
|
|
|
|
lt_delay,
|
|
|
|
FormatDelay(delay)));
|
|
|
|
Core::App().settings().setGroupCallPushToTalkDelay(delay);
|
2020-12-06 15:13:18 +00:00
|
|
|
applyAndSave();
|
2020-12-06 12:44:20 +00:00
|
|
|
};
|
|
|
|
callback(value);
|
2020-12-06 15:13:18 +00:00
|
|
|
const auto slider = pushToTalkInner->add(
|
|
|
|
object_ptr<Ui::MediaSlider>(
|
|
|
|
pushToTalkInner,
|
|
|
|
st::groupCallDelaySlider),
|
2020-12-06 12:44:20 +00:00
|
|
|
st::groupCallDelayMargin);
|
|
|
|
slider->resize(st::groupCallDelaySlider.seekSize);
|
|
|
|
slider->setPseudoDiscrete(
|
|
|
|
kDelaysCount,
|
|
|
|
DelayByIndex,
|
|
|
|
value,
|
|
|
|
callback);
|
|
|
|
|
2020-12-06 15:13:18 +00:00
|
|
|
pushToTalkWrap->toggle(
|
|
|
|
settings.groupCallPushToTalk(),
|
|
|
|
anim::type::instant);
|
|
|
|
pushToTalk->toggledChanges(
|
|
|
|
) | rpl::start_with_next([=](bool toggled) {
|
|
|
|
if (!toggled) {
|
|
|
|
stopRecording();
|
2020-12-07 11:47:39 +00:00
|
|
|
} else if (!ensureManager()) {
|
|
|
|
state->pushToTalkToggles.fire(false);
|
|
|
|
pushToTalkWrap->hide(anim::type::instant);
|
|
|
|
return;
|
2020-12-06 15:13:18 +00:00
|
|
|
}
|
|
|
|
Core::App().settings().setGroupCallPushToTalk(toggled);
|
|
|
|
applyAndSave();
|
|
|
|
pushToTalkWrap->toggle(toggled, anim::type::normal);
|
|
|
|
}, pushToTalk->lifetime());
|
2020-12-03 22:28:52 +00:00
|
|
|
|
|
|
|
auto boxKeyFilter = [=](not_null<QEvent*> e) {
|
2020-12-06 12:44:20 +00:00
|
|
|
return (e->type() == QEvent::KeyPress && state->recording)
|
2020-12-03 22:28:52 +00:00
|
|
|
? base::EventFilterResult::Cancel
|
|
|
|
: base::EventFilterResult::Continue;
|
|
|
|
};
|
|
|
|
box->lifetime().make_state<base::unique_qptr<QObject>>(
|
|
|
|
base::install_event_filter(box, std::move(boxKeyFilter)));
|
2020-12-03 18:17:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AddSkip(layout);
|
|
|
|
//AddDivider(layout);
|
|
|
|
//AddSkip(layout);
|
2020-11-28 16:18:51 +00:00
|
|
|
|
|
|
|
const auto lookupLink = [=] {
|
2020-12-14 12:52:18 +00:00
|
|
|
if (const auto group = peer->asMegagroup()) {
|
|
|
|
return group->hasUsername()
|
|
|
|
? group->session().createInternalLinkFull(group->username)
|
|
|
|
: group->inviteLink();
|
|
|
|
} else if (const auto chat = peer->asChat()) {
|
|
|
|
return chat->inviteLink();
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
};
|
|
|
|
const auto canCreateLink = [&] {
|
|
|
|
if (const auto chat = peer->asChat()) {
|
|
|
|
return chat->canHaveInviteLink();
|
|
|
|
} else if (const auto group = peer->asMegagroup()) {
|
|
|
|
return group->canHaveInviteLink();
|
|
|
|
}
|
|
|
|
return false;
|
2020-11-28 16:18:51 +00:00
|
|
|
};
|
2020-12-14 12:52:18 +00:00
|
|
|
if (!lookupLink().isEmpty() || canCreateLink()) {
|
2020-11-28 16:18:51 +00:00
|
|
|
const auto copyLink = [=] {
|
|
|
|
const auto link = lookupLink();
|
|
|
|
if (link.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QGuiApplication::clipboard()->setText(link);
|
|
|
|
if (weakBox) {
|
|
|
|
Ui::Toast::Show(
|
|
|
|
box->getDelegate()->outerContainer(),
|
|
|
|
tr::lng_create_channel_link_copied(tr::now));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
AddButton(
|
|
|
|
layout,
|
|
|
|
tr::lng_group_call_share(),
|
2020-11-29 18:26:49 +00:00
|
|
|
st::groupCallSettingsButton
|
2020-11-28 16:18:51 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
if (!copyLink() && !state->generatingLink) {
|
|
|
|
state->generatingLink = true;
|
2021-01-14 13:13:43 +00:00
|
|
|
peer->session().api().inviteLinks().create(
|
|
|
|
peer,
|
|
|
|
crl::guard(layout, [=](auto&&) { copyLink(); }));
|
2020-11-28 16:18:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:52:18 +00:00
|
|
|
if (peer->canManageGroupCall()) {
|
2020-11-28 16:18:51 +00:00
|
|
|
AddButton(
|
|
|
|
layout,
|
|
|
|
tr::lng_group_call_end(),
|
2020-11-29 18:26:49 +00:00
|
|
|
st::groupCallSettingsAttentionButton
|
2020-11-28 16:18:51 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
if (const auto call = weakCall.get()) {
|
|
|
|
box->getDelegate()->show(Box(
|
|
|
|
LeaveGroupCallBox,
|
|
|
|
call,
|
|
|
|
true,
|
|
|
|
BoxContext::GroupCallPanel));
|
|
|
|
box->closeBox();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-30 18:08:27 +00:00
|
|
|
box->setShowFinishedCallback([=] {
|
|
|
|
// Means we finished showing the box.
|
|
|
|
crl::on_main(box, [=] {
|
|
|
|
state->micTester = std::make_unique<Webrtc::AudioInputTester>(
|
2021-01-07 15:27:11 +00:00
|
|
|
Core::App().settings().callAudioBackend(),
|
2020-11-30 18:08:27 +00:00
|
|
|
Core::App().settings().callInputDeviceId());
|
|
|
|
state->levelUpdateTimer.callEach(kMicTestUpdateInterval);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-28 16:18:51 +00:00
|
|
|
box->setTitle(tr::lng_group_call_settings_title());
|
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (canChangeJoinMuted
|
|
|
|
&& muteJoined
|
2020-12-03 18:17:15 +00:00
|
|
|
&& muteJoined->toggled() != joinMuted) {
|
2020-12-14 12:52:18 +00:00
|
|
|
SaveCallJoinMuted(peer, id, muteJoined->toggled());
|
2020-11-28 16:18:51 +00:00
|
|
|
}
|
|
|
|
}, box->lifetime());
|
|
|
|
box->addButton(tr::lng_box_done(), [=] {
|
2020-11-28 14:07:36 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Calls
|