Support removing notifications by max_message_id.
GitOrigin-RevId: 7841a68dcc05cb70910da0b28b93996c87782f4b
This commit is contained in:
parent
4ec3171d29
commit
cb1d429eb2
@ -532,6 +532,9 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti
|
||||
added_notifications.push_back(
|
||||
get_notification_object(group_it->first.dialog_id,
|
||||
group_it->second.notifications[old_group_size - max_notification_group_size_ - 1]));
|
||||
if (added_notifications.back()->type_ == nullptr) {
|
||||
added_notifications.pop_back();
|
||||
}
|
||||
} else {
|
||||
// TODO preload more notifications in the group
|
||||
}
|
||||
@ -552,11 +555,12 @@ void NotificationManager::remove_notification(NotificationGroupId group_id, Noti
|
||||
}
|
||||
|
||||
void NotificationManager::remove_notification_group(NotificationGroupId group_id, NotificationId max_notification_id,
|
||||
int32 new_total_count, Promise<Unit> &&promise) {
|
||||
MessageId max_message_id, int32 new_total_count,
|
||||
Promise<Unit> &&promise) {
|
||||
if (!group_id.is_valid()) {
|
||||
return promise.set_error(Status::Error(400, "Group identifier is invalid"));
|
||||
}
|
||||
if (!max_notification_id.is_valid()) {
|
||||
if (!max_notification_id.is_valid() && !max_message_id.is_valid()) {
|
||||
return promise.set_error(Status::Error(400, "Notification identifier is invalid"));
|
||||
}
|
||||
|
||||
@ -564,9 +568,11 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
VLOG(notifications) << "Remove " << group_id << " up to " << max_notification_id;
|
||||
VLOG(notifications) << "Remove " << group_id << " up to " << max_notification_id << " or " << max_message_id;
|
||||
|
||||
if (max_notification_id.is_valid()) {
|
||||
// TODO remove notifications from database by max_notification_id, save that they are removed
|
||||
}
|
||||
|
||||
auto group_it = get_group(group_id);
|
||||
if (group_it == groups_.end()) {
|
||||
@ -577,7 +583,8 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
|
||||
auto pending_delete_end = group_it->second.pending_notifications.begin();
|
||||
for (auto it = group_it->second.pending_notifications.begin(); it != group_it->second.pending_notifications.end();
|
||||
++it) {
|
||||
if (it->notification_id.get() <= max_notification_id.get()) {
|
||||
if (it->notification_id.get() <= max_notification_id.get() ||
|
||||
(max_message_id.is_valid() && it->type->get_message_id().get() <= max_message_id.get())) {
|
||||
pending_delete_end = it + 1;
|
||||
}
|
||||
}
|
||||
@ -595,7 +602,9 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
|
||||
auto old_group_size = group_it->second.notifications.size();
|
||||
auto notification_delete_end = old_group_size;
|
||||
for (size_t pos = 0; pos < notification_delete_end; pos++) {
|
||||
if (group_it->second.notifications[pos].notification_id.get() > max_notification_id.get()) {
|
||||
auto ¬ification = group_it->second.notifications[pos];
|
||||
if (notification.notification_id.get() > max_notification_id.get() &&
|
||||
(!max_message_id.is_valid() || notification.type->get_message_id().get() > max_message_id.get())) {
|
||||
notification_delete_end = pos;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/MessageId.h"
|
||||
#include "td/telegram/NotificationGroupId.h"
|
||||
#include "td/telegram/NotificationId.h"
|
||||
#include "td/telegram/NotificationType.h"
|
||||
@ -53,7 +54,7 @@ class NotificationManager : public Actor {
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void remove_notification_group(NotificationGroupId group_id, NotificationId max_notification_id,
|
||||
int32 new_total_count, Promise<Unit> &&promise);
|
||||
MessageId max_message_id, int32 new_total_count, Promise<Unit> &&promise);
|
||||
|
||||
void on_notification_group_count_max_changed();
|
||||
|
||||
|
@ -16,6 +16,10 @@ class NotificationTypeMessage : public NotificationType {
|
||||
return true;
|
||||
}
|
||||
|
||||
MessageId get_message_id() const override {
|
||||
return message_id_;
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const override {
|
||||
auto message_object = G()->td().get_actor_unsafe()->messages_manager_->get_message_object({dialog_id, message_id_});
|
||||
if (message_object == nullptr) {
|
||||
@ -44,6 +48,10 @@ class NotificationTypeSecretChat : public NotificationType {
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageId get_message_id() const override {
|
||||
return MessageId();
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const override {
|
||||
return td_api::make_object<td_api::notificationTypeNewSecretChat>();
|
||||
}
|
||||
@ -66,6 +74,10 @@ class NotificationTypeCall : public NotificationType {
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageId get_message_id() const override {
|
||||
return MessageId();
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const override {
|
||||
return td_api::make_object<td_api::notificationTypeNewCall>(call_id_.get());
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ class NotificationType {
|
||||
|
||||
virtual bool can_be_delayed() const = 0;
|
||||
|
||||
virtual MessageId get_message_id() const = 0;
|
||||
|
||||
virtual td_api::object_ptr<td_api::NotificationType> get_notification_type_object(DialogId dialog_id) const = 0;
|
||||
|
||||
virtual StringBuilder &to_string_builder(StringBuilder &string_builder) const = 0;
|
||||
|
@ -5110,7 +5110,7 @@ void Td::on_request(uint64 id, const td_api::removeNotificationGroup &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
notification_manager_->remove_notification_group(NotificationGroupId(request.notification_group_id_),
|
||||
NotificationId(request.max_notification_id_), -1,
|
||||
NotificationId(request.max_notification_id_), MessageId(), -1,
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user