diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d25e0144..b59f3eaa 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -515,9 +515,12 @@ foundMessages messages:vector next_from_search_id:int64 = FoundMessages //@description Notification settings applied to all private and secret chats when the corresponding chat setting has a default value notificationSettingsScopePrivateChats = NotificationSettingsScope; -//@description Notification settings applied to all basic groups, supergroups and channels when the corresponding chat setting has a default value +//@description Notification settings applied to all basic groups and supergroups when the corresponding chat setting has a default value notificationSettingsScopeGroupChats = NotificationSettingsScope; +//@description Notification settings applied to all channels when the corresponding chat setting has a default value +notificationSettingsScopeChannelChats = NotificationSettingsScope; + //@description Contains information about notification settings for a chat //@use_default_mute_for If true, mute_for is ignored and the value for the relevant type of chat is used instead @mute_for Time left before notifications will be unmuted, in seconds diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index a4f12971..c462063e 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a0b15760..10619a9e 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -4076,7 +4076,7 @@ void MessagesManager::on_dialog_unmute_timeout_callback(void *messages_manager_p } auto messages_manager = static_cast(messages_manager_ptr); - if (1 <= dialog_id_int && dialog_id_int <= 2) { + if (1 <= dialog_id_int && dialog_id_int <= 3) { send_closure_later(messages_manager->actor_id(messages_manager), &MessagesManager::on_scope_unmute, static_cast(dialog_id_int - 1)); } else { @@ -5514,6 +5514,8 @@ string MessagesManager::get_notification_settings_scope_database_key(Notificatio return "nsfpc"; case NotificationSettingsScope::Group: return "nsfgc"; + case NotificationSettingsScope::Channel: + return "nsfcc"; default: UNREACHABLE(); return ""; @@ -8722,7 +8724,8 @@ void MessagesManager::init() { load_calls_db_state(); - vector scopes{NotificationSettingsScope::Private, NotificationSettingsScope::Group}; + vector scopes{NotificationSettingsScope::Private, NotificationSettingsScope::Group, + NotificationSettingsScope::Channel}; for (auto scope : scopes) { auto notification_settings_string = G()->td_db()->get_binlog_pmc()->get(get_notification_settings_scope_database_key(scope)); @@ -8736,6 +8739,11 @@ void MessagesManager::init() { update_scope_notification_settings(scope, current_settings, notification_settings); } } + if (!channels_notification_settings_.is_synchronized) { + channels_notification_settings_ = chats_notification_settings_; + channels_notification_settings_.is_synchronized = false; + send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>()); + } G()->td_db()->get_binlog_pmc()->erase("nsfac"); /* @@ -12793,14 +12801,15 @@ std::pair MessagesManager::get_dialog_mute_until(DialogId dialog_id return {d->notification_settings.is_use_default_fixed, get_dialog_mute_until(d)}; } -NotificationSettingsScope MessagesManager::get_dialog_notification_setting_scope(DialogId dialog_id) { +NotificationSettingsScope MessagesManager::get_dialog_notification_setting_scope(DialogId dialog_id) const { switch (dialog_id.get_type()) { case DialogType::User: case DialogType::SecretChat: return NotificationSettingsScope::Private; case DialogType::Chat: - case DialogType::Channel: return NotificationSettingsScope::Group; + case DialogType::Channel: + return is_broadcast_channel(dialog_id) ? NotificationSettingsScope::Channel : NotificationSettingsScope::Group; case DialogType::None: default: UNREACHABLE(); @@ -12814,8 +12823,10 @@ int32 MessagesManager::get_scope_mute_until(DialogId dialog_id) const { case DialogType::SecretChat: return users_notification_settings_.mute_until; case DialogType::Chat: - case DialogType::Channel: return chats_notification_settings_.mute_until; + case DialogType::Channel: + return is_broadcast_channel(dialog_id) ? channels_notification_settings_.mute_until + : chats_notification_settings_.mute_until; case DialogType::None: default: UNREACHABLE(); @@ -12853,6 +12864,8 @@ ScopeNotificationSettings *MessagesManager::get_scope_notification_settings(Noti return &users_notification_settings_; case NotificationSettingsScope::Group: return &chats_notification_settings_; + case NotificationSettingsScope::Channel: + return &channels_notification_settings_; default: UNREACHABLE(); return nullptr; @@ -12866,6 +12879,8 @@ const ScopeNotificationSettings *MessagesManager::get_scope_notification_setting return &users_notification_settings_; case NotificationSettingsScope::Group: return &chats_notification_settings_; + case NotificationSettingsScope::Channel: + return &channels_notification_settings_; default: UNREACHABLE(); return nullptr; @@ -12997,6 +13012,8 @@ void MessagesManager::reset_all_notification_settings() { new_scope_settings); update_scope_notification_settings(NotificationSettingsScope::Group, &chats_notification_settings_, new_scope_settings); + update_scope_notification_settings(NotificationSettingsScope::Channel, &channels_notification_settings_, + new_scope_settings); for (auto &dialog : dialogs_) { Dialog *d = dialog.second.get(); @@ -23194,6 +23211,9 @@ void MessagesManager::load_notification_settings() { if (!chats_notification_settings_.is_synchronized) { send_get_scope_notification_settings_query(NotificationSettingsScope::Group, Promise<>()); } + if (!channels_notification_settings_.is_synchronized) { + send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>()); + } } string MessagesManager::get_channel_pts_key(DialogId dialog_id) { @@ -24781,7 +24801,8 @@ void MessagesManager::get_current_state(vector scopes{NotificationSettingsScope::Private, NotificationSettingsScope::Group}; + vector scopes{NotificationSettingsScope::Private, NotificationSettingsScope::Group, + NotificationSettingsScope::Channel}; for (auto scope : scopes) { auto current_settings = get_scope_notification_settings(scope); CHECK(current_settings != nullptr); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 2d99bfd3..0d2cbbf6 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1778,7 +1778,7 @@ class MessagesManager : public Actor { std::pair get_dialog_mute_until(DialogId dialog_id, const Dialog *d) const; - static NotificationSettingsScope get_dialog_notification_setting_scope(DialogId dialog_id); + NotificationSettingsScope get_dialog_notification_setting_scope(DialogId dialog_id) const; int32 get_scope_mute_until(DialogId dialog_id) const; @@ -2214,6 +2214,7 @@ class MessagesManager : public Actor { ScopeNotificationSettings users_notification_settings_; ScopeNotificationSettings chats_notification_settings_; + ScopeNotificationSettings channels_notification_settings_; std::unordered_map notification_group_id_to_dialog_id_; diff --git a/td/telegram/NotificationSettings.cpp b/td/telegram/NotificationSettings.cpp index ec49d03f..f077a3bb 100644 --- a/td/telegram/NotificationSettings.cpp +++ b/td/telegram/NotificationSettings.cpp @@ -31,6 +31,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, NotificationSettingsSco return string_builder << "notification settings for private chats"; case NotificationSettingsScope::Group: return string_builder << "notification settings for group chats"; + case NotificationSettingsScope::Channel: + return string_builder << "notification settings for channel chats"; default: UNREACHABLE(); return string_builder; @@ -51,6 +53,8 @@ td_api::object_ptr get_notification_settings_ return td_api::make_object(); case NotificationSettingsScope::Group: return td_api::make_object(); + case NotificationSettingsScope::Channel: + return td_api::make_object(); default: UNREACHABLE(); return nullptr; @@ -85,6 +89,8 @@ telegram_api::object_ptr get_input_notify_peer(No return telegram_api::make_object(); case NotificationSettingsScope::Group: return telegram_api::make_object(); + case NotificationSettingsScope::Channel: + return telegram_api::make_object(); default: return nullptr; } @@ -98,6 +104,8 @@ NotificationSettingsScope get_notification_settings_scope( return NotificationSettingsScope::Private; case td_api::notificationSettingsScopeGroupChats::ID: return NotificationSettingsScope::Group; + case td_api::notificationSettingsScopeChannelChats::ID: + return NotificationSettingsScope::Channel; default: UNREACHABLE(); return NotificationSettingsScope::Private; diff --git a/td/telegram/NotificationSettings.h b/td/telegram/NotificationSettings.h index ca0b798d..2be453a5 100644 --- a/td/telegram/NotificationSettings.h +++ b/td/telegram/NotificationSettings.h @@ -54,7 +54,7 @@ class DialogNotificationSettings { } }; -enum class NotificationSettingsScope : int32 { Private, Group }; +enum class NotificationSettingsScope : int32 { Private, Group, Channel }; class ScopeNotificationSettings { public: diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index a8712c53..5cc73321 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1521,6 +1521,9 @@ void UpdatesManager::on_update(tl_object_ptr case telegram_api::notifyChats::ID: return td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Group, std::move(update->notify_settings_)); + case telegram_api::notifyBroadcasts::ID: + return td_->messages_manager_->on_update_scope_notify_settings(NotificationSettingsScope::Channel, + std::move(update->notify_settings_)); default: UNREACHABLE(); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index ef6b0bc7..1696a61b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -883,7 +883,10 @@ class CliClient final : public Actor { } tl_object_ptr get_notification_settings_scope(Slice scope) const { - if (scope == "chats" || scope == "groups" || scope == "channels" || as_bool(scope.str())) { + if (scope == "channels" || scope == "ch") { + return make_tl_object(); + } + if (scope == "chats" || scope == "groups" || as_bool(scope.str())) { return make_tl_object(); } return make_tl_object(); diff --git a/td/telegram/net/MtprotoHeader.cpp b/td/telegram/net/MtprotoHeader.cpp index e6d86ab7..a9a1cffa 100644 --- a/td/telegram/net/MtprotoHeader.cpp +++ b/td/telegram/net/MtprotoHeader.cpp @@ -21,7 +21,7 @@ class HeaderStorer { } template void store(StorerT &storer) const { - constexpr int32 LAYER = 86; + constexpr int32 LAYER = 87; using td::store; // invokeWithLayer#da9b0d0d {X:Type} layer:int query:!X = X;