mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +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({});
|
||||
}
|
||||
}, _lifetime);
|
||||
|
||||
if (Core::App().settings().disableCallsLegacy()) {
|
||||
toggleCallsDisabledHere(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Authorizations::reload() {
|
||||
|
@ -198,6 +202,39 @@ rpl::producer<int> Authorizations::ttlDays() const {
|
|||
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 {
|
||||
return ranges::count_if(
|
||||
_list,
|
||||
|
|
|
@ -43,6 +43,14 @@ public:
|
|||
void updateTTL(int days);
|
||||
[[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:
|
||||
MTP::Sender _api;
|
||||
mtpRequestId _requestId = 0;
|
||||
|
@ -53,6 +61,9 @@ private:
|
|||
mtpRequestId _ttlRequestId = 0;
|
||||
rpl::variable<int> _ttlDays = 0;
|
||||
|
||||
base::flat_map<uint64, mtpRequestId> _toggleCallsDisabledRequests;
|
||||
rpl::variable<bool> _callsDisabledHere;
|
||||
|
||||
crl::time _lastReceived = 0;
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
|
|
|
@ -503,8 +503,6 @@ 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);
|
||||
|
|
|
@ -203,7 +203,7 @@ QByteArray Settings::serialize() const {
|
|||
<< _groupCallPushToTalkShortcut
|
||||
<< qint64(_groupCallPushToTalkDelay)
|
||||
<< qint32(0) // Call audio backend
|
||||
<< qint32(_disableCalls ? 1 : 0)
|
||||
<< qint32(0) // Legacy disable calls, now in session settings
|
||||
<< windowPosition
|
||||
<< qint32(recentEmojiPreloadData.size());
|
||||
for (const auto &[id, rating] : recentEmojiPreloadData) {
|
||||
|
@ -300,7 +300,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
QByteArray groupCallPushToTalkShortcut = _groupCallPushToTalkShortcut;
|
||||
qint64 groupCallPushToTalkDelay = _groupCallPushToTalkDelay;
|
||||
qint32 callAudioBackend = 0;
|
||||
qint32 disableCalls = _disableCalls ? 1 : 0;
|
||||
qint32 disableCallsLegacy = 0;
|
||||
QByteArray windowPosition;
|
||||
std::vector<RecentEmojiId> recentEmojiPreload;
|
||||
base::flat_map<QString, uint8> emojiVariants;
|
||||
|
@ -413,7 +413,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
stream >> callAudioBackend;
|
||||
}
|
||||
if (!stream.atEnd()) {
|
||||
stream >> disableCalls;
|
||||
stream >> disableCallsLegacy;
|
||||
}
|
||||
if (!stream.atEnd()) {
|
||||
stream >> windowPosition;
|
||||
|
@ -593,7 +593,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
_groupCallPushToTalk = (groupCallPushToTalk == 1);
|
||||
_groupCallPushToTalkShortcut = groupCallPushToTalkShortcut;
|
||||
_groupCallPushToTalkDelay = groupCallPushToTalkDelay;
|
||||
_disableCalls = (disableCalls == 1);
|
||||
_disableCallsLegacy = (disableCallsLegacy == 1);
|
||||
if (!windowPosition.isEmpty()) {
|
||||
_windowPosition = Deserialize(windowPosition);
|
||||
}
|
||||
|
@ -870,7 +870,7 @@ void Settings::resetOnLastLogout() {
|
|||
//_callInputVolume = 100;
|
||||
//_callAudioDuckingEnabled = true;
|
||||
|
||||
_disableCalls = false;
|
||||
_disableCallsLegacy = false;
|
||||
|
||||
_groupCallPushToTalk = false;
|
||||
_groupCallPushToTalkShortcut = QByteArray();
|
||||
|
|
|
@ -265,11 +265,8 @@ public:
|
|||
_callAudioDuckingEnabled = value;
|
||||
}
|
||||
[[nodiscard]] Webrtc::Backend callAudioBackend() const;
|
||||
void setDisableCalls(bool value) {
|
||||
_disableCalls = value;
|
||||
}
|
||||
[[nodiscard]] bool disableCalls() const {
|
||||
return _disableCalls;
|
||||
[[nodiscard]] bool disableCallsLegacy() const {
|
||||
return _disableCallsLegacy;
|
||||
}
|
||||
[[nodiscard]] bool groupCallPushToTalk() const {
|
||||
return _groupCallPushToTalk;
|
||||
|
@ -714,7 +711,7 @@ private:
|
|||
int _callOutputVolume = 100;
|
||||
int _callInputVolume = 100;
|
||||
bool _callAudioDuckingEnabled = true;
|
||||
bool _disableCalls = false;
|
||||
bool _disableCallsLegacy = false;
|
||||
bool _groupCallPushToTalk = false;
|
||||
bool _groupCallNoiseSuppression = false;
|
||||
QByteArray _groupCallPushToTalkShortcut;
|
||||
|
|
|
@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "calls/calls_call.h"
|
||||
#include "calls/calls_instance.h"
|
||||
#include "calls/calls_video_bubble.h"
|
||||
#include "apiwrap.h"
|
||||
#include "api/api_authorizations.h"
|
||||
#include "webrtc/webrtc_media_devices.h"
|
||||
#include "webrtc/webrtc_video_track.h"
|
||||
#include "webrtc/webrtc_audio_input_tester.h"
|
||||
|
@ -268,19 +270,21 @@ void Calls::setupContent() {
|
|||
AddSkip(content);
|
||||
AddSubsectionTitle(content, tr::lng_settings_call_section_other());
|
||||
|
||||
const auto api = &_controller->session().api();
|
||||
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();
|
||||
)->toggleOn(
|
||||
api->authorizations().callsDisabledHereValue(
|
||||
) | rpl::map(!rpl::mappers::_1)
|
||||
)->toggledChanges(
|
||||
) | rpl::filter([=](bool value) {
|
||||
return (value == api->authorizations().callsDisabledHere());
|
||||
}) | start_with_next([=](bool value) {
|
||||
api->authorizations().toggleCallsDisabledHere(!value);
|
||||
}, content->lifetime());
|
||||
|
||||
AddButton(
|
||||
content,
|
||||
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_account.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "api/api_authorizations.h"
|
||||
#include "apiwrap.h"
|
||||
#include "facades.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
@ -670,15 +671,19 @@ void SetupNotificationsContent(
|
|||
AddSubsectionTitle(
|
||||
container,
|
||||
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),
|
||||
!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();
|
||||
!authorizations->callsDisabledHere());
|
||||
session->api().authorizations().callsDisabledHereChanges(
|
||||
) | rpl::start_with_next([=](bool disabled) {
|
||||
acceptCalls->setChecked(
|
||||
!disabled,
|
||||
Ui::Checkbox::NotifyAboutChange::DontNotify);
|
||||
}, acceptCalls->lifetime());
|
||||
acceptCalls->checkedChanges(
|
||||
) | rpl::start_with_next([=](bool value) {
|
||||
authorizations->toggleCallsDisabledHere(!value);
|
||||
}, container->lifetime());
|
||||
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
|
|
Loading…
Add table
Reference in a new issue