From d2cf780a1f31451e695ad53c4550ce97ff2a2f01 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 21 Aug 2023 18:52:56 +0300 Subject: [PATCH] Move class NotificationGroupInfo to a separate header. --- CMakeLists.txt | 3 ++ td/telegram/MessagesManager.cpp | 43 ++++----------------------- td/telegram/MessagesManager.h | 17 +---------- td/telegram/NotificationGroupInfo.cpp | 17 +++++++++++ td/telegram/NotificationGroupInfo.h | 33 ++++++++++++++++++++ td/telegram/NotificationGroupInfo.hpp | 38 +++++++++++++++++++++++ 6 files changed, 98 insertions(+), 53 deletions(-) create mode 100644 td/telegram/NotificationGroupInfo.cpp create mode 100644 td/telegram/NotificationGroupInfo.h create mode 100644 td/telegram/NotificationGroupInfo.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 450f07447..7cbc8f8ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -426,6 +426,7 @@ set(TDLIB_SOURCE td/telegram/net/SessionProxy.cpp td/telegram/net/SessionMultiProxy.cpp td/telegram/NewPasswordState.cpp + td/telegram/NotificationGroupInfo.cpp td/telegram/NotificationManager.cpp td/telegram/NotificationSettingsScope.cpp td/telegram/NotificationSettingsManager.cpp @@ -715,6 +716,7 @@ set(TDLIB_SOURCE td/telegram/NewPasswordState.h td/telegram/Notification.h td/telegram/NotificationGroupId.h + td/telegram/NotificationGroupInfo.h td/telegram/NotificationGroupKey.h td/telegram/NotificationGroupType.h td/telegram/NotificationId.h @@ -847,6 +849,7 @@ set(TDLIB_SOURCE td/telegram/MessageReaction.hpp td/telegram/MessageReplyInfo.hpp td/telegram/MinChannel.hpp + td/telegram/NotificationGroupInfo.hpp td/telegram/OrderInfo.hpp td/telegram/Photo.hpp td/telegram/PhotoSize.hpp diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 40443bcc5..67ab35a73 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -49,6 +49,7 @@ #include "td/telegram/misc.h" #include "td/telegram/net/DcId.h" #include "td/telegram/net/NetQuery.h" +#include "td/telegram/NotificationGroupInfo.hpp" #include "td/telegram/NotificationGroupType.h" #include "td/telegram/NotificationManager.h" #include "td/telegram/NotificationSettingsManager.h" @@ -5197,28 +5198,6 @@ void MessagesManager::Message::parse(ParserT &parser) { } } -template -void MessagesManager::NotificationGroupInfo::store(StorerT &storer) const { - using td::store; - store(group_id, storer); - store(last_notification_date, storer); - store(last_notification_id, storer); - store(max_removed_notification_id, storer); - store(max_removed_message_id, storer); -} - -template -void MessagesManager::NotificationGroupInfo::parse(ParserT &parser) { - using td::parse; - parse(group_id, parser); - parse(last_notification_date, parser); - parse(last_notification_id, parser); - parse(max_removed_notification_id, parser); - if (parser.version() >= static_cast(Version::AddNotificationGroupInfoMaxRemovedMessageId)) { - parse(max_removed_message_id, parser); - } -} - template void MessagesManager::Dialog::store(StorerT &storer) const { using td::store; @@ -28912,14 +28891,14 @@ void MessagesManager::send_update_new_message(const Dialog *d, const Message *m) td_api::make_object(get_message_object(d->dialog_id, m, "send_update_new_message"))); } -MessagesManager::NotificationGroupInfo &MessagesManager::get_notification_group_info(Dialog *d, bool from_mentions) { +NotificationGroupInfo &MessagesManager::get_notification_group_info(Dialog *d, bool from_mentions) { CHECK(d != nullptr); auto notification_info = add_dialog_notification_info(d); return from_mentions ? notification_info->mention_notification_group_ : notification_info->message_notification_group_; } -MessagesManager::NotificationGroupInfo &MessagesManager::get_notification_group_info(Dialog *d, const Message *m) { +NotificationGroupInfo &MessagesManager::get_notification_group_info(Dialog *d, const Message *m) { return get_notification_group_info(d, is_from_mention_notification_group(m)); } @@ -37020,20 +36999,10 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab << d->first_database_message_id << ", last database " << d->last_database_message_id << ", last " << d->last_message_id << " with order " << d->order; if (d->notification_info != nullptr) { - VLOG(notifications) << "Have " << dialog_id << " with message " - << d->notification_info->message_notification_group_.group_id << " with last " - << d->notification_info->message_notification_group_.last_notification_id << " sent at " - << d->notification_info->message_notification_group_.last_notification_date << ", max removed " - << d->notification_info->message_notification_group_.max_removed_notification_id << "/" - << d->notification_info->message_notification_group_.max_removed_message_id + VLOG(notifications) << "Have " << dialog_id << " with message " << d->notification_info->message_notification_group_ << " and new secret chat " << d->notification_info->new_secret_chat_notification_id_; - VLOG(notifications) << "Have " << dialog_id << " with mention " - << d->notification_info->mention_notification_group_.group_id << " with last " - << d->notification_info->mention_notification_group_.last_notification_id << " sent at " - << d->notification_info->mention_notification_group_.last_notification_date << ", max removed " - << d->notification_info->mention_notification_group_.max_removed_notification_id << "/" - << d->notification_info->mention_notification_group_.max_removed_message_id << " and pinned " - << d->notification_info->pinned_message_notification_message_id_; + VLOG(notifications) << "Have " << dialog_id << " with mention " << d->notification_info->mention_notification_group_ + << " and pinned " << d->notification_info->pinned_message_notification_message_id_; VLOG(notifications) << "In " << dialog_id << " have last_read_inbox_message_id = " << d->last_read_inbox_message_id << ", last_new_message_id = " << d->last_new_message_id << ", max_notification_message_id = " << d->notification_info->max_notification_message_id_; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index df5e03587..79417b522 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -48,6 +48,7 @@ #include "td/telegram/net/NetQuery.h" #include "td/telegram/Notification.h" #include "td/telegram/NotificationGroupId.h" +#include "td/telegram/NotificationGroupInfo.h" #include "td/telegram/NotificationGroupKey.h" #include "td/telegram/NotificationGroupType.h" #include "td/telegram/NotificationId.h" @@ -1286,22 +1287,6 @@ class MessagesManager final : public Actor { ~Message() = default; }; - struct NotificationGroupInfo { - NotificationGroupId group_id; - int32 last_notification_date = 0; // date of last notification in the group - NotificationId last_notification_id; // identifier of last notification in the group - NotificationId max_removed_notification_id; // notification identifier, up to which all notifications are removed - MessageId max_removed_message_id; // message identifier, up to which all notifications are removed - bool is_changed = false; // true, if the group needs to be saved to database - bool try_reuse = false; // true, if the group needs to be deleted from database and tried to be reused - - template - void store(StorerT &storer) const; - - template - void parse(ParserT &parser); - }; - struct DialogScheduledMessages { FlatHashMap scheduled_message_date_; diff --git a/td/telegram/NotificationGroupInfo.cpp b/td/telegram/NotificationGroupInfo.cpp new file mode 100644 index 000000000..bf09d0d01 --- /dev/null +++ b/td/telegram/NotificationGroupInfo.cpp @@ -0,0 +1,17 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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/NotificationGroupInfo.h" + +namespace td { + +StringBuilder &operator<<(StringBuilder &string_builder, const NotificationGroupInfo &group_info) { + return string_builder << group_info.group_id << " with last " << group_info.last_notification_id << " sent at " + << group_info.last_notification_date << ", max removed " + << group_info.max_removed_notification_id << '/' << group_info.max_removed_message_id; +} + +} // namespace td diff --git a/td/telegram/NotificationGroupInfo.h b/td/telegram/NotificationGroupInfo.h new file mode 100644 index 000000000..6bce03994 --- /dev/null +++ b/td/telegram/NotificationGroupInfo.h @@ -0,0 +1,33 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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/MessageId.h" +#include "td/telegram/NotificationGroupId.h" +#include "td/telegram/NotificationId.h" + +namespace td { + +struct NotificationGroupInfo { + NotificationGroupId group_id; + int32 last_notification_date = 0; // date of last notification in the group + NotificationId last_notification_id; // identifier of last notification in the group + NotificationId max_removed_notification_id; // notification identifier, up to which all notifications are removed + MessageId max_removed_message_id; // message identifier, up to which all notifications are removed + bool is_changed = false; // true, if the group needs to be saved to database + bool try_reuse = false; // true, if the group needs to be deleted from database and tried to be reused + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); +}; + +StringBuilder &operator<<(StringBuilder &string_builder, const NotificationGroupInfo &group_info); + +} // namespace td diff --git a/td/telegram/NotificationGroupInfo.hpp b/td/telegram/NotificationGroupInfo.hpp new file mode 100644 index 000000000..b356617ef --- /dev/null +++ b/td/telegram/NotificationGroupInfo.hpp @@ -0,0 +1,38 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// 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/NotificationGroupInfo.h" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void NotificationGroupInfo::store(StorerT &storer) const { + using td::store; + store(group_id, storer); + store(last_notification_date, storer); + store(last_notification_id, storer); + store(max_removed_notification_id, storer); + store(max_removed_message_id, storer); +} + +template +void NotificationGroupInfo::parse(ParserT &parser) { + using td::parse; + parse(group_id, parser); + parse(last_notification_date, parser); + parse(last_notification_id, parser); + parse(max_removed_notification_id, parser); + if (parser.version() >= static_cast(Version::AddNotificationGroupInfoMaxRemovedMessageId)) { + parse(max_removed_message_id, parser); + } +} + +} // namespace td