mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use cloud "disable calls" settings instead of local.
This commit is contained in:
parent
598cec8a9d
commit
8264968718
7 changed files with 81 additions and 29 deletions
|
@ -104,6 +104,10 @@ Authorizations::Authorizations(not_null<ApiWrap*> api)
|
||||||
_listChanges.fire({});
|
_listChanges.fire({});
|
||||||
}
|
}
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
|
||||||
|
if (Core::App().settings().disableCallsLegacy()) {
|
||||||
|
toggleCallsDisabledHere(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Authorizations::reload() {
|
void Authorizations::reload() {
|
||||||
|
@ -198,6 +202,39 @@ rpl::producer<int> Authorizations::ttlDays() const {
|
||||||
return _ttlDays.value() | rpl::filter(rpl::mappers::_1 != 0);
|
return _ttlDays.value() | rpl::filter(rpl::mappers::_1 != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Authorizations::toggleCallsDisabled(uint64 hash, bool disabled) {
|
||||||
|
if (const auto sent = _toggleCallsDisabledRequests.take(hash)) {
|
||||||
|
_api.request(*sent).cancel();
|
||||||
|
}
|
||||||
|
using Flag = MTPaccount_ChangeAuthorizationSettings::Flag;
|
||||||
|
const auto id = _api.request(MTPaccount_ChangeAuthorizationSettings(
|
||||||
|
MTP_flags(Flag::f_call_requests_disabled),
|
||||||
|
MTP_long(hash),
|
||||||
|
MTPBool(), // encrypted_requests_disabled
|
||||||
|
MTP_bool(disabled)
|
||||||
|
)).done([=](const MTPBool &) {
|
||||||
|
_toggleCallsDisabledRequests.remove(hash);
|
||||||
|
}).fail([=](const MTP::Error &) {
|
||||||
|
_toggleCallsDisabledRequests.remove(hash);
|
||||||
|
}).send();
|
||||||
|
_toggleCallsDisabledRequests.emplace(hash, id);
|
||||||
|
if (!hash) {
|
||||||
|
_callsDisabledHere = disabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Authorizations::callsDisabledHere() const {
|
||||||
|
return _callsDisabledHere.current();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<bool> Authorizations::callsDisabledHereValue() const {
|
||||||
|
return _callsDisabledHere.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<bool> Authorizations::callsDisabledHereChanges() const {
|
||||||
|
return _callsDisabledHere.changes();
|
||||||
|
}
|
||||||
|
|
||||||
int Authorizations::total() const {
|
int Authorizations::total() const {
|
||||||
return ranges::count_if(
|
return ranges::count_if(
|
||||||
_list,
|
_list,
|
||||||
|
|
|
@ -43,6 +43,14 @@ public:
|
||||||
void updateTTL(int days);
|
void updateTTL(int days);
|
||||||
[[nodiscard]] rpl::producer<int> ttlDays() const;
|
[[nodiscard]] rpl::producer<int> ttlDays() const;
|
||||||
|
|
||||||
|
void toggleCallsDisabledHere(bool disabled) {
|
||||||
|
toggleCallsDisabled(0, disabled);
|
||||||
|
}
|
||||||
|
void toggleCallsDisabled(uint64 hash, bool disabled);
|
||||||
|
[[nodiscard]] bool callsDisabledHere() const;
|
||||||
|
[[nodiscard]] rpl::producer<bool> callsDisabledHereValue() const;
|
||||||
|
[[nodiscard]] rpl::producer<bool> callsDisabledHereChanges() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _requestId = 0;
|
||||||
|
@ -53,6 +61,9 @@ private:
|
||||||
mtpRequestId _ttlRequestId = 0;
|
mtpRequestId _ttlRequestId = 0;
|
||||||
rpl::variable<int> _ttlDays = 0;
|
rpl::variable<int> _ttlDays = 0;
|
||||||
|
|
||||||
|
base::flat_map<uint64, mtpRequestId> _toggleCallsDisabledRequests;
|
||||||
|
rpl::variable<bool> _callsDisabledHere;
|
||||||
|
|
||||||
crl::time _lastReceived = 0;
|
crl::time _lastReceived = 0;
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
|
|
|
@ -503,8 +503,6 @@ void Instance::handleCallUpdate(
|
||||||
} else if (phoneCall.vdate().v + (config.callRingTimeoutMs / 1000)
|
} else if (phoneCall.vdate().v + (config.callRingTimeoutMs / 1000)
|
||||||
< base::unixtime::now()) {
|
< base::unixtime::now()) {
|
||||||
LOG(("Ignoring too old call."));
|
LOG(("Ignoring too old call."));
|
||||||
} else if (Core::App().settings().disableCalls()) {
|
|
||||||
LOG(("Ignoring call because of 'accept calls' settings."));
|
|
||||||
} else {
|
} else {
|
||||||
createCall(user, Call::Type::Incoming, phoneCall.is_video());
|
createCall(user, Call::Type::Incoming, phoneCall.is_video());
|
||||||
_currentCall->handleUpdate(call);
|
_currentCall->handleUpdate(call);
|
||||||
|
|
|
@ -203,7 +203,7 @@ QByteArray Settings::serialize() const {
|
||||||
<< _groupCallPushToTalkShortcut
|
<< _groupCallPushToTalkShortcut
|
||||||
<< qint64(_groupCallPushToTalkDelay)
|
<< qint64(_groupCallPushToTalkDelay)
|
||||||
<< qint32(0) // Call audio backend
|
<< qint32(0) // Call audio backend
|
||||||
<< qint32(_disableCalls ? 1 : 0)
|
<< qint32(0) // Legacy disable calls, now in session settings
|
||||||
<< windowPosition
|
<< windowPosition
|
||||||
<< qint32(recentEmojiPreloadData.size());
|
<< qint32(recentEmojiPreloadData.size());
|
||||||
for (const auto &[id, rating] : recentEmojiPreloadData) {
|
for (const auto &[id, rating] : recentEmojiPreloadData) {
|
||||||
|
@ -300,7 +300,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
QByteArray groupCallPushToTalkShortcut = _groupCallPushToTalkShortcut;
|
QByteArray groupCallPushToTalkShortcut = _groupCallPushToTalkShortcut;
|
||||||
qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay;
|
qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay;
|
||||||
qint32 callAudioBackend = 0;
|
qint32 callAudioBackend = 0;
|
||||||
qint32 disableCalls = _disableCalls ? 1 : 0;
|
qint32 disableCallsLegacy = 0;
|
||||||
QByteArray windowPosition;
|
QByteArray windowPosition;
|
||||||
std::vector<RecentEmojiId> recentEmojiPreload;
|
std::vector<RecentEmojiId> recentEmojiPreload;
|
||||||
base::flat_map<QString, uint8> emojiVariants;
|
base::flat_map<QString, uint8> emojiVariants;
|
||||||
|
@ -413,7 +413,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
stream >> callAudioBackend;
|
stream >> callAudioBackend;
|
||||||
}
|
}
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
stream >> disableCalls;
|
stream >> disableCallsLegacy;
|
||||||
}
|
}
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
stream >> windowPosition;
|
stream >> windowPosition;
|
||||||
|
@ -593,7 +593,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||||
_groupCallPushToTalk = (groupCallPushToTalk == 1);
|
_groupCallPushToTalk = (groupCallPushToTalk == 1);
|
||||||
_groupCallPushToTalkShortcut = groupCallPushToTalkShortcut;
|
_groupCallPushToTalkShortcut = groupCallPushToTalkShortcut;
|
||||||
_groupCallPushToTalkDelay = groupCallPushToTalkDelay;
|
_groupCallPushToTalkDelay = groupCallPushToTalkDelay;
|
||||||
_disableCalls = (disableCalls == 1);
|
_disableCallsLegacy = (disableCallsLegacy == 1);
|
||||||
if (!windowPosition.isEmpty()) {
|
if (!windowPosition.isEmpty()) {
|
||||||
_windowPosition = Deserialize(windowPosition);
|
_windowPosition = Deserialize(windowPosition);
|
||||||
}
|
}
|
||||||
|
@ -870,7 +870,7 @@ void Settings::resetOnLastLogout() {
|
||||||
//_callInputVolume = 100;
|
//_callInputVolume = 100;
|
||||||
//_callAudioDuckingEnabled = true;
|
//_callAudioDuckingEnabled = true;
|
||||||
|
|
||||||
_disableCalls = false;
|
_disableCallsLegacy = false;
|
||||||
|
|
||||||
_groupCallPushToTalk = false;
|
_groupCallPushToTalk = false;
|
||||||
_groupCallPushToTalkShortcut = QByteArray();
|
_groupCallPushToTalkShortcut = QByteArray();
|
||||||
|
|
|
@ -265,11 +265,8 @@ public:
|
||||||
_callAudioDuckingEnabled = value;
|
_callAudioDuckingEnabled = value;
|
||||||
}
|
}
|
||||||
[[nodiscard]] Webrtc::Backend callAudioBackend() const;
|
[[nodiscard]] Webrtc::Backend callAudioBackend() const;
|
||||||
void setDisableCalls(bool value) {
|
[[nodiscard]] bool disableCallsLegacy() const {
|
||||||
_disableCalls = value;
|
return _disableCallsLegacy;
|
||||||
}
|
|
||||||
[[nodiscard]] bool disableCalls() const {
|
|
||||||
return _disableCalls;
|
|
||||||
}
|
}
|
||||||
[[nodiscard]] bool groupCallPushToTalk() const {
|
[[nodiscard]] bool groupCallPushToTalk() const {
|
||||||
return _groupCallPushToTalk;
|
return _groupCallPushToTalk;
|
||||||
|
@ -714,7 +711,7 @@ private:
|
||||||
int _callOutputVolume = 100;
|
int _callOutputVolume = 100;
|
||||||
int _callInputVolume = 100;
|
int _callInputVolume = 100;
|
||||||
bool _callAudioDuckingEnabled = true;
|
bool _callAudioDuckingEnabled = true;
|
||||||
bool _disableCalls = false;
|
bool _disableCallsLegacy = false;
|
||||||
bool _groupCallPushToTalk = false;
|
bool _groupCallPushToTalk = false;
|
||||||
bool _groupCallNoiseSuppression = false;
|
bool _groupCallNoiseSuppression = false;
|
||||||
QByteArray _groupCallPushToTalkShortcut;
|
QByteArray _groupCallPushToTalkShortcut;
|
||||||
|
|
|
@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "calls/calls_call.h"
|
#include "calls/calls_call.h"
|
||||||
#include "calls/calls_instance.h"
|
#include "calls/calls_instance.h"
|
||||||
#include "calls/calls_video_bubble.h"
|
#include "calls/calls_video_bubble.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_authorizations.h"
|
||||||
#include "webrtc/webrtc_media_devices.h"
|
#include "webrtc/webrtc_media_devices.h"
|
||||||
#include "webrtc/webrtc_video_track.h"
|
#include "webrtc/webrtc_video_track.h"
|
||||||
#include "webrtc/webrtc_audio_input_tester.h"
|
#include "webrtc/webrtc_audio_input_tester.h"
|
||||||
|
@ -268,19 +270,21 @@ void Calls::setupContent() {
|
||||||
AddSkip(content);
|
AddSkip(content);
|
||||||
AddSubsectionTitle(content, tr::lng_settings_call_section_other());
|
AddSubsectionTitle(content, tr::lng_settings_call_section_other());
|
||||||
|
|
||||||
|
const auto api = &_controller->session().api();
|
||||||
AddButton(
|
AddButton(
|
||||||
content,
|
content,
|
||||||
tr::lng_settings_call_accept_calls(),
|
tr::lng_settings_call_accept_calls(),
|
||||||
st::settingsButton
|
st::settingsButton
|
||||||
)->toggleOn(rpl::single(
|
)->toggleOn(
|
||||||
!settings.disableCalls()
|
api->authorizations().callsDisabledHereValue(
|
||||||
))->toggledChanges(
|
) | rpl::map(!rpl::mappers::_1)
|
||||||
) | rpl::filter([&settings](bool value) {
|
)->toggledChanges(
|
||||||
return (settings.disableCalls() == value);
|
) | rpl::filter([=](bool value) {
|
||||||
}) | rpl::start_with_next([=](bool value) {
|
return (value == api->authorizations().callsDisabledHere());
|
||||||
Core::App().settings().setDisableCalls(!value);
|
}) | start_with_next([=](bool value) {
|
||||||
Core::App().saveSettingsDelayed();
|
api->authorizations().toggleCallsDisabledHere(!value);
|
||||||
}, content->lifetime());
|
}, content->lifetime());
|
||||||
|
|
||||||
AddButton(
|
AddButton(
|
||||||
content,
|
content,
|
||||||
tr::lng_settings_call_open_system_prefs(),
|
tr::lng_settings_call_open_system_prefs(),
|
||||||
|
|
|
@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "main/main_account.h"
|
#include "main/main_account.h"
|
||||||
#include "main/main_domain.h"
|
#include "main/main_domain.h"
|
||||||
|
#include "api/api_authorizations.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "facades.h"
|
#include "facades.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
|
@ -670,15 +671,19 @@ void SetupNotificationsContent(
|
||||||
AddSubsectionTitle(
|
AddSubsectionTitle(
|
||||||
container,
|
container,
|
||||||
tr::lng_settings_notifications_calls_title());
|
tr::lng_settings_notifications_calls_title());
|
||||||
addCheckbox(
|
const auto authorizations = &session->api().authorizations();
|
||||||
|
const auto acceptCalls = addCheckbox(
|
||||||
tr::lng_settings_call_accept_calls(tr::now),
|
tr::lng_settings_call_accept_calls(tr::now),
|
||||||
!settings.disableCalls()
|
!authorizations->callsDisabledHere());
|
||||||
)->checkedChanges(
|
session->api().authorizations().callsDisabledHereChanges(
|
||||||
) | rpl::filter([&settings](bool value) {
|
) | rpl::start_with_next([=](bool disabled) {
|
||||||
return (settings.disableCalls() == value);
|
acceptCalls->setChecked(
|
||||||
}) | rpl::start_with_next([=](bool value) {
|
!disabled,
|
||||||
Core::App().settings().setDisableCalls(!value);
|
Ui::Checkbox::NotifyAboutChange::DontNotify);
|
||||||
Core::App().saveSettingsDelayed();
|
}, acceptCalls->lifetime());
|
||||||
|
acceptCalls->checkedChanges(
|
||||||
|
) | rpl::start_with_next([=](bool value) {
|
||||||
|
authorizations->toggleCallsDisabledHere(!value);
|
||||||
}, container->lifetime());
|
}, container->lifetime());
|
||||||
|
|
||||||
AddSkip(container, st::settingsCheckboxesSkip);
|
AddSkip(container, st::settingsCheckboxesSkip);
|
||||||
|
|
Loading…
Add table
Reference in a new issue