Use object_id instead of message_id in NotificationGroupInfo.

This commit is contained in:
levlam 2023-08-22 16:32:40 +03:00
parent ce1fdf097c
commit 15c14e4983
4 changed files with 31 additions and 29 deletions

View File

@ -29198,12 +29198,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) &&
m->message_id.get()) &&
(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) &&
m->message_id.get()) &&
m->message_id > d->last_read_inbox_message_id;
}
}
@ -29222,7 +29222,8 @@ void MessagesManager::try_add_pinned_message_notification(Dialog *d, vector<Noti
auto m = get_message_force(d, message_id, "try_add_pinned_message_notification");
if (m != nullptr &&
!d->notification_info->mention_notification_group_.is_removed_notification(m->notification_id, m->message_id) &&
!d->notification_info->mention_notification_group_.is_removed_notification(m->notification_id,
m->message_id.get()) &&
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;
@ -29315,7 +29316,7 @@ vector<Notification> MessagesManager::get_message_notifications_from_database_fo
is_found = true;
}
if (group_info.is_removed_notification(notification_id, m->message_id) ||
if (group_info.is_removed_notification(notification_id, m->message_id.get()) ||
(!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
@ -29473,7 +29474,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) ||
if (!group_info.is_valid() || group_info.is_removed_notification(from_notification_id, from_message_id.get()) ||
(!from_mentions && from_message_id <= d->last_read_inbox_message_id)) {
return promise.set_value(vector<Notification>());
}
@ -29567,7 +29568,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) ||
if (group_info.is_removed_notification(notification_id, m->message_id.get()) ||
(!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,
@ -29736,7 +29737,8 @@ 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, "remove_message_notifications")) {
if (group_info.set_max_removed_notification_id(max_notification_id, max_message_id.get_prev_server_message_id().get(),
"remove_message_notifications")) {
on_dialog_updated(dialog_id, "remove_message_notifications");
}
}
@ -29898,7 +29900,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_message_id(m->message_id)) {
if (group_info.is_removed_object_id(m->message_id.get())) {
is_active = false;
}
}
@ -30089,8 +30091,9 @@ void MessagesManager::remove_all_dialog_notifications(Dialog *d, bool from_menti
NotificationGroupInfo &group_info = get_notification_group_info(d, from_mentions);
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_,
source);
group_info.set_max_removed_notification_id(
last_notification_id, d->notification_info->max_notification_message_id_.get_prev_server_message_id().get(),
source);
on_dialog_updated(d->dialog_id, source);
if (!d->notification_info->pending_new_message_notifications_.empty()) {
@ -36686,7 +36689,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&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_message_id(pinned_message_id)) {
d->notification_info->mention_notification_group_.is_removed_object_id(pinned_message_id.get())) {
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_message_id,

View File

@ -32,14 +32,14 @@ bool NotificationGroupInfo::set_last_notification(int32 last_notification_date,
}
bool NotificationGroupInfo::set_max_removed_notification_id(NotificationId max_removed_notification_id,
MessageId max_removed_message_id, const char *source) {
int64 max_removed_object_id, const char *source) {
if (max_removed_notification_id.get() <= max_removed_notification_id_.get()) {
return false;
}
if (max_removed_message_id > max_removed_message_id_) {
VLOG(notifications) << "Set max_removed_message_id in " << group_id_ << " to " << max_removed_message_id << " from "
if (max_removed_object_id > max_removed_object_id_) {
VLOG(notifications) << "Set max_removed_object_id in " << group_id_ << " to " << max_removed_object_id << " from "
<< source;
max_removed_message_id_ = max_removed_message_id.get_prev_server_message_id();
max_removed_object_id_ = max_removed_object_id;
}
VLOG(notifications) << "Set max_removed_notification_id in " << group_id_ << " to " << max_removed_notification_id
@ -61,20 +61,20 @@ void NotificationGroupInfo::drop_max_removed_notification_id() {
}
VLOG(notifications) << "Drop max_removed_notification_id in " << group_id_;
max_removed_message_id_ = MessageId();
max_removed_object_id_ = 0;
max_removed_notification_id_ = NotificationId();
}
bool NotificationGroupInfo::is_removed_notification(NotificationId notification_id, MessageId message_id) const {
return is_removed_notification_id(notification_id) || is_removed_message_id(message_id);
bool NotificationGroupInfo::is_removed_notification(NotificationId notification_id, int64 object_id) const {
return is_removed_notification_id(notification_id) || is_removed_object_id(object_id);
}
bool NotificationGroupInfo::is_removed_notification_id(NotificationId notification_id) const {
return notification_id.get() <= max_removed_notification_id_.get();
}
bool NotificationGroupInfo::is_removed_message_id(MessageId message_id) const {
return message_id <= max_removed_message_id_;
bool NotificationGroupInfo::is_removed_object_id(int64 object_id) const {
return object_id <= max_removed_object_id_;
}
bool NotificationGroupInfo::is_used_notification_id(NotificationId notification_id) const {
@ -118,14 +118,14 @@ NotificationGroupId NotificationGroupInfo::get_reused_group_id() {
auto result = group_id_;
group_id_ = NotificationGroupId();
max_removed_notification_id_ = NotificationId();
max_removed_message_id_ = MessageId();
max_removed_object_id_ = 0;
return result;
}
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_;
<< group_info.max_removed_notification_id_ << '/' << group_info.max_removed_object_id_;
}
} // namespace td

View File

@ -7,7 +7,6 @@
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/NotificationGroupId.h"
#include "td/telegram/NotificationGroupKey.h"
#include "td/telegram/NotificationId.h"
@ -19,7 +18,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
MessageId max_removed_message_id_; // message identifier, up to which all notifications are removed
int64 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
@ -53,16 +52,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, MessageId max_removed_message_id,
bool set_max_removed_notification_id(NotificationId max_removed_notification_id, int64 max_removed_object_id,
const char *source);
void drop_max_removed_notification_id();
bool is_removed_notification(NotificationId notification_id, MessageId message_id) const;
bool is_removed_notification(NotificationId notification_id, int64 object_id) const;
bool is_removed_notification_id(NotificationId notification_id) const;
bool is_removed_message_id(MessageId message_id) const;
bool is_removed_object_id(int64 object_id) const;
bool is_used_notification_id(NotificationId notification_id) const;

View File

@ -20,7 +20,7 @@ void NotificationGroupInfo::store(StorerT &storer) const {
store(last_notification_date_, storer);
store(last_notification_id_, storer);
store(max_removed_notification_id_, storer);
store(max_removed_message_id_, storer);
store(max_removed_object_id_, storer);
}
template <class ParserT>
@ -31,7 +31,7 @@ void NotificationGroupInfo::parse(ParserT &parser) {
parse(last_notification_id_, parser);
parse(max_removed_notification_id_, parser);
if (parser.version() >= static_cast<int32>(Version::AddNotificationGroupInfoMaxRemovedMessageId)) {
parse(max_removed_message_id_, parser);
parse(max_removed_object_id_, parser);
}
}