mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 10:11:41 -05:00
Add 'Contact joined' notifications setting.
This commit is contained in:
parent
01b7d4ffba
commit
61b9a32504
5 changed files with 99 additions and 5 deletions
|
@ -276,16 +276,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_settings_empty_bio" = "None";
|
||||
|
||||
"lng_settings_section_notify" = "Notifications";
|
||||
"lng_settings_notify_title" = "Notifications for chats";
|
||||
"lng_settings_desktop_notify" = "Desktop notifications";
|
||||
"lng_settings_show_name" = "Show sender's name";
|
||||
"lng_settings_show_preview" = "Show message preview";
|
||||
"lng_settings_native_title" = "Native notifications";
|
||||
"lng_settings_use_windows" = "Use Windows notifications";
|
||||
"lng_settings_use_native_notifications" = "Use native notifications";
|
||||
"lng_settings_notifications_position" = "Location on the screen";
|
||||
"lng_settings_notifications_count" = "Notifications count";
|
||||
"lng_settings_sound_notify" = "Play sound";
|
||||
"lng_settings_badge_title" = "Badge counter";
|
||||
"lng_settings_include_muted" = "Include muted chats in unread count";
|
||||
"lng_settings_count_unread" = "Count unread messages";
|
||||
"lng_settings_events_title" = "Events";
|
||||
"lng_settings_events_joined" = "Contact joined Telegram";
|
||||
|
||||
"lng_notification_preview" = "You have a new message";
|
||||
"lng_notification_reply" = "Reply";
|
||||
|
|
|
@ -5231,6 +5231,48 @@ auto ApiWrap::passwordStateCurrent() const
|
|||
: std::nullopt;
|
||||
}
|
||||
|
||||
void ApiWrap::reloadContactSignupSilent() {
|
||||
if (_contactSignupSilentRequestId) {
|
||||
return;
|
||||
}
|
||||
const auto requestId = request(MTPaccount_GetContactSignUpNotification(
|
||||
)).done([=](const MTPBool &result) {
|
||||
_contactSignupSilentRequestId = 0;
|
||||
const auto silent = mtpIsTrue(result);
|
||||
_contactSignupSilent = silent;
|
||||
_contactSignupSilentChanges.fire_copy(silent);
|
||||
}).fail([=](const RPCError &error) {
|
||||
_contactSignupSilentRequestId = 0;
|
||||
}).send();
|
||||
_contactSignupSilentRequestId = requestId;
|
||||
}
|
||||
|
||||
rpl::producer<bool> ApiWrap::contactSignupSilent() const {
|
||||
return _contactSignupSilent
|
||||
? _contactSignupSilentChanges.events_starting_with_copy(
|
||||
*_contactSignupSilent)
|
||||
: (_contactSignupSilentChanges.events() | rpl::type_erased());
|
||||
}
|
||||
|
||||
std::optional<bool> ApiWrap::contactSignupSilentCurrent() const {
|
||||
return _contactSignupSilent;
|
||||
}
|
||||
|
||||
void ApiWrap::saveContactSignupSilent(bool silent) {
|
||||
request(base::take(_contactSignupSilentRequestId)).cancel();
|
||||
|
||||
const auto requestId = request(MTPaccount_SetContactSignUpNotification(
|
||||
MTP_bool(silent)
|
||||
)).done([=](const MTPBool &) {
|
||||
_contactSignupSilentRequestId = 0;
|
||||
_contactSignupSilent = silent;
|
||||
_contactSignupSilentChanges.fire_copy(silent);
|
||||
}).fail([=](const RPCError &error) {
|
||||
_contactSignupSilentRequestId = 0;
|
||||
}).send();
|
||||
_contactSignupSilentRequestId = requestId;
|
||||
}
|
||||
|
||||
void ApiWrap::saveSelfBio(const QString &text, FnMut<void()> done) {
|
||||
if (_saveBioRequestId) {
|
||||
if (text != _saveBioText) {
|
||||
|
|
|
@ -366,6 +366,11 @@ public:
|
|||
rpl::producer<Core::CloudPasswordState> passwordState() const;
|
||||
std::optional<Core::CloudPasswordState> passwordStateCurrent() const;
|
||||
|
||||
void reloadContactSignupSilent();
|
||||
rpl::producer<bool> contactSignupSilent() const;
|
||||
std::optional<bool> contactSignupSilentCurrent() const;
|
||||
void saveContactSignupSilent(bool silent);
|
||||
|
||||
void saveSelfBio(const QString &text, FnMut<void()> done);
|
||||
|
||||
struct Privacy {
|
||||
|
@ -786,4 +791,8 @@ private:
|
|||
Fn<void(const Data::WallPaper &)> _wallPaperDone;
|
||||
Fn<void(const RPCError &)> _wallPaperFail;
|
||||
|
||||
mtpRequestId _contactSignupSilentRequestId = 0;
|
||||
std::optional<bool> _contactSignupSilent;
|
||||
rpl::event_stream<bool> _contactSignupSilentChanges;
|
||||
|
||||
};
|
||||
|
|
|
@ -284,6 +284,7 @@ void Main::setupContent(not_null<Window::Controller*> controller) {
|
|||
|
||||
// If we load this in advance it won't jump when we open its' section.
|
||||
Auth().api().reloadPasswordState();
|
||||
Auth().api().reloadContactSignupSilent();
|
||||
}
|
||||
|
||||
rpl::producer<Type> Main::sectionShowOther() {
|
||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "mainwindow.h"
|
||||
#include "messenger.h"
|
||||
#include "auth_session.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_window.h"
|
||||
|
@ -512,6 +513,8 @@ void SetupAdvancedNotifications(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
|
||||
void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
||||
AddSubsectionTitle(container, lng_settings_notify_title);
|
||||
|
||||
const auto checkbox = [&](LangKey label, bool checked) {
|
||||
return object_ptr<Ui::Checkbox>(
|
||||
container,
|
||||
|
@ -543,6 +546,12 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
const auto sound = addCheckbox(
|
||||
lng_settings_sound_notify,
|
||||
Global::SoundNotify());
|
||||
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddDivider(container);
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddSubsectionTitle(container, lng_settings_badge_title);
|
||||
|
||||
const auto muted = addCheckbox(
|
||||
lng_settings_include_muted,
|
||||
Auth().settings().includeMutedCounter());
|
||||
|
@ -550,7 +559,27 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
lng_settings_count_unread,
|
||||
Auth().settings().countUnreadMessages());
|
||||
|
||||
const auto nativeNotificationsKey = [&] {
|
||||
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddDivider(container);
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddSubsectionTitle(container, lng_settings_events_title);
|
||||
const auto joined = addCheckbox(
|
||||
lng_settings_events_joined,
|
||||
!Auth().api().contactSignupSilentCurrent().value_or(false));
|
||||
Auth().api().contactSignupSilent(
|
||||
) | rpl::start_with_next([=](bool silent) {
|
||||
joined->setChecked(!silent);
|
||||
}, joined->lifetime());
|
||||
joined->checkedChanges(
|
||||
) | rpl::filter([](bool enabled) {
|
||||
const auto silent = Auth().api().contactSignupSilentCurrent();
|
||||
return (enabled == silent.value_or(false));
|
||||
}) | rpl::start_with_next([=](bool enabled) {
|
||||
Auth().api().saveContactSignupSilent(!enabled);
|
||||
}, joined->lifetime());
|
||||
|
||||
const auto nativeKey = [&] {
|
||||
if (!Platform::Notifications::Supported()) {
|
||||
return LangKey();
|
||||
} else if (cPlatform() == dbipWindows) {
|
||||
|
@ -561,9 +590,17 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
return LangKey();
|
||||
}();
|
||||
const auto native = nativeNotificationsKey
|
||||
? addCheckbox(nativeNotificationsKey, Global::NativeNotifications())
|
||||
: nullptr;
|
||||
const auto native = [&]() -> Ui::Checkbox* {
|
||||
if (!nativeKey) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddDivider(container);
|
||||
AddSkip(container, st::settingsCheckboxesSkip);
|
||||
AddSubsectionTitle(container, lng_settings_native_title);
|
||||
return addCheckbox(nativeKey, Global::NativeNotifications());
|
||||
}();
|
||||
|
||||
const auto advancedSlide = (cPlatform() != dbipMac)
|
||||
? container->add(
|
||||
|
|
Loading…
Add table
Reference in a new issue