diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index ee65b6b3b..3243e05e0 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -3798,66 +3798,6 @@ auto Session::dialogsRowReplacements() const return _dialogsRowReplacements.events(); } -bool Session::notifyIsMuted(not_null peer) const { - return notifySettings().notifyIsMuted(peer, nullptr); -} - -bool Session::notifySilentPosts(not_null peer) const { - if (const auto silent = peer->notifySilentPosts()) { - return *silent; - } - const auto &settings = notifySettings().defaultNotifySettings(peer); - if (const auto silent = settings.silentPosts()) { - return *silent; - } - return false; -} - -bool Session::notifySoundIsNone(not_null peer) const { - if (const auto soundIsNone = peer->notifySoundIsNone()) { - return *soundIsNone; - } - const auto &settings = notifySettings().defaultNotifySettings(peer); - if (const auto soundIsNone = settings.soundIsNone()) { - return *soundIsNone; - } - return false; -} - -bool Session::notifyMuteUnknown(not_null peer) const { - if (peer->notifySettingsUnknown()) { - return true; - } else if (const auto nonDefault = peer->notifyMuteUntil()) { - return false; - } - return notifySettings().defaultNotifySettings(peer).settingsUnknown(); -} - -bool Session::notifySilentPostsUnknown( - not_null peer) const { - if (peer->notifySettingsUnknown()) { - return true; - } else if (const auto nonDefault = peer->notifySilentPosts()) { - return false; - } - return notifySettings().defaultNotifySettings(peer).settingsUnknown(); -} - -bool Session::notifySoundIsNoneUnknown(not_null peer) const { - if (peer->notifySettingsUnknown()) { - return true; - } else if (const auto nonDefault = peer->notifySoundIsNone()) { - return false; - } - return notifySettings().defaultNotifySettings(peer).settingsUnknown(); -} - -bool Session::notifySettingsUnknown(not_null peer) const { - return notifyMuteUnknown(peer) - || notifySilentPostsUnknown(peer) - || notifySoundIsNoneUnknown(peer); -} - void Session::serviceNotification( const TextWithEntities &message, const MTPMessageMedia &media) { diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 058b282c4..986e2c490 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -662,14 +662,6 @@ public: void dialogsRowReplaced(DialogsRowReplacement replacement); rpl::producer dialogsRowReplacements() const; - bool notifyIsMuted(not_null peer) const; - bool notifySilentPosts(not_null peer) const; - bool notifySoundIsNone(not_null peer) const; - bool notifyMuteUnknown(not_null peer) const; - bool notifySilentPostsUnknown(not_null peer) const; - bool notifySoundIsNoneUnknown(not_null peer) const; - bool notifySettingsUnknown(not_null peer) const; - void serviceNotification( const TextWithEntities &message, const MTPMessageMedia &media = MTP_messageMediaEmpty()); diff --git a/Telegram/SourceFiles/data/notify/data_notify_settings.cpp b/Telegram/SourceFiles/data/notify/data_notify_settings.cpp index af1f61a2a..b35de58fd 100644 --- a/Telegram/SourceFiles/data/notify/data_notify_settings.cpp +++ b/Telegram/SourceFiles/data/notify/data_notify_settings.cpp @@ -130,16 +130,6 @@ void NotifySettings::resetNotifySettingsToDefault(not_null peer) { } } - -PeerNotifySettings &NotifySettings::defaultNotifySettings( - not_null peer) { - return peer->isUser() - ? _defaultUserNotifySettings - : (peer->isChat() || peer->isMegagroup()) - ? _defaultChatNotifySettings - : _defaultBroadcastNotifySettings; -} - const PeerNotifySettings &NotifySettings::defaultNotifySettings( not_null peer) const { return peer->isUser() @@ -152,7 +142,7 @@ const PeerNotifySettings &NotifySettings::defaultNotifySettings( void NotifySettings::updateNotifySettingsLocal(not_null peer) { const auto history = _owner->historyLoaded(peer->id); auto changesIn = crl::time(0); - const auto muted = notifyIsMuted(peer, &changesIn); + const auto muted = isMuted(peer, &changesIn); if (history && history->changeMute(muted)) { // Notification already sent. } else { @@ -185,7 +175,7 @@ void NotifySettings::unmuteByFinished() { for (auto i = begin(_mutedPeers); i != end(_mutedPeers);) { const auto history = _owner->historyLoaded((*i)->id); auto changesIn = crl::time(0); - const auto muted = notifyIsMuted(*i, &changesIn); + const auto muted = isMuted(*i, &changesIn); if (muted) { if (history) { history->changeMute(true); @@ -206,7 +196,7 @@ void NotifySettings::unmuteByFinished() { } } -bool NotifySettings::notifyIsMuted( +bool NotifySettings::isMuted( not_null peer, crl::time *changesIn) const { const auto resultFromUntil = [&](TimeId until) { @@ -229,6 +219,67 @@ bool NotifySettings::notifyIsMuted( return true; } +bool NotifySettings::isMuted(not_null peer) const { + return isMuted(peer, nullptr); +} + +bool NotifySettings::silentPosts(not_null peer) const { + if (const auto silent = peer->notifySilentPosts()) { + return *silent; + } + const auto &settings = defaultNotifySettings(peer); + if (const auto silent = settings.silentPosts()) { + return *silent; + } + return false; +} + +bool NotifySettings::soundIsNone(not_null peer) const { + if (const auto soundIsNone = peer->notifySoundIsNone()) { + return *soundIsNone; + } + const auto &settings = defaultNotifySettings(peer); + if (const auto soundIsNone = settings.soundIsNone()) { + return *soundIsNone; + } + return false; +} + +bool NotifySettings::muteUnknown(not_null peer) const { + if (peer->notifySettingsUnknown()) { + return true; + } else if (const auto nonDefault = peer->notifyMuteUntil()) { + return false; + } + return defaultNotifySettings(peer).settingsUnknown(); +} + +bool NotifySettings::silentPostsUnknown( + not_null peer) const { + if (peer->notifySettingsUnknown()) { + return true; + } else if (const auto nonDefault = peer->notifySilentPosts()) { + return false; + } + return defaultNotifySettings(peer).settingsUnknown(); +} + +bool NotifySettings::soundIsNoneUnknown( + not_null peer) const { + if (peer->notifySettingsUnknown()) { + return true; + } else if (const auto nonDefault = peer->notifySoundIsNone()) { + return false; + } + return defaultNotifySettings(peer).settingsUnknown(); +} + +bool NotifySettings::settingsUnknown(not_null peer) const { + return muteUnknown(peer) + || silentPostsUnknown(peer) + || soundIsNoneUnknown(peer); +} + rpl::producer<> NotifySettings::defaultUserNotifyUpdates() const { return _defaultUserNotifyUpdates.events(); } diff --git a/Telegram/SourceFiles/data/notify/data_notify_settings.h b/Telegram/SourceFiles/data/notify/data_notify_settings.h index 88f70f53a..32181b007 100644 --- a/Telegram/SourceFiles/data/notify/data_notify_settings.h +++ b/Telegram/SourceFiles/data/notify/data_notify_settings.h @@ -38,15 +38,24 @@ public: [[nodiscard]] rpl::producer<> defaultNotifyUpdates( not_null peer) const; - [[nodiscard]] bool notifyIsMuted( + [[nodiscard]] bool isMuted(not_null peer) const; + [[nodiscard]] bool silentPosts(not_null peer) const; + [[nodiscard]] bool soundIsNone(not_null peer) const; + [[nodiscard]] bool muteUnknown(not_null peer) const; + [[nodiscard]] bool silentPostsUnknown( + not_null peer) const; + [[nodiscard]] bool soundIsNoneUnknown( + not_null peer) const; + +private: + [[nodiscard]] bool isMuted( not_null peer, crl::time *changesIn) const; - [[nodiscard]] PeerNotifySettings &defaultNotifySettings( - not_null peer); [[nodiscard]] const PeerNotifySettings &defaultNotifySettings( not_null peer) const; -private: + [[nodiscard]] bool settingsUnknown(not_null peer) const; + void unmuteByFinished(); void unmuteByFinishedDelayed(crl::time delay); void updateNotifySettingsLocal(not_null peer); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index f0b046622..3b910e617 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -71,7 +71,7 @@ History::History(not_null owner, PeerId peerId) , peer(owner->peer(peerId)) , cloudDraftTextCache(st::dialogsTextWidthMin) , _delegateMixin(HistoryInner::DelegateMixin()) -, _mute(owner->notifyIsMuted(peer)) +, _mute(owner->notifySettings().isMuted(peer)) , _chatListNameSortKey(owner->nameSortKey(peer->name)) , _sendActionPainter(this) { if (const auto user = peer->asUser()) { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index eedec7113..72657b2f3 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/ui_integration.h" #include "storage/storage_shared_media.h" #include "mtproto/mtproto_config.h" +#include "data/notify/data_notify_settings.h" #include "data/data_session.h" #include "data/data_changes.h" #include "data/data_media_types.h" @@ -198,7 +199,8 @@ bool ShouldSendSilent( not_null peer, const Api::SendOptions &options) { return options.silent - || (peer->isBroadcast() && peer->owner().notifySilentPosts(peer)) + || (peer->isBroadcast() + && peer->owner().notifySettings().silentPosts(peer)) || (peer->session().supportMode() && peer->session().settings().supportAllSilent()); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index d033af39e..9074bafe7 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2499,9 +2499,10 @@ void HistoryWidget::updateNotifyControls() { _muteUnmute->setText((_history->mute() ? tr::lng_channel_unmute(tr::now) : tr::lng_channel_mute(tr::now)).toUpper()); - if (!session().data().notifySilentPostsUnknown(_peer)) { + if (!session().data().notifySettings().silentPostsUnknown(_peer)) { if (_silent) { - _silent->setChecked(session().data().notifySilentPosts(_peer)); + _silent->setChecked( + session().data().notifySettings().silentPosts(_peer)); updateFieldPlaceholder(); } else if (hasSilentToggle()) { refreshSilentToggle(); @@ -4286,7 +4287,7 @@ bool HistoryWidget::hasSilentToggle() const { && _peer->isChannel() && !_peer->isMegagroup() && _peer->canWrite() - && !session().data().notifySilentPostsUnknown(_peer); + && !session().data().notifySettings().silentPostsUnknown(_peer); } void HistoryWidget::handleSupportSwitch(not_null updated) { @@ -4832,7 +4833,7 @@ void HistoryWidget::updateFieldPlaceholder() { return rpl::single(_keyboard->placeholder()); } else if (const auto channel = _history->peer->asChannel()) { if (channel->isBroadcast()) { - return session().data().notifySilentPosts(channel) + return session().data().notifySettings().silentPosts(channel) ? tr::lng_broadcast_silent_ph() : tr::lng_broadcast_ph(); } else if (channel->adminRights() & ChatAdminRight::Anonymous) { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index a40a55a90..8b6df7bfd 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/field_autocomplete.h" #include "core/application.h" #include "core/core_settings.h" +#include "data/notify/data_notify_settings.h" #include "data/data_changes.h" #include "data/data_drafts.h" #include "data/data_messages.h" @@ -1338,7 +1339,7 @@ void ComposeControls::updateFieldPlaceholder() { return tr::lng_message_ph(); } else if (const auto channel = _history->peer->asChannel()) { if (channel->isBroadcast()) { - return session().data().notifySilentPosts(channel) + return session().data().notifySettings().silentPosts(channel) ? tr::lng_broadcast_silent_ph() : tr::lng_broadcast_ph(); } else if (channel->adminRights() & ChatAdminRight::Anonymous) { @@ -1358,8 +1359,9 @@ void ComposeControls::updateSilentBroadcast() { return; } const auto &peer = _history->peer; - if (!session().data().notifySilentPostsUnknown(peer)) { - _silent->setChecked(session().data().notifySilentPosts(peer)); + if (!session().data().notifySettings().silentPostsUnknown(peer)) { + _silent->setChecked( + session().data().notifySettings().silentPosts(peer)); updateFieldPlaceholder(); } } @@ -2465,7 +2467,7 @@ bool ComposeControls::hasSilentBroadcastToggle() const { && peer->isChannel() && !peer->isMegagroup() && peer->canWrite() - && !session().data().notifySilentPostsUnknown(peer); + && !session().data().notifySettings().silentPostsUnknown(peer); } void ComposeControls::updateInlineBotQuery() { diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index b0b9bcc56..814a98ff4 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -174,7 +174,7 @@ rpl::producer NotificationsEnabledValue(not_null peer) { ) | rpl::to_empty, peer->owner().notifySettings().defaultNotifyUpdates(peer) ) | rpl::map([=] { - return !peer->owner().notifyIsMuted(peer); + return !peer->owner().notifySettings().isMuted(peer); }) | rpl::distinct_until_changed(); } diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp index c0c416eb0..30da9fadc 100644 --- a/Telegram/SourceFiles/menu/menu_mute.cpp +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -57,7 +57,7 @@ MuteItem::MuteItem( nullptr, nullptr) , _itemIconPosition(st.itemIconPosition) -, _isMuted(peer->owner().notifyIsMuted(peer)) { +, _isMuted(peer->owner().notifySettings().isMuted(peer)) { Info::Profile::NotificationsEnabledValue( peer @@ -135,14 +135,14 @@ void FillMuteMenu( Args args) { const auto peer = args.peer; - const auto soundIsNone = peer->owner().notifySoundIsNone(peer); + const auto soundIsNone = peer->owner().notifySettings().soundIsNone(peer); menu->addAction( soundIsNone ? tr::lng_mute_menu_sound_on(tr::now) : tr::lng_mute_menu_sound_off(tr::now), [=] { - const auto soundIsNone = peer->owner().notifySoundIsNone(peer); auto ¬ifySettings = peer->owner().notifySettings(); + const auto soundIsNone = notifySettings.soundIsNone(peer); notifySettings.updateNotifySettings(peer, {}, {}, !soundIsNone); }, soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff); diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 542427561..c84780389 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -812,8 +812,8 @@ SilentToggle::SilentToggle(QWidget *parent, not_null channel) : RippleButton(parent, st::historySilentToggle.ripple) , _st(st::historySilentToggle) , _channel(channel) -, _checked(channel->owner().notifySilentPosts(_channel)) { - Expects(!channel->owner().notifySilentPostsUnknown(_channel)); +, _checked(channel->owner().notifySettings().silentPosts(_channel)) { + Expects(!channel->owner().notifySettings().silentPostsUnknown(_channel)); resize(_st.width, _st.height); diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index d71b6c6e7..54ad82970 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -180,7 +180,8 @@ System::SkipState System::computeSkipState( .silent = (forceSilent || !messageNotification || item->isSilent() - || history->owner().notifySoundIsNone(history->peer)), + || history->owner().notifySettings().soundIsNone( + history->peer)), }; }; const auto showForMuted = messageNotification @@ -207,20 +208,20 @@ System::SkipState System::computeSkipState( } if (messageNotification - && history->owner().notifyMuteUnknown(history->peer)) { + && history->owner().notifySettings().muteUnknown(history->peer)) { return { SkipState::Unknown }; } else if (messageNotification - && !history->owner().notifyIsMuted(history->peer)) { + && !history->owner().notifySettings().isMuted(history->peer)) { return withSilent(SkipState::DontSkip); } else if (!notifyBy) { return withSilent( showForMuted ? SkipState::DontSkip : SkipState::Skip, showForMuted); - } else if (history->owner().notifyMuteUnknown(notifyBy) + } else if (history->owner().notifySettings().muteUnknown(notifyBy) || (!messageNotification && notifyBy->blockStatus() == PeerData::BlockStatus::Unknown)) { return withSilent(SkipState::Unknown); - } else if (!history->owner().notifyIsMuted(notifyBy) + } else if (!history->owner().notifySettings().isMuted(notifyBy) && (messageNotification || !notifyBy->isBlocked())) { return withSilent(SkipState::DontSkip); } else { @@ -470,14 +471,15 @@ void System::showNext() { for (auto i = _whenAlerts.begin(); i != _whenAlerts.end();) { while (!i->second.empty() && i->second.begin()->first <= ms) { const auto peer = i->first->peer; - const auto peerUnknown = peer->owner().notifyMuteUnknown(peer); + const auto ¬ifySettings = peer->owner().notifySettings(); + const auto peerUnknown = notifySettings.muteUnknown(peer); const auto peerAlert = !peerUnknown - && !peer->owner().notifyIsMuted(peer); + && !notifySettings.isMuted(peer); const auto from = i->second.begin()->second; const auto fromUnknown = (!from - || peer->owner().notifyMuteUnknown(from)); + || notifySettings.muteUnknown(from)); const auto fromAlert = !fromUnknown - && !peer->owner().notifyIsMuted(from); + && !notifySettings.isMuted(from); if (peerAlert || fromAlert) { alert = true; } diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index e8802f581..76685b313 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -132,7 +132,7 @@ void PeerMenuAddMuteSubmenuAction( not_null peer, const PeerMenuCallback &addAction) { peer->owner().notifySettings().requestNotifySettings(peer); - const auto isMuted = peer->owner().notifyIsMuted(peer); + const auto isMuted = peer->owner().notifySettings().isMuted(peer); if (isMuted) { const auto text = tr::lng_context_unmute(tr::now) + '\t' @@ -146,7 +146,7 @@ void PeerMenuAddMuteSubmenuAction( addAction(PeerMenuCallback::Args{ .text = tr::lng_context_mute(tr::now), .handler = nullptr, - .icon = peer->owner().notifySoundIsNone(peer) + .icon = peer->owner().notifySettings().soundIsNone(peer) ? &st::menuIconSilent : &st::menuIconMute, .fillSubmenu = [=](not_null menu) { @@ -1430,14 +1430,14 @@ void PeerMenuAddMuteAction( : tr::lng_context_unmute(tr::now); }; const auto muteAction = addAction(QString("-"), [=] { - if (!peer->owner().notifyIsMuted(peer)) { + if (!peer->owner().notifySettings().isMuted(peer)) { controller->show( Box(peer), Ui::LayerOption::CloseOther); } else { peer->owner().notifySettings().updateNotifySettings(peer, 0); } - }, (peer->owner().notifyIsMuted(peer) + }, (peer->owner().notifySettings().isMuted(peer) ? &st::menuIconUnmute : &st::menuIconMute));