Use cloud-based settings for p2p in calls.

This commit is contained in:
John Preston 2018-10-24 13:07:54 +04:00
parent 5174c002cf
commit 8d27d8efcf
10 changed files with 80 additions and 87 deletions

View File

@ -336,6 +336,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_privacy_title" = "Privacy";
"lng_settings_last_seen" = "Last seen";
"lng_settings_calls" = "Voice calls";
"lng_settings_calls_peer_to_peer" = "Peer-to-peer in calls";
"lng_settings_groups_invite" = "Groups";
"lng_settings_group_privacy_about" = "Change who can add you to groups and channels.";
"lng_settings_sessions_about" = "Control your sessions on other devices.";
@ -347,7 +348,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_phone_label" = "Phone number";
"lng_settings_username_add" = "Add username";
"lng_settings_close_sure" = "Are you sure you want to close this page? You didn't save your changes.";
"lng_settings_peer_to_peer" = "Peer-to-Peer";
//"lng_settings_peer_to_peer" = "Peer-to-Peer";
"lng_settings_peer_to_peer_about" = "Disabling peer-to-peer will relay all calls through Telegram servers to avoid revealing your IP address, but may slightly decrease audio quality.";
"lng_settings_advanced" = "Advanced";
"lng_settings_stickers_emoji" = "Stickers and emoji";
@ -558,14 +559,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_edit_privacy_nobody" = "Nobody";
"lng_edit_privacy_exceptions" = "Add exceptions";
"lng_edit_privacy_exceptions_count#one" = "{count} user";
"lng_edit_privacy_exceptions_count#other" = "{count} users";
"lng_edit_privacy_exceptions_add" = "Add users";
"lng_edit_privacy_lastseen_title" = "Last seen privacy";
"lng_edit_privacy_lastseen_header" = "Who can see your last seen time";
"lng_edit_privacy_lastseen_warning" = "Important: you won't be able to see Last Seen times for people with whom you don't share your Last Seen time. Approximate last seen will be shown instead (recently, within a week, within a month).";
"lng_edit_privacy_lastseen_always_empty" = "Always share with";
"lng_edit_privacy_lastseen_never_empty" = "Never share with";
"lng_edit_privacy_exceptions_count#one" = "{count} user";
"lng_edit_privacy_exceptions_count#other" = "{count} users";
"lng_edit_privacy_exceptions_add" = "Add users";
"lng_edit_privacy_lastseen_exceptions" = "These settings will override the values above.";
"lng_edit_privacy_lastseen_always_title" = "Always share with";
"lng_edit_privacy_lastseen_never_title" = "Never share with";
@ -586,6 +588,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_edit_privacy_calls_always_title" = "Always allow";
"lng_edit_privacy_calls_never_title" = "Never allow";
"lng_edit_privacy_calls_p2p_title" = "Peer-to-peer in calls";
"lng_edit_privacy_calls_p2p_header" = "With who peer-to-peer is enabled?";
"lng_edit_privacy_calls_p2p_always_empty" = "Always allow";
"lng_edit_privacy_calls_p2p_never_empty" = "Never allow";
"lng_edit_privacy_calls_p2p_exceptions" = "Peer-to-peer in calls will or will not be used with these users regardless of the settings above.";
"lng_edit_privacy_calls_p2p_always_title" = "Always allow";
"lng_edit_privacy_calls_p2p_never_title" = "Never allow";
"lng_self_destruct_title" = "Account self-destruction";
"lng_self_destruct_description" = "If you don't come online at least once within this period, your account will be deleted along with all groups, messages and contacts.";
"lng_self_destruct_months#one" = "{count} month";

View File

@ -157,6 +157,8 @@ MTPInputPrivacyKey ApiWrap::Privacy::Input(Key key) {
case Privacy::Key::Invites: return MTP_inputPrivacyKeyChatInvite();
case Privacy::Key::LastSeen:
return MTP_inputPrivacyKeyStatusTimestamp();
case Privacy::Key::CallsPeer2Peer:
return MTP_inputPrivacyKeyPhoneP2P();
}
Unexpected("Key in ApiWrap::Privacy::Input.");
}
@ -2000,6 +2002,8 @@ void ApiWrap::handlePrivacyChange(
case mtpc_inputPrivacyKeyChatInvite: return Key::Invites;
case mtpc_privacyKeyPhoneCall:
case mtpc_inputPrivacyKeyPhoneCall: return Key::Calls;
case mtpc_privacyKeyPhoneP2P:
case mtpc_inputPrivacyKeyPhoneP2P: return Key::CallsPeer2Peer;
}
return std::nullopt;
}();

View File

@ -350,6 +350,7 @@ public:
LastSeen,
Calls,
Invites,
CallsPeer2Peer,
};
enum class Option {
Everyone,

View File

@ -300,8 +300,6 @@ void EditPrivacyBox::setupContent() {
AddLabel(content, _controller->exceptionsDescription());
AddSkip(content);
const auto saveAdditional = _controller->setupAdditional(content);
addButton(langFactory(lng_settings_save), [=] {
const auto someAreDisallowed = (_value.option != Option::Everyone)
|| !_value.never.empty();
@ -309,9 +307,6 @@ void EditPrivacyBox::setupContent() {
Auth().api().savePrivacy(
_controller->apiKey(),
collectResult());
if (saveAdditional) {
saveAdditional();
}
closeBox();
}));
});

View File

@ -13,10 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
enum LangKey : int;
namespace Calls {
enum class PeerToPeer;
} // namespace Calls
namespace Ui {
class VerticalLayout;
class FlatLabel;
@ -62,10 +58,6 @@ public:
FnMut<void()> saveCallback) {
saveCallback();
}
virtual Fn<void()> setupAdditional(
not_null<Ui::VerticalLayout*> container) {
return nullptr;
}
virtual ~Controller() = default;

View File

@ -580,20 +580,10 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
_controller->SetMicMute(_mute);
}
_controller->implData = static_cast<void*>(this);
const auto p2p = [&] {
switch (Auth().settings().callsPeerToPeer()) {
case PeerToPeer::DefaultContacts:
case PeerToPeer::Contacts:
return _user->isContact();
case PeerToPeer::DefaultEveryone:
case PeerToPeer::Everyone:
return true;
case PeerToPeer::Nobody:
return false;
}
Unexpected("Calls::PeerToPeer value in Auth().settings().");
}();
_controller->SetRemoteEndpoints(endpoints, p2p, protocol.vmax_layer.v);
_controller->SetRemoteEndpoints(
endpoints,
call.is_p2p_allowed(),
protocol.vmax_layer.v);
_controller->SetConfig(config);
_controller->SetEncryptionKey(reinterpret_cast<char*>(_authKey.data()), (_type == Type::Outgoing));
_controller->SetCallbacks(callbacks);

View File

@ -793,18 +793,6 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
+ (data.vexpires.v - unixtime()) * TimeMs(1000);
requestConfigIfExpired();
if (AuthSession::Exists()) {
using PeerToPeer = Calls::PeerToPeer;
const auto current = Auth().settings().callsPeerToPeer();
if (current == PeerToPeer::DefaultContacts
|| current == PeerToPeer::DefaultEveryone) {
Auth().settings().setCallsPeerToPeer(
(data.is_default_p2p_contacts()
? PeerToPeer::DefaultContacts
: PeerToPeer::DefaultEveryone));
}
}
emit _instance->configLoaded();
}

View File

@ -368,50 +368,45 @@ rpl::producer<QString> CallsPrivacyController::exceptionsDescription() {
return Lang::Viewer(lng_edit_privacy_calls_exceptions);
}
Fn<void()> CallsPrivacyController::setupAdditional(
not_null<Ui::VerticalLayout*> container) {
using PeerToPeer = Calls::PeerToPeer;
const auto convert = [](PeerToPeer value) {
switch (value) {
case PeerToPeer::DefaultContacts: return Option::Contacts;
case PeerToPeer::DefaultEveryone: return Option::Everyone;
case PeerToPeer::Everyone: return Option::Everyone;
case PeerToPeer::Contacts: return Option::Contacts;
case PeerToPeer::Nobody: return Option::Nobody;
}
Unexpected("Calls::PeerToPeer value.");
};
const auto group = std::make_shared<Ui::RadioenumGroup<Option>>(
convert(Auth().settings().callsPeerToPeer()));
const auto changed = Ui::AttachAsChild(container, false);
group->setChangedCallback([=](Option) {
*changed = true;
});
ApiWrap::Privacy::Key CallsPeer2PeerPrivacyController::key() {
return Key::CallsPeer2Peer;
}
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, lng_settings_peer_to_peer);
EditPrivacyBox::AddOption(container, group, Option::Everyone);
EditPrivacyBox::AddOption(container, group, Option::Contacts);
EditPrivacyBox::AddOption(container, group, Option::Nobody);
EditPrivacyBox::AddLabel(
container,
Lang::Viewer(lng_settings_peer_to_peer_about));
AddSkip(container);
MTPInputPrivacyKey CallsPeer2PeerPrivacyController::apiKey() {
return MTP_inputPrivacyKeyPhoneP2P();
}
return [=] {
if (*changed) {
Auth().settings().setCallsPeerToPeer([&] {
switch (group->value()) {
case Option::Everyone: return PeerToPeer::Everyone;
case Option::Contacts: return PeerToPeer::Contacts;
case Option::Nobody: return PeerToPeer::Nobody;
}
Unexpected("PeerToPeer edit value.");
}());
Auth().saveSettingsDelayed();
}
};
QString CallsPeer2PeerPrivacyController::title() {
return lang(lng_edit_privacy_calls_p2p_title);
}
LangKey CallsPeer2PeerPrivacyController::optionsTitleKey() {
return lng_edit_privacy_calls_p2p_header;
}
rpl::producer<QString> CallsPeer2PeerPrivacyController::warning() {
return Lang::Viewer(lng_settings_peer_to_peer_about);
}
LangKey CallsPeer2PeerPrivacyController::exceptionButtonTextKey(
Exception exception) {
switch (exception) {
case Exception::Always: return lng_edit_privacy_calls_p2p_always_empty;
case Exception::Never: return lng_edit_privacy_calls_p2p_never_empty;
}
Unexpected("Invalid exception value.");
}
QString CallsPeer2PeerPrivacyController::exceptionBoxTitle(Exception exception) {
switch (exception) {
case Exception::Always: return lang(lng_edit_privacy_calls_p2p_always_title);
case Exception::Never: return lang(lng_edit_privacy_calls_p2p_never_title);
}
Unexpected("Invalid exception value.");
}
rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionsDescription() {
return Lang::Viewer(lng_edit_privacy_calls_p2p_exceptions);
}
} // namespace Settings

View File

@ -86,8 +86,22 @@ public:
QString exceptionBoxTitle(Exception exception) override;
rpl::producer<QString> exceptionsDescription() override;
Fn<void()> setupAdditional(
not_null<Ui::VerticalLayout*> container) override;
};
class CallsPeer2PeerPrivacyController : public EditPrivacyBox::Controller, private base::Subscriber {
public:
using Option = EditPrivacyBox::Option;
using Exception = EditPrivacyBox::Exception;
Key key() override;
MTPInputPrivacyKey apiKey() override;
QString title() override;
LangKey optionsTitleKey() override;
rpl::producer<QString> warning() override;
LangKey exceptionButtonTextKey(Exception exception) override;
QString exceptionBoxTitle(Exception exception) override;
rpl::producer<QString> exceptionsDescription() override;
};

View File

@ -124,6 +124,10 @@ void SetupPrivacy(not_null<Ui::VerticalLayout*> container) {
lng_settings_calls,
Privacy::Key::Calls,
[] { return std::make_unique<CallsPrivacyController>(); });
add(
lng_settings_calls_peer_to_peer,
Privacy::Key::CallsPeer2Peer,
[] { return std::make_unique<CallsPeer2PeerPrivacyController>(); });
add(
lng_settings_groups_invite,
Privacy::Key::Invites,