diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 506d3e112..b51f8f9a4 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -1908,7 +1908,7 @@ void Updates::feedUpdate(const MTPUpdate &update) { case mtpc_updateNotifySettings: { auto &d = update.c_updateNotifySettings(); - session().data().notifySettings().applyNotifySetting( + session().data().notifySettings().apply( d.vpeer(), d.vnotify_settings()); } break; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 64f219445..919794b9d 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2095,20 +2095,20 @@ void ApiWrap::applyNotifySettings( auto ¬ifySettings = _session->data().notifySettings(); switch (notifyPeer.type()) { case mtpc_inputNotifyUsers: - notifySettings.applyNotifySetting(MTP_notifyUsers(), settings); + notifySettings.apply(MTP_notifyUsers(), settings); break; case mtpc_inputNotifyChats: - notifySettings.applyNotifySetting(MTP_notifyChats(), settings); + notifySettings.apply(MTP_notifyChats(), settings); break; case mtpc_inputNotifyBroadcasts: - notifySettings.applyNotifySetting( + notifySettings.apply( MTP_notifyBroadcasts(), settings); break; case mtpc_inputNotifyPeer: { auto &peer = notifyPeer.c_inputNotifyPeer().vpeer(); const auto apply = [&](PeerId peerId) { - notifySettings.applyNotifySetting( + notifySettings.apply( MTP_notifyPeer(peerToMTP(peerId)), settings); }; diff --git a/Telegram/SourceFiles/boxes/mute_settings_box.cpp b/Telegram/SourceFiles/boxes/mute_settings_box.cpp index 6ec93f792..07da7ca13 100644 --- a/Telegram/SourceFiles/boxes/mute_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/mute_settings_box.cpp @@ -76,9 +76,7 @@ void MuteSettingsBox::prepare() { _save = [=] { const auto muteForSeconds = group->value() * 3600; - _peer->owner().notifySettings().updateNotifySettings( - _peer, - muteForSeconds); + _peer->owner().notifySettings().update(_peer, muteForSeconds); closeBox(); }; addButton(tr::lng_box_ok(), _save); diff --git a/Telegram/SourceFiles/boxes/ringtones_box.cpp b/Telegram/SourceFiles/boxes/ringtones_box.cpp index 92a4d0a40..1e929eb08 100644 --- a/Telegram/SourceFiles/boxes/ringtones_box.cpp +++ b/Telegram/SourceFiles/boxes/ringtones_box.cpp @@ -222,11 +222,7 @@ void RingtonesBox( : (value == kNoSoundValue) ? Data::NotifySound{ .none = true } : Data::NotifySound{ .id = state->documentIds[value] }; - peer->owner().notifySettings().updateNotifySettings( - peer, - std::nullopt, - std::nullopt, - sound); + peer->owner().notifySettings().update(peer, {}, {}, sound); box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); diff --git a/Telegram/SourceFiles/data/notify/data_notify_settings.cpp b/Telegram/SourceFiles/data/notify/data_notify_settings.cpp index 1079fb733..bb361c9c6 100644 --- a/Telegram/SourceFiles/data/notify/data_notify_settings.cpp +++ b/Telegram/SourceFiles/data/notify/data_notify_settings.cpp @@ -33,7 +33,7 @@ NotifySettings::NotifySettings(not_null owner) , _unmuteByFinishedTimer([=] { unmuteByFinished(); }) { } -void NotifySettings::requestNotifySettings(not_null peer) { +void NotifySettings::request(not_null peer) { if (peer->notifySettingsUnknown()) { peer->session().api().requestNotifySettings( MTP_inputNotifyPeer(peer->input)); @@ -47,7 +47,7 @@ void NotifySettings::requestNotifySettings(not_null peer) { } } -void NotifySettings::applyNotifySetting( +void NotifySettings::apply( const MTPNotifyPeer ¬ifyPeer, const MTPPeerNotifySettings &settings) { const auto goodForUpdate = [&]( @@ -61,34 +61,34 @@ void NotifySettings::applyNotifySetting( switch (notifyPeer.type()) { case mtpc_notifyUsers: { - if (_defaultUserNotifySettings.change(settings)) { - _defaultUserNotifyUpdates.fire({}); + if (_defaultUser.change(settings)) { + _defaultUserUpdates.fire({}); _owner->enumerateUsers([&](not_null user) { - if (goodForUpdate(user, _defaultUserNotifySettings)) { - updateNotifySettingsLocal(user); + if (goodForUpdate(user, _defaultUser)) { + updateLocal(user); } }); } } break; case mtpc_notifyChats: { - if (_defaultChatNotifySettings.change(settings)) { - _defaultChatNotifyUpdates.fire({}); + if (_defaultChat.change(settings)) { + _defaultChatUpdates.fire({}); _owner->enumerateGroups([&](not_null peer) { - if (goodForUpdate(peer, _defaultChatNotifySettings)) { - updateNotifySettingsLocal(peer); + if (goodForUpdate(peer, _defaultChat)) { + updateLocal(peer); } }); } } break; case mtpc_notifyBroadcasts: { - if (_defaultBroadcastNotifySettings.change(settings)) { - _defaultBroadcastNotifyUpdates.fire({}); + if (_defaultBroadcast.change(settings)) { + _defaultBroadcastUpdates.fire({}); _owner->enumerateChannels([&](not_null channel) { - if (goodForUpdate(channel, _defaultBroadcastNotifySettings)) { - updateNotifySettingsLocal(channel); + if (goodForUpdate(channel, _defaultBroadcast)) { + updateLocal(channel); } }); } @@ -97,25 +97,25 @@ void NotifySettings::applyNotifySetting( const auto &data = notifyPeer.c_notifyPeer(); if (const auto peer = _owner->peerLoaded(peerFromMTP(data.vpeer()))) { if (peer->notifyChange(settings)) { - updateNotifySettingsLocal(peer); + updateLocal(peer); } } } break; } } -void NotifySettings::updateNotifySettings( +void NotifySettings::update( not_null peer, std::optional muteForSeconds, std::optional silentPosts, std::optional sound) { if (peer->notifyChange(muteForSeconds, silentPosts, sound)) { - updateNotifySettingsLocal(peer); + updateLocal(peer); peer->session().api().updateNotifySettingsDelayed(peer); } } -void NotifySettings::resetNotifySettingsToDefault(not_null peer) { +void NotifySettings::resetToDefault(not_null peer) { const auto empty = MTP_peerNotifySettings( MTP_flags(0), MTPBool(), @@ -125,7 +125,7 @@ void NotifySettings::resetNotifySettingsToDefault(not_null peer) { MTPNotificationSound(), MTPNotificationSound()); if (peer->notifyChange(empty)) { - updateNotifySettingsLocal(peer); + updateLocal(peer); peer->session().api().updateNotifySettingsDelayed(peer); } } @@ -133,13 +133,13 @@ void NotifySettings::resetNotifySettingsToDefault(not_null peer) { const PeerNotifySettings &NotifySettings::defaultNotifySettings( not_null peer) const { return peer->isUser() - ? _defaultUserNotifySettings + ? _defaultUser : (peer->isChat() || peer->isMegagroup()) - ? _defaultChatNotifySettings - : _defaultBroadcastNotifySettings; + ? _defaultChat + : _defaultBroadcast; } -void NotifySettings::updateNotifySettingsLocal(not_null peer) { +void NotifySettings::updateLocal(not_null peer) { const auto history = _owner->historyLoaded(peer->id); auto changesIn = crl::time(0); const auto muted = isMuted(peer, &changesIn); @@ -281,15 +281,15 @@ bool NotifySettings::settingsUnknown(not_null peer) const { } rpl::producer<> NotifySettings::defaultUserNotifyUpdates() const { - return _defaultUserNotifyUpdates.events(); + return _defaultUserUpdates.events(); } rpl::producer<> NotifySettings::defaultChatNotifyUpdates() const { - return _defaultChatNotifyUpdates.events(); + return _defaultChatUpdates.events(); } rpl::producer<> NotifySettings::defaultBroadcastNotifyUpdates() const { - return _defaultBroadcastNotifyUpdates.events(); + return _defaultBroadcastUpdates.events(); } rpl::producer<> NotifySettings::defaultNotifyUpdates( diff --git a/Telegram/SourceFiles/data/notify/data_notify_settings.h b/Telegram/SourceFiles/data/notify/data_notify_settings.h index 732e8ee8c..54396dfcc 100644 --- a/Telegram/SourceFiles/data/notify/data_notify_settings.h +++ b/Telegram/SourceFiles/data/notify/data_notify_settings.h @@ -21,16 +21,16 @@ class NotifySettings final { public: NotifySettings(not_null owner); - void requestNotifySettings(not_null peer); - void applyNotifySetting( + void request(not_null peer); + void apply( const MTPNotifyPeer ¬ifyPeer, const MTPPeerNotifySettings &settings); - void updateNotifySettings( + void update( not_null peer, std::optional muteForSeconds, std::optional silentPosts = std::nullopt, std::optional sound = std::nullopt); - void resetNotifySettingsToDefault(not_null peer); + void resetToDefault(not_null peer); [[nodiscard]] rpl::producer<> defaultUserNotifyUpdates() const; [[nodiscard]] rpl::producer<> defaultChatNotifyUpdates() const; @@ -57,16 +57,16 @@ private: void unmuteByFinished(); void unmuteByFinishedDelayed(crl::time delay); - void updateNotifySettingsLocal(not_null peer); + void updateLocal(not_null peer); const not_null _owner; - PeerNotifySettings _defaultUserNotifySettings; - PeerNotifySettings _defaultChatNotifySettings; - PeerNotifySettings _defaultBroadcastNotifySettings; - rpl::event_stream<> _defaultUserNotifyUpdates; - rpl::event_stream<> _defaultChatNotifyUpdates; - rpl::event_stream<> _defaultBroadcastNotifyUpdates; + PeerNotifySettings _defaultUser; + PeerNotifySettings _defaultChat; + PeerNotifySettings _defaultBroadcast; + rpl::event_stream<> _defaultUserUpdates; + rpl::event_stream<> _defaultChatUpdates; + rpl::event_stream<> _defaultBroadcastUpdates; std::unordered_set> _mutedPeers; base::Timer _unmuteByFinishedTimer; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 3b910e617..722f4cd48 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2554,7 +2554,7 @@ void History::applyDialog( } } } - owner().notifySettings().applyNotifySetting( + owner().notifySettings().apply( MTP_notifyPeer(data.vpeer()), data.vnotify_settings()); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 9074bafe7..00fca145f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2238,7 +2238,7 @@ void HistoryWidget::showHistory( if (_peer->isChannel()) { updateNotifyControls(); - session().data().notifySettings().requestNotifySettings(_peer); + session().data().notifySettings().request(_peer); refreshSilentToggle(); } else if (_peer->isRepliesChat()) { updateNotifyControls(); @@ -3852,9 +3852,7 @@ void HistoryWidget::toggleMuteUnmute() { const auto muteForSeconds = _history->mute() ? 0 : Data::PeerNotifySettings::kDefaultMutePeriod; - session().data().notifySettings().updateNotifySettings( - _peer, - muteForSeconds); + session().data().notifySettings().update(_peer, muteForSeconds); } void HistoryWidget::reportSelectedMessages() { diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index be7144566..4440db7c4 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -474,7 +474,7 @@ void ContactStatus::setupUnarchiveHandler(not_null peer) { _bar.entity()->unarchiveClicks( ) | rpl::start_with_next([=] { Window::ToggleHistoryArchived(peer->owner().history(peer), false); - peer->owner().notifySettings().resetNotifySettingsToDefault(peer); + peer->owner().notifySettings().resetToDefault(peer); if (const auto settings = peer->settings()) { const auto flags = PeerSetting::AutoArchived | PeerSetting::BlockContact diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp index 4c9081a1f..49c41cee8 100644 --- a/Telegram/SourceFiles/menu/menu_mute.cpp +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -112,7 +112,7 @@ MuteItem::MuteItem( }, lifetime()); setClickedCallback([=] { - peer->owner().notifySettings().updateNotifySettings( + peer->owner().notifySettings().update( peer, _isMuted ? 0 : Data::PeerNotifySettings::kDefaultMutePeriod); }); @@ -154,9 +154,7 @@ void MuteBox(not_null box, not_null peer) { : tr::lng_mute_menu_mute(); }) | rpl::flatten_latest(); const auto confirm = box->addButton(std::move(confirmText), [=] { - peer->owner().notifySettings().updateNotifySettings( - peer, - state->lastSeconds); + peer->owner().notifySettings().update(peer, state->lastSeconds); box->getDelegate()->hideLayer(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); @@ -194,7 +192,7 @@ void PickMuteBox(not_null box, not_null peer) { box->addButton(tr::lng_mute_menu_mute(), [=] { const auto muteFor = pickerCallback(); - peer->owner().notifySettings().updateNotifySettings(peer, muteFor); + peer->owner().notifySettings().update(peer, muteFor); peer->session().settings().addMutePeriod(muteFor); peer->session().saveSettings(); box->closeBox(); @@ -245,7 +243,7 @@ void FillMuteMenu( auto ¬ifySettings = peer->owner().notifySettings(); auto sound = notifySettings.sound(peer); sound.none = !sound.none; - notifySettings.updateNotifySettings(peer, {}, {}, sound); + notifySettings.update(peer, {}, {}, sound); }, soundIsNone ? &st::menuIconSoundOn : &st::menuIconSoundOff); @@ -254,9 +252,7 @@ void FillMuteMenu( + st::menuIconMuteForAnyTextPosition; for (const auto &muteFor : peer->session().settings().mutePeriods()) { const auto callback = [=] { - peer->owner().notifySettings().updateNotifySettings( - peer, - muteFor); + peer->owner().notifySettings().update(peer, muteFor); }; auto item = base::make_unique_q( diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index c84780389..00f871785 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -865,10 +865,7 @@ void SilentToggle::mouseReleaseEvent(QMouseEvent *e) { setChecked(!_checked); RippleButton::mouseReleaseEvent(e); Ui::Tooltip::Show(0, this); - _channel->owner().notifySettings().updateNotifySettings( - _channel, - std::nullopt, - _checked); + _channel->owner().notifySettings().update(_channel, {}, _checked); } QString SilentToggle::tooltipText() const { diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index f140e3e82..67472115e 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -198,13 +198,13 @@ System::SkipState System::computeSkipState( } if (messageNotification) { - history->owner().notifySettings().requestNotifySettings( + history->owner().notifySettings().request( history->peer); } else if (notifyBy->blockStatus() == PeerData::BlockStatus::Unknown) { notifyBy->updateFull(); } if (notifyBy) { - history->owner().notifySettings().requestNotifySettings(notifyBy); + history->owner().notifySettings().request(notifyBy); } if (messageNotification diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 8ec46e7ca..f2b0e043e 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -131,7 +131,7 @@ void PeerMenuAddMuteSubmenuAction( not_null controller, not_null peer, const PeerMenuCallback &addAction) { - peer->owner().notifySettings().requestNotifySettings(peer); + peer->owner().notifySettings().request(peer); const auto isMuted = peer->owner().notifySettings().isMuted(peer); if (isMuted) { const auto text = tr::lng_context_unmute(tr::now) @@ -139,7 +139,7 @@ void PeerMenuAddMuteSubmenuAction( + Ui::FormatMuteForTiny(peer->notifyMuteUntil().value_or(0) - base::unixtime::now()); addAction(text, [=] { - peer->owner().notifySettings().updateNotifySettings(peer, 0); + peer->owner().notifySettings().update(peer, 0); }, &st::menuIconUnmute); } else { const auto show = std::make_shared(controller); @@ -1426,7 +1426,7 @@ void PeerMenuAddMuteAction( not_null peer, const PeerMenuCallback &addAction) { // There is no async to make weak from controller. - peer->owner().notifySettings().requestNotifySettings(peer); + peer->owner().notifySettings().request(peer); const auto muteText = [](bool isUnmuted) { return isUnmuted ? tr::lng_context_mute(tr::now) @@ -1438,7 +1438,7 @@ void PeerMenuAddMuteAction( Box(peer), Ui::LayerOption::CloseOther); } else { - peer->owner().notifySettings().updateNotifySettings(peer, 0); + peer->owner().notifySettings().update(peer, 0); } }, (peer->owner().notifySettings().isMuted(peer) ? &st::menuIconUnmute