Skip to content

Commit

Permalink
Allow disabling pinned messages notifications.
Browse files Browse the repository at this point in the history
Fixes #1864.
  • Loading branch information
john-preston committed May 28, 2019
1 parent e0d4884 commit af85aec
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 18 additions & 0 deletions Telegram/SourceFiles/auth_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()"));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/auth_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ class AuthSessionSettings final {
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;
}
Expand Down Expand Up @@ -245,6 +249,7 @@ class AuthSessionSettings final {
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;
Expand Down
8 changes: 8 additions & 0 deletions Telegram/SourceFiles/history/history_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions Telegram/SourceFiles/history/history_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ class HistoryItem : public RuntimeComposer<HistoryItem> {
}
[[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;
Expand Down
16 changes: 16 additions & 0 deletions Telegram/SourceFiles/settings/settings_notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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();
Expand Down

1 comment on commit af85aec

@Keltere
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

God bless you!

Please sign in to comment.