2022-04-04 23:40:22 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2022-04-04 23:40:22 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2022-04-08 16:17:56 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
2022-10-25 00:22:04 +02:00
|
|
|
#include "td/telegram/DialogNotificationSettings.h"
|
2022-04-12 21:50:20 +02:00
|
|
|
#include "td/telegram/files/FileId.h"
|
2022-04-15 15:27:30 +02:00
|
|
|
#include "td/telegram/files/FileSourceId.h"
|
2023-09-21 18:11:17 +02:00
|
|
|
#include "td/telegram/MessageFullId.h"
|
2022-12-06 12:53:54 +01:00
|
|
|
#include "td/telegram/MessageId.h"
|
2022-10-25 00:22:04 +02:00
|
|
|
#include "td/telegram/NotificationSettingsScope.h"
|
2024-04-24 16:33:06 +02:00
|
|
|
#include "td/telegram/ReactionNotificationSettings.h"
|
2022-10-25 00:22:04 +02:00
|
|
|
#include "td/telegram/ScopeNotificationSettings.h"
|
2022-04-11 11:45:52 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2022-04-08 16:17:56 +02:00
|
|
|
|
2022-04-04 23:40:22 +02:00
|
|
|
#include "td/actor/actor.h"
|
2022-07-02 22:32:18 +02:00
|
|
|
#include "td/actor/MultiTimeout.h"
|
2022-04-04 23:40:22 +02:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-04-08 16:17:56 +02:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2022-04-10 21:10:41 +02:00
|
|
|
#include "td/utils/Status.h"
|
2022-04-04 23:40:22 +02:00
|
|
|
|
2022-04-15 13:07:54 +02:00
|
|
|
#include <memory>
|
2023-08-22 17:55:59 +02:00
|
|
|
#include <utility>
|
2022-04-15 13:07:54 +02:00
|
|
|
|
2022-04-04 23:40:22 +02:00
|
|
|
namespace td {
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
struct BinlogEvent;
|
|
|
|
|
2022-04-16 05:01:05 +02:00
|
|
|
class NotificationSound;
|
|
|
|
|
2022-04-04 23:40:22 +02:00
|
|
|
class Td;
|
|
|
|
|
|
|
|
class NotificationSettingsManager final : public Actor {
|
|
|
|
public:
|
|
|
|
NotificationSettingsManager(Td *td, ActorShared<> parent);
|
|
|
|
NotificationSettingsManager(const NotificationSettingsManager &) = delete;
|
|
|
|
NotificationSettingsManager &operator=(const NotificationSettingsManager &) = delete;
|
|
|
|
NotificationSettingsManager(NotificationSettingsManager &&) = delete;
|
|
|
|
NotificationSettingsManager &operator=(NotificationSettingsManager &&) = delete;
|
|
|
|
~NotificationSettingsManager() final;
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
int32 get_scope_mute_until(NotificationSettingsScope scope) const;
|
|
|
|
|
2023-08-22 17:55:59 +02:00
|
|
|
std::pair<bool, bool> get_scope_mute_stories(NotificationSettingsScope scope) const;
|
|
|
|
|
2022-04-15 17:36:24 +02:00
|
|
|
const unique_ptr<NotificationSound> &get_scope_notification_sound(NotificationSettingsScope scope) const;
|
|
|
|
|
2023-08-22 17:55:59 +02:00
|
|
|
const unique_ptr<NotificationSound> &get_scope_story_notification_sound(NotificationSettingsScope scope) const;
|
|
|
|
|
2022-06-16 17:54:50 +02:00
|
|
|
bool get_scope_show_preview(NotificationSettingsScope scope) const;
|
|
|
|
|
2023-08-22 17:55:59 +02:00
|
|
|
bool get_scope_hide_story_sender(NotificationSettingsScope scope) const;
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
bool get_scope_disable_pinned_message_notifications(NotificationSettingsScope scope) const;
|
|
|
|
|
|
|
|
bool get_scope_disable_mention_notifications(NotificationSettingsScope scope) const;
|
|
|
|
|
2022-12-06 12:53:54 +01:00
|
|
|
tl_object_ptr<telegram_api::InputNotifyPeer> get_input_notify_peer(DialogId dialog_id,
|
|
|
|
MessageId top_thread_message_id) const;
|
2022-04-11 12:06:16 +02:00
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
void on_update_scope_notify_settings(NotificationSettingsScope scope,
|
|
|
|
tl_object_ptr<telegram_api::peerNotifySettings> &&peer_notify_settings);
|
|
|
|
|
2024-04-24 16:33:06 +02:00
|
|
|
void on_update_reaction_notification_settings(ReactionNotificationSettings reaction_notification_settings);
|
|
|
|
|
2022-04-14 21:39:25 +02:00
|
|
|
void add_saved_ringtone(td_api::object_ptr<td_api::InputFile> &&input_file,
|
|
|
|
Promise<td_api::object_ptr<td_api::notificationSound>> &&promise);
|
|
|
|
|
2022-04-14 12:23:43 +02:00
|
|
|
FileId get_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise);
|
|
|
|
|
2022-04-13 21:14:40 +02:00
|
|
|
vector<FileId> get_saved_ringtones(Promise<Unit> &&promise);
|
|
|
|
|
2022-04-14 13:31:18 +02:00
|
|
|
void remove_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise);
|
|
|
|
|
2022-04-13 21:14:40 +02:00
|
|
|
void reload_saved_ringtones(Promise<Unit> &&promise);
|
2022-04-13 19:36:57 +02:00
|
|
|
|
2022-04-15 15:27:30 +02:00
|
|
|
void repair_saved_ringtones(Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
FileSourceId get_saved_ringtones_file_source_id();
|
|
|
|
|
2022-04-14 13:31:18 +02:00
|
|
|
void send_save_ringtone_query(FileId ringtone_file_id, bool unsave,
|
|
|
|
Promise<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&promise);
|
|
|
|
|
2022-12-06 12:53:54 +01:00
|
|
|
void send_get_dialog_notification_settings_query(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
Promise<Unit> &&promise);
|
2022-04-08 16:17:56 +02:00
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
const ScopeNotificationSettings *get_scope_notification_settings(NotificationSettingsScope scope,
|
|
|
|
Promise<Unit> &&promise);
|
2022-04-08 16:17:56 +02:00
|
|
|
void send_get_scope_notification_settings_query(NotificationSettingsScope scope, Promise<Unit> &&promise);
|
|
|
|
|
2024-04-24 16:33:06 +02:00
|
|
|
void send_get_reaction_notification_settings_query(Promise<Unit> &&promise);
|
|
|
|
|
2022-12-06 12:53:54 +01:00
|
|
|
void on_get_dialog_notification_settings_query_finished(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
Status &&status);
|
2022-04-08 16:17:56 +02:00
|
|
|
|
2022-12-06 12:53:54 +01:00
|
|
|
void update_dialog_notify_settings(DialogId dialog_id, MessageId top_thread_message_id,
|
|
|
|
const DialogNotificationSettings &new_settings, Promise<Unit> &&promise);
|
2022-04-04 23:40:22 +02:00
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
Status set_scope_notification_settings(NotificationSettingsScope scope,
|
|
|
|
td_api::object_ptr<td_api::scopeNotificationSettings> &¬ification_settings)
|
|
|
|
TD_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
void reset_scope_notification_settings();
|
2022-04-08 16:17:56 +02:00
|
|
|
|
|
|
|
void reset_notify_settings(Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void get_notify_settings_exceptions(NotificationSettingsScope scope, bool filter_scope, bool compare_sound,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2023-07-06 18:15:00 +02:00
|
|
|
void get_story_notification_settings_exceptions(Promise<td_api::object_ptr<td_api::chats>> &&promise);
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
void init();
|
|
|
|
|
|
|
|
void on_binlog_events(vector<BinlogEvent> &&events);
|
|
|
|
|
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
2022-04-08 16:17:56 +02:00
|
|
|
private:
|
2022-04-11 11:45:52 +02:00
|
|
|
class UpdateScopeNotificationSettingsOnServerLogEvent;
|
|
|
|
|
2022-04-16 03:20:36 +02:00
|
|
|
class RingtoneListLogEvent;
|
|
|
|
|
2022-04-15 13:07:54 +02:00
|
|
|
class UploadRingtoneCallback;
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
void start_up() final;
|
|
|
|
|
2022-04-04 23:40:22 +02:00
|
|
|
void tear_down() final;
|
|
|
|
|
2022-04-13 19:36:57 +02:00
|
|
|
void timeout_expired() final;
|
|
|
|
|
|
|
|
bool is_active() const;
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
static void on_scope_unmute_timeout_callback(void *notification_settings_manager_ptr, int64 scope_int);
|
|
|
|
|
2022-04-13 19:36:57 +02:00
|
|
|
Result<FileId> get_ringtone(telegram_api::object_ptr<telegram_api::Document> &&ringtone) const;
|
|
|
|
|
2022-04-15 13:07:54 +02:00
|
|
|
void upload_ringtone(FileId file_id, bool is_reupload,
|
|
|
|
Promise<td_api::object_ptr<td_api::notificationSound>> &&promise, vector<int> bad_parts = {});
|
|
|
|
|
|
|
|
void on_upload_ringtone(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file);
|
|
|
|
|
|
|
|
void on_upload_ringtone_error(FileId file_id, Status status);
|
|
|
|
|
|
|
|
void on_upload_saved_ringtone(telegram_api::object_ptr<telegram_api::Document> &&saved_ringtone,
|
|
|
|
Promise<td_api::object_ptr<td_api::notificationSound>> &&promise);
|
|
|
|
|
2022-04-14 21:39:25 +02:00
|
|
|
void on_add_saved_ringtone(FileId file_id,
|
|
|
|
telegram_api::object_ptr<telegram_api::account_SavedRingtone> &&saved_ringtone,
|
|
|
|
Promise<td_api::object_ptr<td_api::notificationSound>> &&promise);
|
|
|
|
|
2022-04-14 13:31:18 +02:00
|
|
|
void on_remove_saved_ringtone(int64 ringtone_id, Promise<Unit> &&promise);
|
|
|
|
|
2022-04-15 15:27:30 +02:00
|
|
|
void on_reload_saved_ringtones(bool is_repair,
|
|
|
|
Result<telegram_api::object_ptr<telegram_api::account_SavedRingtones>> &&result);
|
|
|
|
|
2022-04-16 03:20:36 +02:00
|
|
|
static string get_saved_ringtones_database_key();
|
|
|
|
|
|
|
|
void load_saved_ringtones(Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void on_load_saved_ringtones(Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void save_saved_ringtones_to_database() const;
|
|
|
|
|
2022-04-15 15:27:30 +02:00
|
|
|
void on_saved_ringtones_updated(bool from_database);
|
2022-04-13 19:36:57 +02:00
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
ScopeNotificationSettings *get_scope_notification_settings(NotificationSettingsScope scope);
|
|
|
|
|
|
|
|
const ScopeNotificationSettings *get_scope_notification_settings(NotificationSettingsScope scope) const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::updateScopeNotificationSettings> get_update_scope_notification_settings_object(
|
|
|
|
NotificationSettingsScope scope) const;
|
|
|
|
|
2024-04-24 16:33:06 +02:00
|
|
|
td_api::object_ptr<td_api::updateReactionNotificationSettings> get_update_reaction_notification_settings_object()
|
|
|
|
const;
|
|
|
|
|
2022-04-15 20:54:47 +02:00
|
|
|
td_api::object_ptr<td_api::updateSavedNotificationSounds> get_update_saved_notification_sounds_object() const;
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
void on_scope_unmute(NotificationSettingsScope scope);
|
|
|
|
|
|
|
|
static string get_notification_settings_scope_database_key(NotificationSettingsScope scope);
|
|
|
|
|
|
|
|
static void save_scope_notification_settings(NotificationSettingsScope scope,
|
|
|
|
const ScopeNotificationSettings &new_settings);
|
|
|
|
|
|
|
|
bool update_scope_notification_settings(NotificationSettingsScope scope, ScopeNotificationSettings *current_settings,
|
2022-04-11 19:01:44 +02:00
|
|
|
ScopeNotificationSettings &&new_settings);
|
2022-04-11 11:45:52 +02:00
|
|
|
|
|
|
|
static uint64 save_update_scope_notification_settings_on_server_log_event(NotificationSettingsScope scope);
|
|
|
|
|
|
|
|
void update_scope_notification_settings_on_server(NotificationSettingsScope scope, uint64 log_event_id);
|
|
|
|
|
2023-10-04 11:24:58 +02:00
|
|
|
void schedule_scope_unmute(NotificationSettingsScope scope, int32 mute_until, int32 unix_time);
|
2022-04-11 11:45:52 +02:00
|
|
|
|
|
|
|
void update_scope_unmute_timeout(NotificationSettingsScope scope, int32 &old_mute_until, int32 new_mute_until);
|
|
|
|
|
2022-04-04 23:40:22 +02:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
2022-04-08 16:17:56 +02:00
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
bool is_inited_ = false;
|
2022-04-13 21:14:40 +02:00
|
|
|
bool are_saved_ringtones_loaded_ = false;
|
|
|
|
bool are_saved_ringtones_reloaded_ = false;
|
2022-04-11 11:45:52 +02:00
|
|
|
|
|
|
|
ScopeNotificationSettings users_notification_settings_;
|
|
|
|
ScopeNotificationSettings chats_notification_settings_;
|
|
|
|
ScopeNotificationSettings channels_notification_settings_;
|
|
|
|
|
2024-04-24 16:33:06 +02:00
|
|
|
ReactionNotificationSettings reaction_notification_settings_;
|
|
|
|
|
2022-04-11 11:45:52 +02:00
|
|
|
MultiTimeout scope_unmute_timeout_{"ScopeUnmuteTimeout"};
|
|
|
|
|
2022-04-13 21:14:40 +02:00
|
|
|
int64 saved_ringtone_hash_ = 0;
|
|
|
|
vector<FileId> saved_ringtone_file_ids_;
|
2022-04-15 15:27:30 +02:00
|
|
|
vector<FileId> sorted_saved_ringtone_file_ids_;
|
|
|
|
FileSourceId saved_ringtones_file_source_id_;
|
2022-04-13 19:36:57 +02:00
|
|
|
|
2022-04-15 13:07:54 +02:00
|
|
|
std::shared_ptr<UploadRingtoneCallback> upload_ringtone_callback_;
|
|
|
|
|
|
|
|
struct UploadedRingtone {
|
|
|
|
bool is_reupload;
|
|
|
|
Promise<td_api::object_ptr<td_api::notificationSound>> promise;
|
|
|
|
|
|
|
|
UploadedRingtone(bool is_reupload, Promise<td_api::object_ptr<td_api::notificationSound>> promise)
|
|
|
|
: is_reupload(is_reupload), promise(std::move(promise)) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
FlatHashMap<FileId, UploadedRingtone, FileIdHash> being_uploaded_ringtones_;
|
|
|
|
|
2022-04-15 15:27:30 +02:00
|
|
|
vector<Promise<Unit>> reload_saved_ringtones_queries_;
|
|
|
|
vector<Promise<Unit>> repair_saved_ringtones_queries_;
|
2022-04-13 19:36:57 +02:00
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
FlatHashMap<MessageFullId, vector<Promise<Unit>>, MessageFullIdHash> get_dialog_notification_settings_queries_;
|
2022-04-04 23:40:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|