Implement updateNotification.

GitOrigin-RevId: 804e527cc2819e8fa6420d8a7ceea4ad6688a641
This commit is contained in:
levlam 2018-11-16 18:00:46 +03:00
parent 64c7362fd8
commit c5c3b8c95a
7 changed files with 59 additions and 19 deletions

View File

@ -2613,8 +2613,8 @@ getChatMessageByDate chat_id:int53 date:int32 = Message;
getChatMessageCount chat_id:int53 filter:SearchMessagesFilter return_local:Bool = Count;
//@description Removes an active notification from notification list @notification_id Identifier of removed notification
removeNotification notification_id:int32 = Ok;
//@description Removes an active notification from notification list @notification_group_id Identifier of notification group to which the notification belongs @notification_id Identifier of removed notification
removeNotification notification_group_id:int32 notification_id:int32 = Ok;
//@description Removes group of active notifications @notification_group_id Notification group identifier @max_notification_id Maximum identifier of removed notifications
removeNotificationGroup notification_group_id:int32 max_notification_id:int32 = Ok;

Binary file not shown.

View File

@ -5577,7 +5577,8 @@ void MessagesManager::on_message_edited(FullMessageId full_message_id) {
}
auto dialog_id = full_message_id.get_dialog_id();
Message *m = get_message(full_message_id);
Dialog *d = get_dialog(dialog_id);
const Message *m = get_message(d, full_message_id.get_message_id());
CHECK(m != nullptr);
if (td_->auth_manager_->is_bot()) {
send_update_message_edited(dialog_id, m);
@ -5587,7 +5588,8 @@ void MessagesManager::on_message_edited(FullMessageId full_message_id) {
}
if (m->notification_id.is_valid()) {
send_closure_later(G()->notification_manager(), &NotificationManager::edit_notification, m->notification_id,
send_closure_later(G()->notification_manager(), &NotificationManager::edit_notification,
get_dialog_message_notification_group_id(d), m->notification_id,
create_new_message_notification(m->message_id));
}
}

View File

@ -201,6 +201,20 @@ void NotificationManager::send_update_notification_group(td_api::object_ptr<td_a
send_closure(G()->td(), &Td::send_update, std::move(update));
}
void NotificationManager::send_update_notification(NotificationGroupId notification_group_id, DialogId dialog_id,
const Notification &notification) {
auto notification_object = get_notification_object(dialog_id, notification);
if (notification_object->type_ == nullptr) {
return;
}
// TODO delay and combine updates while getDifference is running
auto update =
td_api::make_object<td_api::updateNotification>(notification_group_id.get(), std::move(notification_object));
VLOG(notifications) << "Send " << to_string(update);
send_closure(G()->td(), &Td::send_update, std::move(update));
}
void NotificationManager::flush_pending_notifications(NotificationGroupKey &group_key, NotificationGroup &group,
vector<PendingNotification> &pending_notifications) {
if (pending_notifications.empty()) {
@ -363,7 +377,8 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_
groups_.emplace(std::move(final_group_key), std::move(group));
}
void NotificationManager::edit_notification(NotificationId notification_id, unique_ptr<NotificationType> type) {
void NotificationManager::edit_notification(NotificationGroupId group_id, NotificationId notification_id,
unique_ptr<NotificationType> type) {
if (is_disabled()) {
return;
}
@ -371,17 +386,28 @@ void NotificationManager::edit_notification(NotificationId notification_id, uniq
CHECK(notification_id.is_valid());
CHECK(type != nullptr);
VLOG(notifications) << "Edit " << notification_id << ": " << *type;
}
void NotificationManager::delete_notification(NotificationId notification_id) {
if (is_disabled()) {
return;
auto group_it = get_group(group_id);
auto &group = group_it->second;
for (size_t i = 0; i < group.notifications.size(); i++) {
auto &notification = group.notifications[i];
if (notification.notification_id == notification_id) {
notification.type = std::move(type);
if (i + max_notification_group_size_ >= group.notifications.size()) {
send_update_notification(group_it->first.group_id, group_it->first.dialog_id, notification);
return;
}
}
}
for (auto &notification : group.pending_notifications) {
if (notification.notification_id == notification_id) {
notification.type = std::move(type);
}
}
CHECK(notification_id.is_valid());
}
void NotificationManager::remove_notification(NotificationId notification_id, Promise<Unit> &&promise) {
void NotificationManager::remove_notification(NotificationGroupId group_id, NotificationId notification_id,
Promise<Unit> &&promise) {
if (!notification_id.is_valid()) {
return promise.set_error(Status::Error(400, "Notification identifier is invalid"));
}
@ -390,6 +416,10 @@ void NotificationManager::remove_notification(NotificationId notification_id, Pr
return promise.set_value(Unit());
}
VLOG(notifications) << "Remove " << notification_id;
// TODO remove notification from database by notification_id
// TODO update total_count
promise.set_value(Unit());
}
@ -407,6 +437,8 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
return promise.set_value(Unit());
}
VLOG(notifications) << "Remove " << group_id << " up to " << max_notification_id;
// TODO update total_count
promise.set_value(Unit());
}

View File

@ -44,11 +44,10 @@ class NotificationManager : public Actor {
DialogId notification_settings_dialog_id, bool is_silent, NotificationId notification_id,
unique_ptr<NotificationType> type);
void edit_notification(NotificationId notification_id, unique_ptr<NotificationType> type);
void edit_notification(NotificationGroupId group_id, NotificationId notification_id,
unique_ptr<NotificationType> type);
void delete_notification(NotificationId notification_id);
void remove_notification(NotificationId notification_id, Promise<Unit> &&promise);
void remove_notification(NotificationGroupId group_id, NotificationId notification_id, Promise<Unit> &&promise);
void remove_notification_group(NotificationGroupId group_id, NotificationId max_notification_id,
Promise<Unit> &&promise);
@ -134,6 +133,9 @@ class NotificationManager : public Actor {
void send_update_notification_group(td_api::object_ptr<td_api::updateNotificationGroup> update);
void send_update_notification(NotificationGroupId notification_group_id, DialogId dialog_id,
const Notification &notification);
NotificationGroups::iterator get_group(NotificationGroupId group_id);
NotificationGroupKey get_last_updated_group_key() const;

View File

@ -5085,7 +5085,8 @@ void Td::on_request(uint64 id, td_api::getChatMessageCount &request) {
void Td::on_request(uint64 id, const td_api::removeNotification &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
notification_manager_->remove_notification(NotificationId(request.notification_id_), std::move(promise));
notification_manager_->remove_notification(NotificationGroupId(request.notification_group_id_),
NotificationId(request.notification_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::removeNotificationGroup &request) {

View File

@ -3293,8 +3293,11 @@ class CliClient final : public Actor {
} else if (op == "rans") {
send_request(make_tl_object<td_api::resetAllNotificationSettings>());
} else if (op == "rn") {
string notification_id = args;
send_request(make_tl_object<td_api::removeNotification>(to_integer<int32>(notification_id)));
string group_id;
string notification_id;
std::tie(group_id, notification_id) = split(args);
send_request(
make_tl_object<td_api::removeNotification>(to_integer<int32>(group_id), to_integer<int32>(notification_id)));
} else if (op == "rng") {
string group_id;
string max_notification_id;