1 //
2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #pragma once
8 
9 #include "td/telegram/td_api.h"
10 #include "td/telegram/telegram_api.h"
11 
12 #include "td/utils/common.h"
13 #include "td/utils/Status.h"
14 #include "td/utils/StringBuilder.h"
15 
16 namespace td {
17 
18 class DialogNotificationSettings {
19  public:
20   int32 mute_until = 0;
21   string sound = "default";
22   bool show_preview = true;
23   bool silent_send_message = false;
24   bool use_default_mute_until = true;
25   bool use_default_sound = true;
26   bool use_default_show_preview = true;
27   bool is_use_default_fixed = true;
28   bool is_secret_chat_show_preview_fixed = false;
29   bool is_synchronized = false;
30 
31   // local settings
32   bool use_default_disable_pinned_message_notifications = true;
33   bool disable_pinned_message_notifications = false;
34   bool use_default_disable_mention_notifications = true;
35   bool disable_mention_notifications = false;
36 
37   DialogNotificationSettings() = default;
38 
DialogNotificationSettings(bool use_default_mute_until,int32 mute_until,bool use_default_sound,string sound,bool use_default_show_preview,bool show_preview,bool silent_send_message,bool use_default_disable_pinned_message_notifications,bool disable_pinned_message_notifications,bool use_default_disable_mention_notifications,bool disable_mention_notifications)39   DialogNotificationSettings(bool use_default_mute_until, int32 mute_until, bool use_default_sound, string sound,
40                              bool use_default_show_preview, bool show_preview, bool silent_send_message,
41                              bool use_default_disable_pinned_message_notifications,
42                              bool disable_pinned_message_notifications, bool use_default_disable_mention_notifications,
43                              bool disable_mention_notifications)
44       : mute_until(mute_until)
45       , sound(std::move(sound))
46       , show_preview(show_preview)
47       , silent_send_message(silent_send_message)
48       , use_default_mute_until(use_default_mute_until)
49       , use_default_sound(use_default_sound)
50       , use_default_show_preview(use_default_show_preview)
51       , is_synchronized(true)
52       , use_default_disable_pinned_message_notifications(use_default_disable_pinned_message_notifications)
53       , disable_pinned_message_notifications(disable_pinned_message_notifications)
54       , use_default_disable_mention_notifications(use_default_disable_mention_notifications)
55       , disable_mention_notifications(disable_mention_notifications) {
56   }
57 };
58 
59 enum class NotificationSettingsScope : int32 { Private, Group, Channel };
60 
61 class ScopeNotificationSettings {
62  public:
63   int32 mute_until = 0;
64   string sound = "default";
65   bool show_preview = true;
66   bool is_synchronized = false;
67 
68   // local settings
69   bool disable_pinned_message_notifications = false;
70   bool disable_mention_notifications = false;
71 
72   ScopeNotificationSettings() = default;
73 
ScopeNotificationSettings(int32 mute_until,string sound,bool show_preview,bool disable_pinned_message_notifications,bool disable_mention_notifications)74   ScopeNotificationSettings(int32 mute_until, string sound, bool show_preview,
75                             bool disable_pinned_message_notifications, bool disable_mention_notifications)
76       : mute_until(mute_until)
77       , sound(std::move(sound))
78       , show_preview(show_preview)
79       , is_synchronized(true)
80       , disable_pinned_message_notifications(disable_pinned_message_notifications)
81       , disable_mention_notifications(disable_mention_notifications) {
82   }
83 };
84 
85 StringBuilder &operator<<(StringBuilder &string_builder, const DialogNotificationSettings &notification_settings);
86 
87 StringBuilder &operator<<(StringBuilder &string_builder, NotificationSettingsScope scope);
88 
89 StringBuilder &operator<<(StringBuilder &string_builder, const ScopeNotificationSettings &notification_settings);
90 
91 td_api::object_ptr<td_api::NotificationSettingsScope> get_notification_settings_scope_object(
92     NotificationSettingsScope scope);
93 
94 td_api::object_ptr<td_api::chatNotificationSettings> get_chat_notification_settings_object(
95     const DialogNotificationSettings *notification_settings);
96 
97 td_api::object_ptr<td_api::scopeNotificationSettings> get_scope_notification_settings_object(
98     const ScopeNotificationSettings *notification_settings);
99 
100 telegram_api::object_ptr<telegram_api::InputNotifyPeer> get_input_notify_peer(NotificationSettingsScope scope);
101 
102 NotificationSettingsScope get_notification_settings_scope(
103     const td_api::object_ptr<td_api::NotificationSettingsScope> &scope);
104 
105 Result<DialogNotificationSettings> get_dialog_notification_settings(
106     td_api::object_ptr<td_api::chatNotificationSettings> &&notification_settings, bool old_silent_send_message);
107 
108 Result<ScopeNotificationSettings> get_scope_notification_settings(
109     td_api::object_ptr<td_api::scopeNotificationSettings> &&notification_settings);
110 
111 DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings,
112                                                             bool old_use_default_disable_pinned_message_notifications,
113                                                             bool old_disable_pinned_message_notifications,
114                                                             bool old_use_default_disable_mention_notifications,
115                                                             bool old_disable_mention_notifications);
116 
117 ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings,
118                                                           bool old_disable_pinned_message_notifications,
119                                                           bool old_disable_mention_notifications);
120 
121 bool are_default_dialog_notification_settings(const DialogNotificationSettings &settings, bool compare_sound);
122 
123 }  // namespace td
124