Allow disabling calls on tdesktop device.

This commit is contained in:
John Preston 2021-01-26 15:58:30 +04:00
parent ce5c19dfe9
commit 7da224d725
6 changed files with 52 additions and 13 deletions

View File

@ -328,6 +328,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_events_title" = "Events";
"lng_settings_events_joined" = "Contact joined Telegram";
"lng_settings_events_pinned" = "Pinned messages";
"lng_settings_notifications_calls_title" = "Calls";
"lng_notification_preview" = "You have a new message";
"lng_notification_reply" = "Reply";
@ -395,6 +396,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_call_stop_mic_test" = "Stop test";
"lng_settings_call_section_other" = "Other settings";
"lng_settings_call_open_system_prefs" = "Open system sound preferences";
"lng_settings_call_accept_calls" = "Accept calls from this device";
"lng_settings_call_device_default" = "Same as the System";
"lng_settings_call_audio_ducking" = "Mute other sounds during calls";

View File

@ -377,6 +377,8 @@ void Instance::handleCallUpdate(
} else if (phoneCall.vdate().v + (config.callRingTimeoutMs / 1000)
< base::unixtime::now()) {
LOG(("Ignoring too old call."));
} else if (Core::App().settings().disableCalls()) {
LOG(("Ignoring call because of 'accept calls' settings."));
} else {
createCall(user, Call::Type::Incoming, phoneCall.is_video());
_currentCall->handleUpdate(call);

View File

@ -19,8 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Core {
Settings::Settings()
: _callAudioBackend(Webrtc::Backend::OpenAL)
, _sendSubmitWay(Ui::InputSubmitSettings::Enter)
: _sendSubmitWay(Ui::InputSubmitSettings::Enter)
, _floatPlayerColumn(Window::Column::Second)
, _floatPlayerCorner(RectPart::TopRight)
, _dialogsWidthRatio(DefaultDialogsWidthRatio()) {
@ -115,7 +114,8 @@ QByteArray Settings::serialize() const {
<< qint32(_groupCallPushToTalk ? 1 : 0)
<< _groupCallPushToTalkShortcut
<< qint64(_groupCallPushToTalkDelay)
<< qint32(_callAudioBackend);
<< qint32(0) // Call audio backend
<< qint32(_disableCalls ? 1 : 0);
}
return result;
}
@ -186,7 +186,8 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
qint32 groupCallPushToTalk = _groupCallPushToTalk ? 1 : 0;
QByteArray groupCallPushToTalkShortcut = _groupCallPushToTalkShortcut;
qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay;
qint32 callAudioBackend = static_cast<qint32>(_callAudioBackend);
qint32 callAudioBackend = 0;
qint32 disableCalls = _disableCalls ? 1 : 0;
stream >> themesAccentColors;
if (!stream.atEnd()) {
@ -285,6 +286,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
if (!stream.atEnd()) {
stream >> callAudioBackend;
}
if (!stream.atEnd()) {
stream >> disableCalls;
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for Core::Settings::constructFromSerialized()"));
@ -379,12 +383,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
_groupCallPushToTalk = (groupCallPushToTalk == 1);
_groupCallPushToTalkShortcut = groupCallPushToTalkShortcut;
_groupCallPushToTalkDelay = groupCallPushToTalkDelay;
auto uncheckedBackend = static_cast<Webrtc::Backend>(callAudioBackend);
switch (uncheckedBackend) {
case Webrtc::Backend::OpenAL:
case Webrtc::Backend::ADM:
case Webrtc::Backend::ADM2: _callAudioBackend = uncheckedBackend; break;
}
_disableCalls = (disableCalls == 1);
}
bool Settings::chatWide() const {
@ -495,6 +494,8 @@ void Settings::resetOnLastLogout() {
//_callInputVolume = 100;
//_callAudioDuckingEnabled = true;
_disableCalls = false;
_groupCallPushToTalk = false;
_groupCallPushToTalkShortcut = QByteArray();
_groupCallPushToTalkDelay = 20;

View File

@ -222,8 +222,11 @@ public:
_callAudioDuckingEnabled = value;
}
[[nodiscard]] Webrtc::Backend callAudioBackend() const;
void setCallAudioBackend(Webrtc::Backend backend) {
_callAudioBackend = backend;
void setDisableCalls(bool value) {
_disableCalls = value;
}
[[nodiscard]] bool disableCalls() const {
return _disableCalls;
}
[[nodiscard]] bool groupCallPushToTalk() const {
return _groupCallPushToTalk;
@ -539,7 +542,7 @@ private:
int _callOutputVolume = 100;
int _callInputVolume = 100;
bool _callAudioDuckingEnabled = true;
Webrtc::Backend _callAudioBackend = Webrtc::Backend();
bool _disableCalls = false;
bool _groupCallPushToTalk = false;
QByteArray _groupCallPushToTalkShortcut;
crl::time _groupCallPushToTalkDelay = 20;

View File

@ -275,6 +275,19 @@ void Calls::setupContent() {
//)->addClickHandler([] {
// Ui::show(ChooseAudioBackendBox());
//});
AddButton(
content,
tr::lng_settings_call_accept_calls(),
st::settingsButton
)->toggleOn(rpl::single(
!settings.disableCalls()
))->toggledChanges(
) | rpl::filter([&settings](bool value) {
return (settings.disableCalls() == value);
}) | rpl::start_with_next([=](bool value) {
Core::App().settings().setDisableCalls(!value);
Core::App().saveSettingsDelayed();
}, content->lifetime());
AddButton(
content,
tr::lng_settings_call_open_system_prefs(),
@ -286,6 +299,7 @@ void Calls::setupContent() {
Ui::show(Box<InformBox>(tr::lng_linux_no_audio_prefs(tr::now)));
}
});
AddSkip(content);
Ui::ResizeFitChild(this, content);

View File

@ -676,6 +676,23 @@ void SetupNotificationsContent(
Core::App().saveSettingsDelayed();
}, joined->lifetime());
AddSkip(container, st::settingsCheckboxesSkip);
AddDivider(container);
AddSkip(container, st::settingsCheckboxesSkip);
AddSubsectionTitle(
container,
tr::lng_settings_notifications_calls_title());
addCheckbox(
tr::lng_settings_call_accept_calls(tr::now),
!settings.disableCalls()
)->checkedChanges(
) | rpl::filter([&settings](bool value) {
return (settings.disableCalls() == value);
}) | rpl::start_with_next([=](bool value) {
Core::App().settings().setDisableCalls(!value);
Core::App().saveSettingsDelayed();
}, container->lifetime());
const auto nativeText = [&] {
if (!Platform::Notifications::Supported()
|| Platform::Notifications::Enforced()) {