Use NotificationObjectId in NotificationGroupInfo.
This commit is contained in:
parent
fcf7748758
commit
432f77ae85
@ -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, 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.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<Notification> 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<Notification>());
|
||||
}
|
||||
@ -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<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_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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -56,6 +56,16 @@ class NotificationObjectId {
|
||||
friend bool operator>=(const NotificationObjectId &lhs, const NotificationObjectId &rhs) {
|
||||
return lhs.id >= rhs.id;
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
storer.store_long(id);
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser) {
|
||||
id = parser.fetch_long();
|
||||
}
|
||||
};
|
||||
|
||||
struct NotificationObjectIdHash {
|
||||
|
Loading…
Reference in New Issue
Block a user