2022-04-01 10:18:07 +00:00
|
|
|
/*
|
|
|
|
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 {
|
|
|
|
|
2022-04-05 12:26:18 +00:00
|
|
|
class DocumentMedia;
|
2022-04-01 10:18:07 +00:00
|
|
|
class Session;
|
2022-10-13 17:34:04 +00:00
|
|
|
class Thread;
|
2022-10-13 18:02:31 +00:00
|
|
|
class Forum;
|
2022-10-12 20:23:14 +00:00
|
|
|
class ForumTopic;
|
2022-04-01 10:18:07 +00:00
|
|
|
|
2022-04-06 15:23:41 +00:00
|
|
|
enum class DefaultNotify {
|
|
|
|
User,
|
|
|
|
Group,
|
|
|
|
Broadcast,
|
|
|
|
};
|
2023-08-23 11:20:41 +00:00
|
|
|
[[nodiscard]] DefaultNotify DefaultNotifyType(
|
|
|
|
not_null<const PeerData*> peer);
|
|
|
|
|
|
|
|
[[nodiscard]] MTPInputNotifyPeer DefaultNotifyToMTP(DefaultNotify type);
|
2022-04-06 15:23:41 +00:00
|
|
|
|
2022-04-01 10:18:07 +00:00
|
|
|
class NotifySettings final {
|
|
|
|
public:
|
|
|
|
NotifySettings(not_null<Session*> owner);
|
|
|
|
|
2022-04-05 06:16:16 +00:00
|
|
|
void request(not_null<PeerData*> peer);
|
2023-08-23 11:20:41 +00:00
|
|
|
void request(not_null<Thread*> thread);
|
2022-10-13 17:34:04 +00:00
|
|
|
|
2022-04-05 06:16:16 +00:00
|
|
|
void apply(
|
2022-04-01 10:18:07 +00:00
|
|
|
const MTPNotifyPeer ¬ifyPeer,
|
|
|
|
const MTPPeerNotifySettings &settings);
|
2022-10-13 17:34:04 +00:00
|
|
|
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<PeerData*> peer,
|
|
|
|
const MTPPeerNotifySettings &settings);
|
|
|
|
void apply(
|
|
|
|
PeerId peerId,
|
|
|
|
MsgId topicRootId,
|
|
|
|
const MTPPeerNotifySettings &settings);
|
|
|
|
void apply(
|
2023-08-23 11:20:41 +00:00
|
|
|
not_null<ForumTopic*> topic,
|
2022-10-13 17:34:04 +00:00
|
|
|
const MTPPeerNotifySettings &settings);
|
|
|
|
|
|
|
|
void update(
|
2023-08-23 11:20:41 +00:00
|
|
|
not_null<Thread*> thread,
|
|
|
|
MuteValue muteForSeconds,
|
2022-10-13 17:34:04 +00:00
|
|
|
std::optional<bool> silentPosts = std::nullopt,
|
2023-06-09 15:31:51 +00:00
|
|
|
std::optional<NotifySound> sound = std::nullopt,
|
|
|
|
std::optional<bool> storiesMuted = std::nullopt);
|
2023-08-23 11:20:41 +00:00
|
|
|
void resetToDefault(not_null<Thread*> thread);
|
2022-04-05 06:16:16 +00:00
|
|
|
void update(
|
2022-04-01 10:18:07 +00:00
|
|
|
not_null<PeerData*> peer,
|
2023-08-23 11:20:41 +00:00
|
|
|
MuteValue muteForSeconds,
|
2022-04-01 10:18:07 +00:00
|
|
|
std::optional<bool> silentPosts = std::nullopt,
|
2023-06-09 15:31:51 +00:00
|
|
|
std::optional<NotifySound> sound = std::nullopt,
|
|
|
|
std::optional<bool> storiesMuted = std::nullopt);
|
2022-04-05 06:16:16 +00:00
|
|
|
void resetToDefault(not_null<PeerData*> peer);
|
2022-04-01 10:18:07 +00:00
|
|
|
|
2023-08-23 11:20:41 +00:00
|
|
|
void forumParentMuteUpdated(not_null<Forum*> forum);
|
2022-10-13 18:02:31 +00:00
|
|
|
|
2022-04-07 07:34:29 +00:00
|
|
|
void cacheSound(DocumentId id);
|
|
|
|
void cacheSound(not_null<DocumentData*> document);
|
|
|
|
[[nodiscard]] std::shared_ptr<DocumentMedia> lookupRingtone(
|
|
|
|
DocumentId id) const;
|
2022-04-05 12:26:18 +00:00
|
|
|
|
2022-04-06 15:23:41 +00:00
|
|
|
[[nodiscard]] rpl::producer<> defaultUpdates(DefaultNotify type) const;
|
|
|
|
[[nodiscard]] rpl::producer<> defaultUpdates(
|
2022-04-01 10:18:07 +00:00
|
|
|
not_null<const PeerData*> peer) const;
|
|
|
|
|
2022-04-06 15:23:41 +00:00
|
|
|
[[nodiscard]] const PeerNotifySettings &defaultSettings(
|
|
|
|
DefaultNotify type) const;
|
2023-08-23 17:29:56 +00:00
|
|
|
[[nodiscard]] bool isMuted(DefaultNotify type) const;
|
2022-04-06 15:23:41 +00:00
|
|
|
|
|
|
|
void defaultUpdate(
|
|
|
|
DefaultNotify type,
|
2023-08-23 11:20:41 +00:00
|
|
|
MuteValue muteForSeconds,
|
2022-04-06 15:23:41 +00:00
|
|
|
std::optional<bool> silentPosts = std::nullopt,
|
2023-06-09 15:31:51 +00:00
|
|
|
std::optional<NotifySound> sound = std::nullopt,
|
|
|
|
std::optional<bool> storiesMuted = std::nullopt);
|
2022-04-06 15:23:41 +00:00
|
|
|
|
2023-08-23 11:20:41 +00:00
|
|
|
[[nodiscard]] bool isMuted(not_null<const Thread*> thread) const;
|
|
|
|
[[nodiscard]] NotifySound sound(not_null<const Thread*> thread) const;
|
|
|
|
[[nodiscard]] bool muteUnknown(not_null<const Thread*> thread) const;
|
|
|
|
[[nodiscard]] bool soundUnknown(not_null<const Thread*> thread) const;
|
2022-10-12 20:23:14 +00:00
|
|
|
|
2022-04-01 10:36:33 +00:00
|
|
|
[[nodiscard]] bool isMuted(not_null<const PeerData*> peer) const;
|
|
|
|
[[nodiscard]] bool silentPosts(not_null<const PeerData*> peer) const;
|
2022-04-04 21:10:15 +00:00
|
|
|
[[nodiscard]] NotifySound sound(not_null<const PeerData*> peer) const;
|
2022-04-01 10:36:33 +00:00
|
|
|
[[nodiscard]] bool muteUnknown(not_null<const PeerData*> peer) const;
|
|
|
|
[[nodiscard]] bool silentPostsUnknown(
|
|
|
|
not_null<const PeerData*> peer) const;
|
2022-04-04 21:10:15 +00:00
|
|
|
[[nodiscard]] bool soundUnknown(not_null<const PeerData*> peer) const;
|
2022-04-01 10:36:33 +00:00
|
|
|
|
2023-08-23 11:20:41 +00:00
|
|
|
void loadExceptions();
|
|
|
|
[[nodiscard]] rpl::producer<DefaultNotify> exceptionsUpdates() const;
|
|
|
|
[[nodiscard]] auto exceptionsUpdatesRealtime() const
|
|
|
|
-> rpl::producer<DefaultNotify>;
|
|
|
|
[[nodiscard]] const base::flat_set<not_null<PeerData*>> &exceptions(
|
|
|
|
DefaultNotify type) const;
|
|
|
|
void clearExceptions(DefaultNotify type);
|
|
|
|
|
2022-04-01 10:36:33 +00:00
|
|
|
private:
|
2023-08-23 11:20:41 +00:00
|
|
|
static constexpr auto kDefaultNotifyTypes = 3;
|
|
|
|
|
2022-04-06 15:23:41 +00:00
|
|
|
struct DefaultValue {
|
|
|
|
PeerNotifySettings settings;
|
|
|
|
rpl::event_stream<> updates;
|
|
|
|
};
|
|
|
|
|
2022-05-03 12:23:39 +00:00
|
|
|
void cacheSound(const std::optional<NotifySound> &sound);
|
|
|
|
|
2022-10-12 20:23:14 +00:00
|
|
|
[[nodiscard]] bool isMuted(
|
2023-08-23 11:20:41 +00:00
|
|
|
not_null<const Thread*> thread,
|
2022-10-12 20:23:14 +00:00
|
|
|
crl::time *changesIn) const;
|
2022-04-01 10:36:33 +00:00
|
|
|
[[nodiscard]] bool isMuted(
|
2022-04-01 10:18:07 +00:00
|
|
|
not_null<const PeerData*> peer,
|
|
|
|
crl::time *changesIn) const;
|
|
|
|
|
2022-04-06 15:23:41 +00:00
|
|
|
[[nodiscard]] DefaultValue &defaultValue(DefaultNotify type);
|
|
|
|
[[nodiscard]] const DefaultValue &defaultValue(DefaultNotify type) const;
|
|
|
|
[[nodiscard]] const PeerNotifySettings &defaultSettings(
|
2022-04-01 10:18:07 +00:00
|
|
|
not_null<const PeerData*> peer) const;
|
2022-04-01 10:36:33 +00:00
|
|
|
[[nodiscard]] bool settingsUnknown(not_null<const PeerData*> peer) const;
|
2022-10-12 20:23:14 +00:00
|
|
|
[[nodiscard]] bool settingsUnknown(
|
2023-08-23 11:20:41 +00:00
|
|
|
not_null<const Thread*> thread) const;
|
2022-04-01 10:36:33 +00:00
|
|
|
|
2022-04-01 10:18:07 +00:00
|
|
|
void unmuteByFinished();
|
|
|
|
void unmuteByFinishedDelayed(crl::time delay);
|
2023-08-23 11:20:41 +00:00
|
|
|
void updateLocal(not_null<Thread*> thread);
|
2022-04-05 06:16:16 +00:00
|
|
|
void updateLocal(not_null<PeerData*> peer);
|
2022-04-06 15:23:41 +00:00
|
|
|
void updateLocal(DefaultNotify type);
|
2022-04-01 10:18:07 +00:00
|
|
|
|
2023-08-23 11:20:41 +00:00
|
|
|
void updateException(not_null<PeerData*> peer);
|
|
|
|
void exceptionsUpdated(DefaultNotify type);
|
|
|
|
|
2022-04-01 10:18:07 +00:00
|
|
|
const not_null<Session*> _owner;
|
|
|
|
|
2022-04-06 15:23:41 +00:00
|
|
|
DefaultValue _defaultValues[3];
|
2022-04-01 10:18:07 +00:00
|
|
|
std::unordered_set<not_null<const PeerData*>> _mutedPeers;
|
2023-08-23 11:20:41 +00:00
|
|
|
std::unordered_map<not_null<ForumTopic*>, rpl::lifetime> _mutedTopics;
|
2022-04-01 10:18:07 +00:00
|
|
|
base::Timer _unmuteByFinishedTimer;
|
|
|
|
|
2022-04-05 12:26:18 +00:00
|
|
|
struct {
|
|
|
|
base::flat_map<
|
|
|
|
DocumentId,
|
|
|
|
std::shared_ptr<DocumentMedia>> views;
|
|
|
|
std::vector<DocumentId> pendingIds;
|
|
|
|
rpl::lifetime pendingLifetime;
|
|
|
|
} _ringtones;
|
|
|
|
|
2023-08-23 11:20:41 +00:00
|
|
|
rpl::event_stream<DefaultNotify> _exceptionsUpdates;
|
|
|
|
rpl::event_stream<DefaultNotify> _exceptionsUpdatesRealtime;
|
|
|
|
std::array<
|
|
|
|
base::flat_set<not_null<PeerData*>>,
|
|
|
|
kDefaultNotifyTypes> _exceptions;
|
|
|
|
std::array<mtpRequestId, kDefaultNotifyTypes> _exceptionsRequestId = {};
|
|
|
|
std::array<bool, kDefaultNotifyTypes> _exceptionsUpdatesScheduled = {};
|
|
|
|
|
2022-04-01 10:18:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|