From 432f77ae855f23f56ee278fe5c2745f34aea7ed5 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 26 Aug 2023 00:48:57 +0300 Subject: [PATCH] Use NotificationObjectId in NotificationGroupInfo. --- td/telegram/MessagesManager.cpp | 22 ++++++++++------------ td/telegram/NotificationGroupInfo.cpp | 12 +++++++----- td/telegram/NotificationGroupInfo.h | 11 ++++++----- td/telegram/NotificationObjectId.h | 10 ++++++++++ 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 2e6e1a15a..7265aa676 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -29249,12 +29249,12 @@ bool MessagesManager::is_message_notification_active(const Dialog *d, const Mess } if (is_from_mention_notification_group(m)) { return !d->notification_info->mention_notification_group_.is_removed_notification(m->notification_id, - m->message_id.get()) && + m->message_id) && (m->contains_unread_mention || m->message_id == d->notification_info->pinned_message_notification_message_id_); } else { return !d->notification_info->message_notification_group_.is_removed_notification(m->notification_id, - m->message_id.get()) && + m->message_id) && m->message_id > d->last_read_inbox_message_id; } } @@ -29273,8 +29273,7 @@ void MessagesManager::try_add_pinned_message_notification(Dialog *d, vectornotification_info->mention_notification_group_.is_removed_notification(m->notification_id, - m->message_id.get()) && + !d->notification_info->mention_notification_group_.is_removed_notification(m->notification_id, m->message_id) && m->message_id > d->last_read_inbox_message_id && !is_dialog_pinned_message_notifications_disabled(d)) { if (m->notification_id.get() < max_notification_id.get()) { VLOG(notifications) << "Add " << m->notification_id << " about pinned " << message_id << " in " << d->dialog_id; @@ -29368,7 +29367,7 @@ vector MessagesManager::get_message_notifications_from_database_fo is_found = true; } - if (group_info.is_removed_notification(notification_id, m->message_id.get()) || + if (group_info.is_removed_notification(notification_id, m->message_id) || (!from_mentions && m->message_id <= d->last_read_inbox_message_id)) { // if message still has notification_id, but it was removed, // then there will be no more messages with active notifications @@ -29526,7 +29525,7 @@ void MessagesManager::do_get_message_notifications_from_database(Dialog *d, bool CHECK(!from_message_id.is_scheduled()); auto &group_info = get_notification_group_info(d, from_mentions); - if (!group_info.is_valid() || group_info.is_removed_notification(from_notification_id, from_message_id.get()) || + if (!group_info.is_valid() || group_info.is_removed_notification(from_notification_id, from_message_id) || (!from_mentions && from_message_id <= d->last_read_inbox_message_id)) { return promise.set_value(vector()); } @@ -29620,7 +29619,7 @@ void MessagesManager::on_get_message_notifications_from_database(DialogId dialog from_message_id = m->message_id; } - if (group_info.is_removed_notification(notification_id, m->message_id.get()) || + if (group_info.is_removed_notification(notification_id, m->message_id) || (!from_mentions && m->message_id <= d->last_read_inbox_message_id)) { // if message still has notification_id, but it was removed via max_removed_notification_id, // or max_removed_message_id, or last_read_inbox_message_id, @@ -29789,7 +29788,7 @@ void MessagesManager::remove_message_notifications(DialogId dialog_id, Notificat return; } auto &group_info = get_notification_group_info(d, from_mentions); - if (group_info.set_max_removed_notification_id(max_notification_id, max_message_id.get_prev_server_message_id().get(), + if (group_info.set_max_removed_notification_id(max_notification_id, max_message_id.get_prev_server_message_id(), "remove_message_notifications")) { on_dialog_updated(dialog_id, "remove_message_notifications"); } @@ -29952,7 +29951,7 @@ bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool f from_mentions ? m->contains_unread_mention || is_pinned : m->message_id > d->last_read_inbox_message_id; if (is_active) { auto &group_info = get_notification_group_info(d, from_mentions); - if (group_info.is_removed_object_id(m->message_id.get())) { + if (group_info.is_removed_object_id(m->message_id)) { is_active = false; } } @@ -30135,8 +30134,7 @@ void MessagesManager::remove_all_dialog_notifications(Dialog *d, bool from_menti if (group_info.is_valid() && group_info.get_last_notification_id().is_valid()) { auto last_notification_id = group_info.get_last_notification_id(); group_info.set_max_removed_notification_id( - last_notification_id, d->notification_info->max_notification_message_id_.get_prev_server_message_id().get(), - source); + last_notification_id, d->notification_info->max_notification_message_id_.get_prev_server_message_id(), source); on_dialog_updated(d->dialog_id, source); if (!d->notification_info->pending_new_message_notifications_.empty()) { @@ -36732,7 +36730,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr &&last_datab on_dialog_updated(dialog_id, "fix pinned message notification"); } else if (is_dialog_pinned_message_notifications_disabled(d) || pinned_message_id <= d->last_read_inbox_message_id || - d->notification_info->mention_notification_group_.is_removed_object_id(pinned_message_id.get())) { + d->notification_info->mention_notification_group_.is_removed_object_id(pinned_message_id)) { VLOG(notifications) << "Remove disabled pinned message notification in " << pinned_message_id << " in " << dialog_id; send_closure_later(G()->notification_manager(), &NotificationManager::remove_temporary_notification_by_object_id, diff --git a/td/telegram/NotificationGroupInfo.cpp b/td/telegram/NotificationGroupInfo.cpp index a3469feb0..db2c7e09b 100644 --- a/td/telegram/NotificationGroupInfo.cpp +++ b/td/telegram/NotificationGroupInfo.cpp @@ -32,7 +32,8 @@ bool NotificationGroupInfo::set_last_notification(int32 last_notification_date, } bool NotificationGroupInfo::set_max_removed_notification_id(NotificationId max_removed_notification_id, - int64 max_removed_object_id, const char *source) { + NotificationObjectId max_removed_object_id, + const char *source) { if (max_removed_notification_id.get() <= max_removed_notification_id_.get()) { return false; } @@ -61,11 +62,12 @@ void NotificationGroupInfo::drop_max_removed_notification_id() { } VLOG(notifications) << "Drop max_removed_notification_id in " << group_id_; - max_removed_object_id_ = 0; + max_removed_object_id_ = {}; max_removed_notification_id_ = NotificationId(); } -bool NotificationGroupInfo::is_removed_notification(NotificationId notification_id, int64 object_id) const { +bool NotificationGroupInfo::is_removed_notification(NotificationId notification_id, + NotificationObjectId object_id) const { return is_removed_notification_id(notification_id) || is_removed_object_id(object_id); } @@ -73,7 +75,7 @@ bool NotificationGroupInfo::is_removed_notification_id(NotificationId notificati return notification_id.get() <= max_removed_notification_id_.get(); } -bool NotificationGroupInfo::is_removed_object_id(int64 object_id) const { +bool NotificationGroupInfo::is_removed_object_id(NotificationObjectId object_id) const { return object_id <= max_removed_object_id_; } @@ -118,7 +120,7 @@ NotificationGroupId NotificationGroupInfo::get_reused_group_id() { auto result = group_id_; group_id_ = NotificationGroupId(); max_removed_notification_id_ = NotificationId(); - max_removed_object_id_ = 0; + max_removed_object_id_ = {}; return result; } diff --git a/td/telegram/NotificationGroupInfo.h b/td/telegram/NotificationGroupInfo.h index 1ec9ec69e..1b37e14cd 100644 --- a/td/telegram/NotificationGroupInfo.h +++ b/td/telegram/NotificationGroupInfo.h @@ -10,6 +10,7 @@ #include "td/telegram/NotificationGroupId.h" #include "td/telegram/NotificationGroupKey.h" #include "td/telegram/NotificationId.h" +#include "td/telegram/NotificationObjectId.h" #include "td/utils/common.h" #include "td/utils/StringBuilder.h" @@ -21,7 +22,7 @@ class NotificationGroupInfo { int32 last_notification_date_ = 0; // date of the last notification in the group NotificationId last_notification_id_; // identifier of the last notification in the group NotificationId max_removed_notification_id_; // notification identifier, up to which all notifications are removed - int64 max_removed_object_id_; // object identifier, up to which all notifications are removed + NotificationObjectId max_removed_object_id_; // object identifier, up to which all notifications are removed bool is_key_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 @@ -55,16 +56,16 @@ class NotificationGroupInfo { bool set_last_notification(int32 last_notification_date, NotificationId last_notification_id, const char *source); - bool set_max_removed_notification_id(NotificationId max_removed_notification_id, int64 max_removed_object_id, - const char *source); + bool set_max_removed_notification_id(NotificationId max_removed_notification_id, + NotificationObjectId max_removed_object_id, const char *source); void drop_max_removed_notification_id(); - bool is_removed_notification(NotificationId notification_id, int64 object_id) const; + bool is_removed_notification(NotificationId notification_id, NotificationObjectId object_id) const; bool is_removed_notification_id(NotificationId notification_id) const; - bool is_removed_object_id(int64 object_id) const; + bool is_removed_object_id(NotificationObjectId object_id) const; bool is_used_notification_id(NotificationId notification_id) const; diff --git a/td/telegram/NotificationObjectId.h b/td/telegram/NotificationObjectId.h index 7f38727de..ba444f1db 100644 --- a/td/telegram/NotificationObjectId.h +++ b/td/telegram/NotificationObjectId.h @@ -56,6 +56,16 @@ class NotificationObjectId { friend bool operator>=(const NotificationObjectId &lhs, const NotificationObjectId &rhs) { return lhs.id >= rhs.id; } + + template + void store(StorerT &storer) const { + storer.store_long(id); + } + + template + void parse(ParserT &parser) { + id = parser.fetch_long(); + } }; struct NotificationObjectIdHash {