/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "data/notify/data_peer_notify_settings.h" #include "base/timer.h" class PeerData; namespace Data { class DocumentMedia; class Session; class Thread; class Forum; class ForumTopic; enum class DefaultNotify { User, Group, Broadcast, }; [[nodiscard]] DefaultNotify DefaultNotifyType( not_null peer); [[nodiscard]] MTPInputNotifyPeer DefaultNotifyToMTP(DefaultNotify type); class NotifySettings final { public: NotifySettings(not_null owner); void request(not_null peer); void request(not_null thread); void apply( const MTPNotifyPeer ¬ifyPeer, const MTPPeerNotifySettings &settings); void apply( const MTPInputNotifyPeer ¬ifyPeer, const MTPPeerNotifySettings &settings); void apply(DefaultNotify type, const MTPPeerNotifySettings &settings); void apply(PeerId peerId, const MTPPeerNotifySettings &settings); void apply( not_null peer, const MTPPeerNotifySettings &settings); void apply( PeerId peerId, MsgId topicRootId, const MTPPeerNotifySettings &settings); void apply( not_null topic, const MTPPeerNotifySettings &settings); void update( not_null thread, MuteValue muteForSeconds, std::optional silentPosts = std::nullopt, std::optional sound = std::nullopt, std::optional storiesMuted = std::nullopt); void resetToDefault(not_null thread); void update( not_null peer, MuteValue muteForSeconds, std::optional silentPosts = std::nullopt, std::optional sound = std::nullopt, std::optional storiesMuted = std::nullopt); void resetToDefault(not_null peer); void forumParentMuteUpdated(not_null forum); void cacheSound(DocumentId id); void cacheSound(not_null document); [[nodiscard]] std::shared_ptr lookupRingtone( DocumentId id) const; [[nodiscard]] rpl::producer<> defaultUpdates(DefaultNotify type) const; [[nodiscard]] rpl::producer<> defaultUpdates( not_null peer) const; [[nodiscard]] const PeerNotifySettings &defaultSettings( DefaultNotify type) const; [[nodiscard]] bool isMuted(DefaultNotify type) const; void defaultUpdate( DefaultNotify type, MuteValue muteForSeconds, std::optional silentPosts = std::nullopt, std::optional sound = std::nullopt, std::optional storiesMuted = std::nullopt); [[nodiscard]] bool isMuted(not_null thread) const; [[nodiscard]] NotifySound sound(not_null thread) const; [[nodiscard]] bool muteUnknown(not_null thread) const; [[nodiscard]] bool soundUnknown(not_null thread) const; [[nodiscard]] bool isMuted(not_null peer) const; [[nodiscard]] bool silentPosts(not_null peer) const; [[nodiscard]] NotifySound sound(not_null peer) const; [[nodiscard]] bool muteUnknown(not_null peer) const; [[nodiscard]] bool silentPostsUnknown( not_null peer) const; [[nodiscard]] bool soundUnknown(not_null peer) const; void loadExceptions(); [[nodiscard]] rpl::producer exceptionsUpdates() const; [[nodiscard]] auto exceptionsUpdatesRealtime() const -> rpl::producer; [[nodiscard]] const base::flat_set> &exceptions( DefaultNotify type) const; void clearExceptions(DefaultNotify type); private: static constexpr auto kDefaultNotifyTypes = 3; struct DefaultValue { PeerNotifySettings settings; rpl::event_stream<> updates; }; void cacheSound(const std::optional &sound); [[nodiscard]] bool isMuted( not_null thread, crl::time *changesIn) const; [[nodiscard]] bool isMuted( not_null peer, crl::time *changesIn) const; [[nodiscard]] DefaultValue &defaultValue(DefaultNotify type); [[nodiscard]] const DefaultValue &defaultValue(DefaultNotify type) const; [[nodiscard]] const PeerNotifySettings &defaultSettings( not_null peer) const; [[nodiscard]] bool settingsUnknown(not_null peer) const; [[nodiscard]] bool settingsUnknown( not_null thread) const; void unmuteByFinished(); void unmuteByFinishedDelayed(crl::time delay); void updateLocal(not_null thread); void updateLocal(not_null peer); void updateLocal(DefaultNotify type); void updateException(not_null peer); void exceptionsUpdated(DefaultNotify type); const not_null _owner; DefaultValue _defaultValues[3]; std::unordered_set> _mutedPeers; std::unordered_map, rpl::lifetime> _mutedTopics; base::Timer _unmuteByFinishedTimer; struct { base::flat_map< DocumentId, std::shared_ptr> views; std::vector pendingIds; rpl::lifetime pendingLifetime; } _ringtones; rpl::event_stream _exceptionsUpdates; rpl::event_stream _exceptionsUpdatesRealtime; std::array< base::flat_set>, kDefaultNotifyTypes> _exceptions; std::array _exceptionsRequestId = {}; std::array _exceptionsUpdatesScheduled = {}; }; } // namespace Data