Improve get_dialog_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings>).

This commit is contained in:
levlam 2022-12-06 15:23:11 +03:00
parent ac9ee00a6b
commit 3c842f1ecb
6 changed files with 38 additions and 27 deletions

View File

@ -69,18 +69,32 @@ Result<DialogNotificationSettings> get_dialog_notification_settings(
}
DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings,
bool old_use_default_disable_pinned_message_notifications,
bool old_disable_pinned_message_notifications,
bool old_use_default_disable_mention_notifications,
bool old_disable_mention_notifications) {
if (settings == nullptr) {
return DialogNotificationSettings();
const DialogNotificationSettings *old_settings) {
bool old_use_default_disable_pinned_message_notifications = true;
bool old_disable_pinned_message_notifications = false;
bool old_use_default_disable_mention_notifications = true;
bool old_disable_mention_notifications = false;
if (old_settings != nullptr) {
old_use_default_disable_pinned_message_notifications =
old_settings->use_default_disable_pinned_message_notifications;
old_disable_pinned_message_notifications = old_settings->disable_pinned_message_notifications;
old_use_default_disable_mention_notifications = old_settings->use_default_disable_mention_notifications;
old_disable_mention_notifications = old_settings->disable_mention_notifications;
}
if (settings == nullptr) {
auto result = DialogNotificationSettings();
result.use_default_disable_pinned_message_notifications = old_use_default_disable_pinned_message_notifications;
result.disable_pinned_message_notifications = old_disable_pinned_message_notifications;
result.use_default_disable_mention_notifications = old_use_default_disable_mention_notifications;
result.disable_mention_notifications = old_disable_mention_notifications;
return result;
}
bool use_default_mute_until = (settings->flags_ & telegram_api::peerNotifySettings::MUTE_UNTIL_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_;
bool silent_send_message = settings->silent_;
return {use_default_mute_until,
mute_until,
get_notification_sound(settings.get()),

View File

@ -64,10 +64,7 @@ Result<DialogNotificationSettings> get_dialog_notification_settings(
td_api::object_ptr<td_api::chatNotificationSettings> &&notification_settings, bool old_silent_send_message);
DialogNotificationSettings get_dialog_notification_settings(tl_object_ptr<telegram_api::peerNotifySettings> &&settings,
bool old_use_default_disable_pinned_message_notifications,
bool old_disable_pinned_message_notifications,
bool old_use_default_disable_mention_notifications,
bool old_disable_mention_notifications);
const DialogNotificationSettings *old_settings);
bool are_default_dialog_notification_settings(const DialogNotificationSettings &settings, bool compare_sound);

View File

@ -16,7 +16,8 @@
namespace td {
ForumTopic::ForumTopic(Td *td, tl_object_ptr<telegram_api::ForumTopic> &&forum_topic_ptr) {
ForumTopic::ForumTopic(Td *td, tl_object_ptr<telegram_api::ForumTopic> &&forum_topic_ptr,
const DialogNotificationSettings *current_notification_settings) {
CHECK(forum_topic_ptr != nullptr);
if (forum_topic_ptr->get_id() != telegram_api::forumTopic::ID) {
LOG(INFO) << "Receive " << to_string(forum_topic_ptr);
@ -27,7 +28,7 @@ ForumTopic::ForumTopic(Td *td, tl_object_ptr<telegram_api::ForumTopic> &&forum_t
is_short_ = forum_topic->short_;
is_pinned_ = forum_topic->pinned_;
notification_settings_ =
get_dialog_notification_settings(std::move(forum_topic->notify_settings_), true, false, true, false);
get_dialog_notification_settings(std::move(forum_topic->notify_settings_), current_notification_settings);
draft_message_ = get_draft_message(td->contacts_manager_.get(), std::move(forum_topic->draft_));
if (is_short_) {
@ -49,7 +50,8 @@ td_api::object_ptr<td_api::forumTopic> ForumTopic::get_forum_topic_object(Td *td
}
// TODO draft_message = can_send_message(dialog_id, info_.get_top_thread_message_id()).is_ok() ? ... : nullptr;
auto last_message = td->messages_manager_->get_message_object({dialog_id, last_message_id_}, "get_forum_topic_object");
auto last_message =
td->messages_manager_->get_message_object({dialog_id, last_message_id_}, "get_forum_topic_object");
auto draft_message = get_draft_message_object(draft_message_);
return td_api::make_object<td_api::forumTopic>(
info.get_forum_topic_info_object(td), std::move(last_message), is_pinned_, unread_count_,

View File

@ -34,7 +34,8 @@ class ForumTopic {
public:
ForumTopic() = default;
ForumTopic(Td *td, tl_object_ptr<telegram_api::ForumTopic> &&forum_topic_ptr);
ForumTopic(Td *td, tl_object_ptr<telegram_api::ForumTopic> &&forum_topic_ptr,
const DialogNotificationSettings *current_notification_settings);
bool is_short() const {
return is_short_;

View File

@ -410,10 +410,7 @@ void ForumTopicManager::on_update_forum_topic_notify_settings(
return;
}
auto notification_settings = get_dialog_notification_settings(
std::move(peer_notify_settings), current_settings->use_default_disable_pinned_message_notifications,
current_settings->disable_pinned_message_notifications,
current_settings->use_default_disable_mention_notifications, current_settings->disable_mention_notifications);
auto notification_settings = get_dialog_notification_settings(std::move(peer_notify_settings), current_settings);
if (!notification_settings.is_synchronized) {
return;
}
@ -658,13 +655,15 @@ MessageId ForumTopicManager::on_get_forum_topic(DialogId dialog_id,
}
case telegram_api::forumTopic::ID: {
auto forum_topic_info = td::make_unique<ForumTopicInfo>(forum_topic);
auto forum_topic_full = td::make_unique<ForumTopic>(td_, std::move(forum_topic));
MessageId top_thread_message_id = forum_topic_info->get_top_thread_message_id();
Topic *topic = add_topic(dialog_id, top_thread_message_id);
auto current_notification_settings =
topic->topic_ == nullptr ? nullptr : topic->topic_->get_notification_settings();
auto forum_topic_full = td::make_unique<ForumTopic>(td_, std::move(forum_topic), current_notification_settings);
if (forum_topic_full->is_short()) {
LOG(ERROR) << "Receive short " << to_string(forum_topic);
return MessageId();
}
MessageId top_thread_message_id = forum_topic_info->get_top_thread_message_id();
Topic *topic = add_topic(dialog_id, top_thread_message_id);
if (topic->topic_ == nullptr || true) {
topic->topic_ = std::move(forum_topic_full);
topic->need_save_to_database_ = true; // temporary

View File

@ -8445,10 +8445,8 @@ void MessagesManager::on_update_dialog_notify_settings(
return;
}
DialogNotificationSettings notification_settings = ::td::get_dialog_notification_settings(
std::move(peer_notify_settings), current_settings->use_default_disable_pinned_message_notifications,
current_settings->disable_pinned_message_notifications,
current_settings->use_default_disable_mention_notifications, current_settings->disable_mention_notifications);
DialogNotificationSettings notification_settings =
::td::get_dialog_notification_settings(std::move(peer_notify_settings), current_settings);
if (!notification_settings.is_synchronized) {
return;
}