From af85aec33b86f138346f28ba70303a0e590f3db7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 28 May 2019 16:53:36 +0200 Subject: [PATCH] Allow disabling pinned messages notifications. Fixes #1864. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/auth_session.cpp | 18 ++++++++++++++++++ Telegram/SourceFiles/auth_session.h | 5 +++++ Telegram/SourceFiles/history/history_item.cpp | 8 ++++++++ Telegram/SourceFiles/history/history_item.h | 4 +--- .../settings/settings_notifications.cpp | 16 ++++++++++++++++ 6 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 352fdc82875be..59a0a5a7b2c94 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -288,6 +288,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_count_unread" = "Count unread messages"; "lng_settings_events_title" = "Events"; "lng_settings_events_joined" = "Contact joined Telegram"; +"lng_settings_events_pinned" = "Pinned messages"; "lng_notification_preview" = "You have a new message"; "lng_notification_reply" = "Reply"; diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 9da0b9efc55d7..70d139c3ee9f2 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -94,6 +94,7 @@ QByteArray AuthSessionSettings::serialize() const { stream << autoDownload; stream << qint32(_variables.supportAllSearchResults.current() ? 1 : 0); stream << qint32(_variables.archiveCollapsed.current() ? 1 : 0); + stream << qint32(_variables.notifyAboutPinned.current() ? 1 : 0); } return result; } @@ -131,6 +132,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) QByteArray autoDownload; qint32 supportAllSearchResults = _variables.supportAllSearchResults.current() ? 1 : 0; qint32 archiveCollapsed = _variables.archiveCollapsed.current() ? 1 : 0; + qint32 notifyAboutPinned = _variables.notifyAboutPinned.current() ? 1 : 0; stream >> selectorTab; stream >> lastSeenWarningSeen; @@ -213,6 +215,9 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) if (!stream.atEnd()) { stream >> archiveCollapsed; } + if (!stream.atEnd()) { + stream >> notifyAboutPinned; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for AuthSessionSettings::constructFromSerialized()")); @@ -283,6 +288,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) _variables.exeLaunchWarning = (exeLaunchWarning == 1); _variables.supportAllSearchResults = (supportAllSearchResults == 1); _variables.archiveCollapsed = (archiveCollapsed == 1); + _variables.notifyAboutPinned = (notifyAboutPinned == 1); } void AuthSessionSettings::setSupportChatsTimeSlice(int slice) { @@ -389,6 +395,18 @@ rpl::producer AuthSessionSettings::archiveCollapsedChanges() const { return _variables.archiveCollapsed.changes(); } +void AuthSessionSettings::setNotifyAboutPinned(bool notify) { + _variables.notifyAboutPinned = notify; +} + +bool AuthSessionSettings::notifyAboutPinned() const { + return _variables.notifyAboutPinned.current(); +} + +rpl::producer AuthSessionSettings::notifyAboutPinnedChanges() const { + return _variables.notifyAboutPinned.changes(); +} + AuthSession &Auth() { const auto result = Core::App().authSession(); Assert(result != nullptr); diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index 4e7a5eab92ecd..19fb919ad46db 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -192,6 +192,10 @@ class AuthSessionSettings final { bool archiveCollapsed() const; rpl::producer archiveCollapsedChanges() const; + void setNotifyAboutPinned(bool notify); + bool notifyAboutPinned() const; + rpl::producer notifyAboutPinnedChanges() const; + bool hadLegacyCallsPeerToPeerNobody() const { return _variables.hadLegacyCallsPeerToPeerNobody; } @@ -245,6 +249,7 @@ class AuthSessionSettings final { bool exeLaunchWarning = true; Data::AutoDownload::Full autoDownload; rpl::variable archiveCollapsed = false; + rpl::variable notifyAboutPinned = true; static constexpr auto kDefaultSupportChatsLimitSlice = 7 * 24 * 60 * 60; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 2956eed3154a7..351e07debf92b 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -281,6 +281,14 @@ bool HistoryItem::isUnreadMention() const { return mentionsMe() && (_flags & MTPDmessage::Flag::f_media_unread); } +bool HistoryItem::mentionsMe() const { + if (Has() + && !history()->session().settings().notifyAboutPinned()) { + return false; + } + return _flags & MTPDmessage::Flag::f_mentioned; +} + bool HistoryItem::isUnreadMedia() const { if (!hasUnreadMediaFlag()) { return false; diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index a5519d4d2a89c..a8bd395b2aa3b 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -116,9 +116,7 @@ class HistoryItem : public RuntimeComposer { } [[nodiscard]] bool unread() const; void markClientSideAsRead(); - [[nodiscard]] bool mentionsMe() const { - return _flags & MTPDmessage::Flag::f_mentioned; - } + [[nodiscard]] bool mentionsMe() const; [[nodiscard]] bool isUnreadMention() const; [[nodiscard]] bool isUnreadMedia() const; [[nodiscard]] bool hasUnreadMediaFlag() const; diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 154cfa9c56ca6..2526119cf639a 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -565,6 +565,7 @@ void SetupNotificationsContent(not_null container) { 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)); @@ -580,6 +581,21 @@ void SetupNotificationsContent(not_null container) { Auth().api().saveContactSignupSilent(!enabled); }, joined->lifetime()); + const auto pinned = addCheckbox( + lng_settings_events_pinned, + Auth().settings().notifyAboutPinned()); + Auth().settings().notifyAboutPinnedChanges( + ) | rpl::start_with_next([=](bool notify) { + pinned->setChecked(notify); + }, pinned->lifetime()); + pinned->checkedChanges( + ) | rpl::filter([](bool notify) { + return (notify != Auth().settings().notifyAboutPinned()); + }) | rpl::start_with_next([=](bool notify) { + Auth().settings().setNotifyAboutPinned(notify); + Auth().saveSettingsDelayed(); + }, joined->lifetime()); + const auto nativeKey = [&] { if (!Platform::Notifications::Supported()) { return LangKey();