Allow disabling pinned messages notifications.

Fixes #1864.
This commit is contained in:
John Preston 2019-05-28 16:53:36 +02:00
parent e0d4884351
commit af85aec33b
6 changed files with 49 additions and 3 deletions

View File

@ -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";

View File

@ -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<bool> 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<bool> AuthSessionSettings::notifyAboutPinnedChanges() const {
return _variables.notifyAboutPinned.changes();
}
AuthSession &Auth() {
const auto result = Core::App().authSession();
Assert(result != nullptr);

View File

@ -192,6 +192,10 @@ public:
bool archiveCollapsed() const;
rpl::producer<bool> archiveCollapsedChanges() const;
void setNotifyAboutPinned(bool notify);
bool notifyAboutPinned() const;
rpl::producer<bool> notifyAboutPinnedChanges() const;
bool hadLegacyCallsPeerToPeerNobody() const {
return _variables.hadLegacyCallsPeerToPeerNobody;
}
@ -245,6 +249,7 @@ private:
bool exeLaunchWarning = true;
Data::AutoDownload::Full autoDownload;
rpl::variable<bool> archiveCollapsed = false;
rpl::variable<bool> notifyAboutPinned = true;
static constexpr auto kDefaultSupportChatsLimitSlice
= 7 * 24 * 60 * 60;

View File

@ -281,6 +281,14 @@ bool HistoryItem::isUnreadMention() const {
return mentionsMe() && (_flags & MTPDmessage::Flag::f_media_unread);
}
bool HistoryItem::mentionsMe() const {
if (Has<HistoryServicePinned>()
&& !history()->session().settings().notifyAboutPinned()) {
return false;
}
return _flags & MTPDmessage::Flag::f_mentioned;
}
bool HistoryItem::isUnreadMedia() const {
if (!hasUnreadMediaFlag()) {
return false;

View File

@ -116,9 +116,7 @@ public:
}
[[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;

View File

@ -565,6 +565,7 @@ void SetupNotificationsContent(not_null<Ui::VerticalLayout*> 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<Ui::VerticalLayout*> 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();