diff --git a/CMakeLists.txt b/CMakeLists.txt index 61a941640..6cc8fd1c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -399,6 +399,7 @@ set(TDLIB_SOURCE td/telegram/net/Session.cpp td/telegram/net/SessionProxy.cpp td/telegram/net/SessionMultiProxy.cpp + td/telegram/NotificationSettings.cpp td/telegram/Payments.cpp td/telegram/PasswordManager.cpp td/telegram/PrivacyManager.cpp @@ -525,6 +526,7 @@ set(TDLIB_SOURCE td/telegram/net/SessionProxy.h td/telegram/net/SessionMultiProxy.h td/telegram/net/TempAuthKeyWatchdog.h + td/telegram/NotificationSettings.h td/telegram/PasswordManager.h td/telegram/Payments.h td/telegram/Photo.h @@ -569,6 +571,7 @@ set(TDLIB_SOURCE td/telegram/Game.hpp td/telegram/InputMessageText.hpp td/telegram/MessageEntity.hpp + td/telegram/NotificationSettings.hpp td/telegram/Payments.hpp td/telegram/Photo.hpp td/telegram/ReplyMarkup.hpp diff --git a/td/telegram/DraftMessage.h b/td/telegram/DraftMessage.h index 881ab08c6..b91460402 100644 --- a/td/telegram/DraftMessage.h +++ b/td/telegram/DraftMessage.h @@ -9,6 +9,7 @@ #include "td/telegram/InputMessageText.h" #include "td/telegram/MessageId.h" #include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" #include "td/utils/common.h" diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4a15d0f87..f9c47dd3e 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -28,6 +28,7 @@ #include "td/telegram/net/DcId.h" #include "td/telegram/net/NetActor.h" #include "td/telegram/net/NetQuery.h" +#include "td/telegram/NotificationSettings.hpp" #include "td/telegram/Payments.h" #include "td/telegram/ReplyMarkup.h" #include "td/telegram/ReplyMarkup.hpp" @@ -3068,7 +3069,7 @@ class GetScopeNotifySettingsQuery : public Td::ResultHandler { void send(NotificationSettingsScope scope) { scope_ = scope; - auto input_notify_peer = td->messages_manager_->get_input_notify_peer(scope); + auto input_notify_peer = get_input_notify_peer(scope); CHECK(input_notify_peer != nullptr); send_query(G()->net_query_creator().create( create_storer(telegram_api::account_getNotifySettings(std::move(input_notify_peer))))); @@ -3161,7 +3162,7 @@ class UpdateScopeNotifySettingsQuery : public Td::ResultHandler { } void send(NotificationSettingsScope scope, const ScopeNotificationSettings &new_settings) { - auto input_notify_peer = td->messages_manager_->get_input_notify_peer(scope); + auto input_notify_peer = get_input_notify_peer(scope); CHECK(input_notify_peer != nullptr); int32 flags = telegram_api::inputPeerNotifySettings::MUTE_UNTIL_MASK | telegram_api::inputPeerNotifySettings::SOUND_MASK | @@ -3815,93 +3816,6 @@ void MessagesManager::Message::parse(ParserT &parser) { is_secret_message_content(ttl, content->get_type()); // repair is_content_secret for old messages } -template -static void store(const DialogNotificationSettings ¬ification_settings, StorerT &storer) { - bool is_muted = !notification_settings.use_default_mute_until && notification_settings.mute_until != 0 && - notification_settings.mute_until > G()->unix_time(); - bool has_sound = !notification_settings.use_default_sound && notification_settings.sound != "default"; - BEGIN_STORE_FLAGS(); - STORE_FLAG(is_muted); - STORE_FLAG(has_sound); - STORE_FLAG(notification_settings.show_preview); - STORE_FLAG(notification_settings.silent_send_message); - STORE_FLAG(notification_settings.is_synchronized); - STORE_FLAG(notification_settings.use_default_mute_until); - STORE_FLAG(notification_settings.use_default_sound); - STORE_FLAG(notification_settings.use_default_show_preview); - STORE_FLAG(notification_settings.is_use_default_fixed); - END_STORE_FLAGS(); - if (is_muted) { - store(notification_settings.mute_until, storer); - } - if (has_sound) { - store(notification_settings.sound, storer); - } -} - -template -static void parse(DialogNotificationSettings ¬ification_settings, ParserT &parser) { - bool is_muted; - bool has_sound; - BEGIN_PARSE_FLAGS(); - PARSE_FLAG(is_muted); - PARSE_FLAG(has_sound); - PARSE_FLAG(notification_settings.show_preview); - PARSE_FLAG(notification_settings.silent_send_message); - PARSE_FLAG(notification_settings.is_synchronized); - PARSE_FLAG(notification_settings.use_default_mute_until); - PARSE_FLAG(notification_settings.use_default_sound); - PARSE_FLAG(notification_settings.use_default_show_preview); - PARSE_FLAG(notification_settings.is_use_default_fixed); - END_PARSE_FLAGS(); - if (is_muted) { - parse(notification_settings.mute_until, parser); - } - if (has_sound) { - parse(notification_settings.sound, parser); - } -} - -template -static void store(const ScopeNotificationSettings ¬ification_settings, StorerT &storer) { - bool is_muted = notification_settings.mute_until != 0 && notification_settings.mute_until > G()->unix_time(); - bool has_sound = notification_settings.sound != "default"; - BEGIN_STORE_FLAGS(); - STORE_FLAG(is_muted); - STORE_FLAG(has_sound); - STORE_FLAG(notification_settings.show_preview); - STORE_FLAG(false); - STORE_FLAG(notification_settings.is_synchronized); - END_STORE_FLAGS(); - if (is_muted) { - store(notification_settings.mute_until, storer); - } - if (has_sound) { - store(notification_settings.sound, storer); - } -} - -template -static void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { - bool is_muted; - bool has_sound; - bool silent_send_message_ignored; - BEGIN_PARSE_FLAGS(); - PARSE_FLAG(is_muted); - PARSE_FLAG(has_sound); - PARSE_FLAG(notification_settings.show_preview); - PARSE_FLAG(silent_send_message_ignored); - PARSE_FLAG(notification_settings.is_synchronized); - END_PARSE_FLAGS(); - (void)silent_send_message_ignored; - if (is_muted) { - parse(notification_settings.mute_until, parser); - } - if (has_sound) { - parse(notification_settings.sound, parser); - } -} - template void MessagesManager::Dialog::store(StorerT &storer) const { using td::store; @@ -5673,20 +5587,6 @@ void MessagesManager::drop_pending_updates() { pending_updates_.clear(); } -NotificationSettingsScope MessagesManager::get_notification_settings_scope( - const tl_object_ptr &scope) { - CHECK(scope != nullptr); - switch (scope->get_id()) { - case td_api::notificationSettingsScopePrivateChats::ID: - return NotificationSettingsScope::Private; - case td_api::notificationSettingsScopeGroupChats::ID: - return NotificationSettingsScope::Group; - default: - UNREACHABLE(); - return NotificationSettingsScope::Private; - } -} - string MessagesManager::get_notification_settings_scope_database_key(NotificationSettingsScope scope) { switch (scope) { case NotificationSettingsScope::Private: @@ -5926,7 +5826,7 @@ void MessagesManager::on_update_dialog_notify_settings( LOG(INFO) << "Receive notification settings for " << dialog_id << ": " << to_string(peer_notify_settings); const DialogNotificationSettings notification_settings = - get_dialog_notification_settings(std::move(peer_notify_settings)); + td::get_dialog_notification_settings(std::move(peer_notify_settings)); if (!notification_settings.is_synchronized) { return; } @@ -5945,7 +5845,7 @@ void MessagesManager::on_update_scope_notify_settings( } const ScopeNotificationSettings notification_settings = - get_scope_notification_settings(std::move(peer_notify_settings)); + td::get_scope_notification_settings(std::move(peer_notify_settings)); if (!notification_settings.is_synchronized) { return; } @@ -12395,34 +12295,6 @@ tl_object_ptr MessagesManager::get_chats_object(const vector(transform(dialogs, [](DialogId dialog_id) { return dialog_id.get(); })); } -tl_object_ptr MessagesManager::get_notification_settings_scope_object( - NotificationSettingsScope scope) { - switch (scope) { - case NotificationSettingsScope::Private: - return make_tl_object(); - case NotificationSettingsScope::Group: - return make_tl_object(); - default: - UNREACHABLE(); - return nullptr; - } -} - -tl_object_ptr MessagesManager::get_chat_notification_settings_object( - const DialogNotificationSettings *notification_settings) { - return make_tl_object( - notification_settings->use_default_mute_until, max(0, notification_settings->mute_until - G()->unix_time()), - notification_settings->use_default_sound, notification_settings->sound, - notification_settings->use_default_show_preview, notification_settings->show_preview); -} - -tl_object_ptr MessagesManager::get_scope_notification_settings_object( - const ScopeNotificationSettings *notification_settings) { - return make_tl_object(max(0, notification_settings->mute_until - G()->unix_time()), - notification_settings->sound, - notification_settings->show_preview); -} - td_api::object_ptr MessagesManager::get_update_scope_notification_settings_object(NotificationSettingsScope scope) const { auto notification_settings = get_scope_notification_settings(scope); @@ -12529,17 +12401,6 @@ tl_object_ptr MessagesManager::get_input_notify_p return make_tl_object(std::move(input_peer)); } -tl_object_ptr MessagesManager::get_input_notify_peer(NotificationSettingsScope scope) { - switch (scope) { - case NotificationSettingsScope::Private: - return make_tl_object(); - case NotificationSettingsScope::Group: - return make_tl_object(); - default: - return nullptr; - } -} - Status MessagesManager::set_dialog_notification_settings( DialogId dialog_id, tl_object_ptr &¬ification_settings) { if (notification_settings == nullptr) { @@ -19739,33 +19600,6 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId return result; } -DialogNotificationSettings MessagesManager::get_dialog_notification_settings( - tl_object_ptr &&settings) { - bool use_default_mute_until = (settings->flags_ & telegram_api::peerNotifySettings::MUTE_UNTIL_MASK) == 0; - bool use_default_sound = (settings->flags_ & telegram_api::peerNotifySettings::SOUND_MASK) == 0; - bool use_default_show_preview = (settings->flags_ & telegram_api::peerNotifySettings::SHOW_PREVIEWS_MASK) == 0; - auto mute_until = use_default_mute_until || settings->mute_until_ <= G()->unix_time() ? 0 : settings->mute_until_; - bool silent_send_message = - (settings->flags_ & telegram_api::peerNotifySettings::SILENT_MASK) == 0 ? false : settings->silent_; - return {use_default_mute_until, mute_until, - use_default_sound, std::move(settings->sound_), - use_default_show_preview, settings->show_previews_, - silent_send_message}; -} - -ScopeNotificationSettings MessagesManager::get_scope_notification_settings( - tl_object_ptr &&settings) { - auto mute_until = (settings->flags_ & telegram_api::peerNotifySettings::MUTE_UNTIL_MASK) == 0 || - settings->mute_until_ <= G()->unix_time() - ? 0 - : settings->mute_until_; - auto sound = - (settings->flags_ & telegram_api::peerNotifySettings::SOUND_MASK) == 0 ? "default" : std::move(settings->sound_); - auto show_preview = - (settings->flags_ & telegram_api::peerNotifySettings::SHOW_PREVIEWS_MASK) == 0 ? false : settings->show_previews_; - return {mute_until, std::move(sound), show_preview}; -} - int32 MessagesManager::get_random_y(MessageId message_id) { return static_cast(static_cast(message_id.get() * 2101234567u)); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 33d0accde..1c7a957d7 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -30,6 +30,7 @@ #include "td/telegram/MessageId.h" #include "td/telegram/MessagesDb.h" #include "td/telegram/net/NetQuery.h" +#include "td/telegram/NotificationSettings.h" #include "td/telegram/ReplyMarkup.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/SecretInputMedia.h" @@ -64,75 +65,6 @@ class MultiSequenceDispatcher; class DraftMessage; -class DialogNotificationSettings { - public: - int32 mute_until = 0; - string sound = "default"; - bool show_preview = true; - bool silent_send_message = false; - bool use_default_mute_until = true; - bool use_default_sound = true; - bool use_default_show_preview = true; - bool is_use_default_fixed = true; - bool is_synchronized = false; - - DialogNotificationSettings() = default; - - 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) - : mute_until(mute_until) - , sound(std::move(sound)) - , show_preview(show_preview) - , silent_send_message(silent_send_message) - , use_default_mute_until(use_default_mute_until) - , use_default_sound(use_default_sound) - , use_default_show_preview(use_default_show_preview) - , is_synchronized(true) { - } -}; - -enum class NotificationSettingsScope : int32 { Private, Group }; - -class ScopeNotificationSettings { - public: - int32 mute_until = 0; - string sound = "default"; - bool show_preview = true; - bool is_synchronized = false; - - ScopeNotificationSettings() = default; - - ScopeNotificationSettings(int32 mute_until, string sound, bool show_preview) - : mute_until(mute_until), sound(std::move(sound)), show_preview(show_preview), is_synchronized(true) { - } -}; - -inline StringBuilder &operator<<(StringBuilder &string_builder, DialogNotificationSettings notification_settings) { - return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", " - << notification_settings.show_preview << ", " << notification_settings.silent_send_message - << ", " << notification_settings.use_default_mute_until << ", " - << notification_settings.use_default_sound << ", " - << notification_settings.use_default_show_preview << ", " - << notification_settings.is_synchronized << "]"; -} - -inline StringBuilder &operator<<(StringBuilder &string_builder, NotificationSettingsScope scope) { - switch (scope) { - case NotificationSettingsScope::Private: - return string_builder << "notification settings for private chats"; - case NotificationSettingsScope::Group: - return string_builder << "notification settings for group chats"; - default: - UNREACHABLE(); - return string_builder; - } -} - -inline StringBuilder &operator<<(StringBuilder &string_builder, ScopeNotificationSettings notification_settings) { - return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", " - << notification_settings.show_preview << ", " << notification_settings.is_synchronized << "]"; -} - class DialogDate { int64 order; DialogId dialog_id; @@ -600,15 +532,6 @@ class MessagesManager : public Actor { Status open_message_content(FullMessageId full_message_id) TD_WARN_UNUSED_RESULT; - static tl_object_ptr get_notification_settings_scope_object( - NotificationSettingsScope scope); - - static tl_object_ptr get_chat_notification_settings_object( - const DialogNotificationSettings *notification_settings); - - static tl_object_ptr get_scope_notification_settings_object( - const ScopeNotificationSettings *notification_settings); - td_api::object_ptr get_update_scope_notification_settings_object( NotificationSettingsScope scope) const; @@ -697,11 +620,6 @@ class MessagesManager : public Actor { tl_object_ptr get_input_notify_peer(DialogId dialogId) const; - static tl_object_ptr get_input_notify_peer(NotificationSettingsScope scope); - - static NotificationSettingsScope get_notification_settings_scope( - const tl_object_ptr &scope); - void on_update_dialog_notify_settings(DialogId dialog_id, tl_object_ptr &&peer_notify_settings); @@ -1722,12 +1640,6 @@ class MessagesManager : public Actor { void on_get_dialog_message_by_date_from_database(DialogId dialog_id, int32 date, int64 random_id, Result result, Promise promise); - static DialogNotificationSettings get_dialog_notification_settings( - tl_object_ptr &&settings); - - static ScopeNotificationSettings get_scope_notification_settings( - tl_object_ptr &&settings); - std::pair get_dialog_mute_until(DialogId dialog_id, const Dialog *d) const; static NotificationSettingsScope get_dialog_notification_setting_scope(DialogId dialog_id); diff --git a/td/telegram/NotificationSettings.cpp b/td/telegram/NotificationSettings.cpp new file mode 100644 index 000000000..141a9b0f6 --- /dev/null +++ b/td/telegram/NotificationSettings.cpp @@ -0,0 +1,120 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// 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) +// +#include "td/telegram/NotificationSettings.h" + +#include "td/telegram/Global.h" + +#include "td/utils/logging.h" + +namespace td { + +StringBuilder &operator<<(StringBuilder &string_builder, const DialogNotificationSettings ¬ification_settings) { + return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", " + << notification_settings.show_preview << ", " << notification_settings.silent_send_message + << ", " << notification_settings.use_default_mute_until << ", " + << notification_settings.use_default_sound << ", " + << notification_settings.use_default_show_preview << ", " + << notification_settings.is_synchronized << "]"; +} + +StringBuilder &operator<<(StringBuilder &string_builder, NotificationSettingsScope scope) { + switch (scope) { + case NotificationSettingsScope::Private: + return string_builder << "notification settings for private chats"; + case NotificationSettingsScope::Group: + return string_builder << "notification settings for group chats"; + default: + UNREACHABLE(); + return string_builder; + } +} + +StringBuilder &operator<<(StringBuilder &string_builder, const ScopeNotificationSettings ¬ification_settings) { + return string_builder << "[" << notification_settings.mute_until << ", " << notification_settings.sound << ", " + << notification_settings.show_preview << ", " << notification_settings.is_synchronized << "]"; +} + +td_api::object_ptr get_notification_settings_scope_object( + NotificationSettingsScope scope) { + switch (scope) { + case NotificationSettingsScope::Private: + return td_api::make_object(); + case NotificationSettingsScope::Group: + return td_api::make_object(); + default: + UNREACHABLE(); + return nullptr; + } +} + +td_api::object_ptr get_chat_notification_settings_object( + const DialogNotificationSettings *notification_settings) { + return td_api::make_object( + notification_settings->use_default_mute_until, max(0, notification_settings->mute_until - G()->unix_time()), + notification_settings->use_default_sound, notification_settings->sound, + notification_settings->use_default_show_preview, notification_settings->show_preview); +} + +td_api::object_ptr get_scope_notification_settings_object( + const ScopeNotificationSettings *notification_settings) { + return td_api::make_object( + max(0, notification_settings->mute_until - G()->unix_time()), notification_settings->sound, + notification_settings->show_preview); +} + +telegram_api::object_ptr get_input_notify_peer(NotificationSettingsScope scope) { + switch (scope) { + case NotificationSettingsScope::Private: + return telegram_api::make_object(); + case NotificationSettingsScope::Group: + return telegram_api::make_object(); + default: + return nullptr; + } +} + +NotificationSettingsScope get_notification_settings_scope( + const td_api::object_ptr &scope) { + CHECK(scope != nullptr); + switch (scope->get_id()) { + case td_api::notificationSettingsScopePrivateChats::ID: + return NotificationSettingsScope::Private; + case td_api::notificationSettingsScopeGroupChats::ID: + return NotificationSettingsScope::Group; + default: + UNREACHABLE(); + return NotificationSettingsScope::Private; + } +} + +DialogNotificationSettings get_dialog_notification_settings( + tl_object_ptr &&settings) { + bool use_default_mute_until = (settings->flags_ & telegram_api::peerNotifySettings::MUTE_UNTIL_MASK) == 0; + bool use_default_sound = (settings->flags_ & telegram_api::peerNotifySettings::SOUND_MASK) == 0; + bool use_default_show_preview = (settings->flags_ & telegram_api::peerNotifySettings::SHOW_PREVIEWS_MASK) == 0; + auto mute_until = use_default_mute_until || settings->mute_until_ <= G()->unix_time() ? 0 : settings->mute_until_; + bool silent_send_message = + (settings->flags_ & telegram_api::peerNotifySettings::SILENT_MASK) == 0 ? false : settings->silent_; + return {use_default_mute_until, mute_until, + use_default_sound, std::move(settings->sound_), + use_default_show_preview, settings->show_previews_, + silent_send_message}; +} + +ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr &&settings) { + auto mute_until = (settings->flags_ & telegram_api::peerNotifySettings::MUTE_UNTIL_MASK) == 0 || + settings->mute_until_ <= G()->unix_time() + ? 0 + : settings->mute_until_; + auto sound = + (settings->flags_ & telegram_api::peerNotifySettings::SOUND_MASK) == 0 ? "default" : std::move(settings->sound_); + auto show_preview = + (settings->flags_ & telegram_api::peerNotifySettings::SHOW_PREVIEWS_MASK) == 0 ? false : settings->show_previews_; + return {mute_until, std::move(sound), show_preview}; +} + +} // namespace td diff --git a/td/telegram/NotificationSettings.h b/td/telegram/NotificationSettings.h new file mode 100644 index 000000000..f9d379c85 --- /dev/null +++ b/td/telegram/NotificationSettings.h @@ -0,0 +1,84 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// 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 + +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class DialogNotificationSettings { + public: + int32 mute_until = 0; + string sound = "default"; + bool show_preview = true; + bool silent_send_message = false; + bool use_default_mute_until = true; + bool use_default_sound = true; + bool use_default_show_preview = true; + bool is_use_default_fixed = true; + bool is_synchronized = false; + + DialogNotificationSettings() = default; + + 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) + : mute_until(mute_until) + , sound(std::move(sound)) + , show_preview(show_preview) + , silent_send_message(silent_send_message) + , use_default_mute_until(use_default_mute_until) + , use_default_sound(use_default_sound) + , use_default_show_preview(use_default_show_preview) + , is_synchronized(true) { + } +}; + +enum class NotificationSettingsScope : int32 { Private, Group }; + +class ScopeNotificationSettings { + public: + int32 mute_until = 0; + string sound = "default"; + bool show_preview = true; + bool is_synchronized = false; + + ScopeNotificationSettings() = default; + + ScopeNotificationSettings(int32 mute_until, string sound, bool show_preview) + : mute_until(mute_until), sound(std::move(sound)), show_preview(show_preview), is_synchronized(true) { + } +}; + +StringBuilder &operator<<(StringBuilder &string_builder, const DialogNotificationSettings ¬ification_settings); + +StringBuilder &operator<<(StringBuilder &string_builder, NotificationSettingsScope scope); + +StringBuilder &operator<<(StringBuilder &string_builder, const ScopeNotificationSettings ¬ification_settings); + +td_api::object_ptr get_notification_settings_scope_object( + NotificationSettingsScope scope); + +td_api::object_ptr get_chat_notification_settings_object( + const DialogNotificationSettings *notification_settings); + +td_api::object_ptr get_scope_notification_settings_object( + const ScopeNotificationSettings *notification_settings); + +telegram_api::object_ptr get_input_notify_peer(NotificationSettingsScope scope); + +NotificationSettingsScope get_notification_settings_scope( + const td_api::object_ptr &scope); + +DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr &&settings); + +ScopeNotificationSettings get_scope_notification_settings(tl_object_ptr &&settings); + +} // namespace td diff --git a/td/telegram/NotificationSettings.hpp b/td/telegram/NotificationSettings.hpp new file mode 100644 index 000000000..b53dbd16c --- /dev/null +++ b/td/telegram/NotificationSettings.hpp @@ -0,0 +1,102 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// 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 + +#include "td/telegram/NotificationSettings.h" + +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void store(const DialogNotificationSettings ¬ification_settings, StorerT &storer) { + bool is_muted = !notification_settings.use_default_mute_until && notification_settings.mute_until != 0 && + notification_settings.mute_until > G()->unix_time(); + bool has_sound = !notification_settings.use_default_sound && notification_settings.sound != "default"; + BEGIN_STORE_FLAGS(); + STORE_FLAG(is_muted); + STORE_FLAG(has_sound); + STORE_FLAG(notification_settings.show_preview); + STORE_FLAG(notification_settings.silent_send_message); + STORE_FLAG(notification_settings.is_synchronized); + STORE_FLAG(notification_settings.use_default_mute_until); + STORE_FLAG(notification_settings.use_default_sound); + STORE_FLAG(notification_settings.use_default_show_preview); + STORE_FLAG(notification_settings.is_use_default_fixed); + END_STORE_FLAGS(); + if (is_muted) { + store(notification_settings.mute_until, storer); + } + if (has_sound) { + store(notification_settings.sound, storer); + } +} + +template +void parse(DialogNotificationSettings ¬ification_settings, ParserT &parser) { + bool is_muted; + bool has_sound; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_muted); + PARSE_FLAG(has_sound); + PARSE_FLAG(notification_settings.show_preview); + PARSE_FLAG(notification_settings.silent_send_message); + PARSE_FLAG(notification_settings.is_synchronized); + PARSE_FLAG(notification_settings.use_default_mute_until); + PARSE_FLAG(notification_settings.use_default_sound); + PARSE_FLAG(notification_settings.use_default_show_preview); + PARSE_FLAG(notification_settings.is_use_default_fixed); + END_PARSE_FLAGS(); + if (is_muted) { + parse(notification_settings.mute_until, parser); + } + if (has_sound) { + parse(notification_settings.sound, parser); + } +} + +template +void store(const ScopeNotificationSettings ¬ification_settings, StorerT &storer) { + bool is_muted = notification_settings.mute_until != 0 && notification_settings.mute_until > G()->unix_time(); + bool has_sound = notification_settings.sound != "default"; + BEGIN_STORE_FLAGS(); + STORE_FLAG(is_muted); + STORE_FLAG(has_sound); + STORE_FLAG(notification_settings.show_preview); + STORE_FLAG(false); + STORE_FLAG(notification_settings.is_synchronized); + END_STORE_FLAGS(); + if (is_muted) { + store(notification_settings.mute_until, storer); + } + if (has_sound) { + store(notification_settings.sound, storer); + } +} + +template +void parse(ScopeNotificationSettings ¬ification_settings, ParserT &parser) { + bool is_muted; + bool has_sound; + bool silent_send_message_ignored; + BEGIN_PARSE_FLAGS(); + PARSE_FLAG(is_muted); + PARSE_FLAG(has_sound); + PARSE_FLAG(notification_settings.show_preview); + PARSE_FLAG(silent_send_message_ignored); + PARSE_FLAG(notification_settings.is_synchronized); + END_PARSE_FLAGS(); + (void)silent_send_message_ignored; + if (is_muted) { + parse(notification_settings.mute_until, parser); + } + if (has_sound) { + parse(notification_settings.sound, parser); + } +} + +} // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index fded31935..4a978852c 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -43,6 +43,7 @@ #include "td/telegram/MessageId.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/misc.h" +#include "td/telegram/NotificationSettings.h" #include "td/telegram/PasswordManager.h" #include "td/telegram/Payments.h" #include "td/telegram/Photo.h" @@ -2233,7 +2234,7 @@ class GetScopeNotificationSettingsRequest : public RequestActor<> { void do_send_result() override { CHECK(notification_settings_ != nullptr); - send_result(td->messages_manager_->get_scope_notification_settings_object(notification_settings_)); + send_result(get_scope_notification_settings_object(notification_settings_)); } public: @@ -6074,7 +6075,7 @@ void Td::on_request(uint64 id, const td_api::getScopeNotificationSettings &reque if (request.scope_ == nullptr) { return send_error_raw(id, 400, "Scope must not be empty"); } - CREATE_REQUEST(GetScopeNotificationSettingsRequest, MessagesManager::get_notification_settings_scope(request.scope_)); + CREATE_REQUEST(GetScopeNotificationSettingsRequest, get_notification_settings_scope(request.scope_)); } void Td::on_request(uint64 id, const td_api::getChatReportSpamState &request) { @@ -6108,8 +6109,7 @@ void Td::on_request(uint64 id, td_api::setScopeNotificationSettings &request) { return send_error_raw(id, 400, "Scope must not be empty"); } answer_ok_query(id, messages_manager_->set_scope_notification_settings( - MessagesManager::get_notification_settings_scope(request.scope_), - std::move(request.notification_settings_))); + get_notification_settings_scope(request.scope_), std::move(request.notification_settings_))); } void Td::on_request(uint64 id, const td_api::resetAllNotificationSettings &request) {