Notifications fixes and improvements.
GitOrigin-RevId: be1ebd6df5f003207ed450d867772286ebcbea27
This commit is contained in:
parent
25225d5c4b
commit
254007eab8
@ -9867,7 +9867,7 @@ void MessagesManager::try_restore_dialog_reply_markup(Dialog *d, const Message *
|
||||
bool MessagesManager::set_dialog_last_notification(Dialog *d, int32 last_notification_date,
|
||||
NotificationId last_notification_id, const char *source) {
|
||||
if (last_notification_date != d->last_notification_date || d->last_notification_id != last_notification_id) {
|
||||
VLOG(notifications) << "Set dialog last notification to " << last_notification_id << " sent at "
|
||||
VLOG(notifications) << "Set " << d->dialog_id << " last notification to " << last_notification_id << " sent at "
|
||||
<< last_notification_date << " from " << source;
|
||||
d->last_notification_date = last_notification_date;
|
||||
d->last_notification_id = last_notification_id;
|
||||
@ -10405,6 +10405,7 @@ void MessagesManager::fix_dialog_last_notification_id(Dialog *d, MessageId messa
|
||||
}
|
||||
}
|
||||
if (G()->parameters().use_message_db) {
|
||||
VLOG(notifications) << "Get message notification in " << d->dialog_id << " from " << d->last_notification_id;
|
||||
G()->td_db()->get_messages_db_async()->get_messages_from_notification_id(
|
||||
d->dialog_id, d->last_notification_id, 1,
|
||||
PromiseCreator::lambda(
|
||||
@ -10422,6 +10423,7 @@ void MessagesManager::do_fix_dialog_last_notification_id(DialogId dialog_id, Not
|
||||
return;
|
||||
}
|
||||
|
||||
VLOG(notifications) << "Receive " << result.ok().size() << " messages with notifications in " << dialog_id;
|
||||
Dialog *d = get_dialog(dialog_id);
|
||||
CHECK(d != nullptr);
|
||||
if (d->last_notification_id != prev_last_notification_id) {
|
||||
@ -10436,6 +10438,7 @@ void MessagesManager::do_fix_dialog_last_notification_id(DialogId dialog_id, Not
|
||||
NotificationId last_notification_id;
|
||||
for (auto &message : messages) {
|
||||
auto m = on_get_message_from_database(dialog_id, d, std::move(message));
|
||||
VLOG(notifications) << "Receive " << m->message_id << " with " << m->notification_id << " in " << dialog_id;
|
||||
if (is_message_has_active_notification(d, m)) {
|
||||
last_notification_date = m->date;
|
||||
last_notification_id = m->notification_id;
|
||||
|
@ -670,6 +670,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour
|
||||
// all other additions and edits can be merged to the first addition/edit
|
||||
// i.e. in edit+delete+add chain we want to remove deletion and merge addition to the edit
|
||||
|
||||
bool is_hidden = get_last_updated_group_key() < group_keys_[NotificationGroupId(group_id)];
|
||||
bool is_changed = true;
|
||||
while (is_changed) {
|
||||
is_changed = false;
|
||||
@ -796,7 +797,7 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (update != nullptr && cur_pos == 1 && (updates.size() > 1 || update_ptr->total_count_ == 0)) {
|
||||
if (update != nullptr && cur_pos == 1 && (updates.size() > 1 || update_ptr->total_count_ == 0 || is_hidden)) {
|
||||
VLOG(notifications) << "Remove empty update " << cur_pos;
|
||||
CHECK(moved_deleted_notification_ids.empty());
|
||||
is_changed = true;
|
||||
@ -876,6 +877,16 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour
|
||||
return;
|
||||
}
|
||||
|
||||
auto has_common_notifications = [](const vector<td_api::object_ptr<td_api::notification>> ¬ifications,
|
||||
const vector<int32> ¬ification_ids) {
|
||||
for (auto ¬ification : notifications) {
|
||||
if (std::find(notification_ids.begin(), notification_ids.end(), notification->id_) != notification_ids.end()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
size_t last_update_pos = 0;
|
||||
for (size_t i = 1; i < updates.size(); i++) {
|
||||
if (updates[last_update_pos]->get_id() == td_api::updateNotificationGroup::ID &&
|
||||
@ -883,21 +894,20 @@ void NotificationManager::flush_pending_updates(int32 group_id, const char *sour
|
||||
auto last_update_ptr = static_cast<td_api::updateNotificationGroup *>(updates[last_update_pos].get());
|
||||
auto update_ptr = static_cast<td_api::updateNotificationGroup *>(updates[i].get());
|
||||
if (last_update_ptr->notification_settings_chat_id_ == update_ptr->notification_settings_chat_id_ &&
|
||||
last_update_ptr->is_silent_ == update_ptr->is_silent_) {
|
||||
if ((last_update_ptr->added_notifications_.empty() && update_ptr->added_notifications_.empty()) ||
|
||||
(last_update_ptr->removed_notification_ids_.empty() && update_ptr->removed_notification_ids_.empty())) {
|
||||
// combine updates
|
||||
VLOG(notifications) << "Combine " << as_notification_update(last_update_ptr) << " and "
|
||||
<< as_notification_update(update_ptr);
|
||||
CHECK(last_update_ptr->notification_group_id_ == update_ptr->notification_group_id_);
|
||||
CHECK(last_update_ptr->chat_id_ == update_ptr->chat_id_);
|
||||
last_update_ptr->total_count_ = update_ptr->total_count_;
|
||||
append(last_update_ptr->added_notifications_, std::move(update_ptr->added_notifications_));
|
||||
append(last_update_ptr->removed_notification_ids_, std::move(update_ptr->removed_notification_ids_));
|
||||
updates[i] = nullptr;
|
||||
is_changed = true;
|
||||
continue;
|
||||
}
|
||||
(!last_update_ptr->is_silent_ || update_ptr->is_silent_) &&
|
||||
!has_common_notifications(last_update_ptr->added_notifications_, update_ptr->removed_notification_ids_) &&
|
||||
!has_common_notifications(update_ptr->added_notifications_, last_update_ptr->removed_notification_ids_)) {
|
||||
// combine updates
|
||||
VLOG(notifications) << "Combine " << as_notification_update(last_update_ptr) << " and "
|
||||
<< as_notification_update(update_ptr);
|
||||
CHECK(last_update_ptr->notification_group_id_ == update_ptr->notification_group_id_);
|
||||
CHECK(last_update_ptr->chat_id_ == update_ptr->chat_id_);
|
||||
last_update_ptr->total_count_ = update_ptr->total_count_;
|
||||
append(last_update_ptr->added_notifications_, std::move(update_ptr->added_notifications_));
|
||||
append(last_update_ptr->removed_notification_ids_, std::move(update_ptr->removed_notification_ids_));
|
||||
updates[i] = nullptr;
|
||||
is_changed = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
last_update_pos++;
|
||||
|
@ -545,7 +545,7 @@ class CliClient final : public Actor {
|
||||
|
||||
template <class T>
|
||||
static vector<T> to_integers(Slice ids_string, char delimiter = ' ') {
|
||||
return transform(full_split(ids_string, delimiter), to_integer<T>);
|
||||
return transform(transform(full_split(ids_string, delimiter), trim<Slice>), to_integer<T>);
|
||||
}
|
||||
|
||||
void on_result(uint64 generation, uint64 id, tl_object_ptr<td_api::Object> result) {
|
||||
@ -3294,10 +3294,12 @@ class CliClient final : public Actor {
|
||||
send_request(make_tl_object<td_api::resetAllNotificationSettings>());
|
||||
} else if (op == "rn") {
|
||||
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)));
|
||||
string notification_ids;
|
||||
std::tie(group_id, notification_ids) = split(args);
|
||||
char delimiter = notification_ids.find(',') != string::npos ? ',' : ' ';
|
||||
for (auto notification_id : to_integers<int32>(notification_ids, delimiter)) {
|
||||
send_request(make_tl_object<td_api::removeNotification>(to_integer<int32>(group_id), notification_id));
|
||||
}
|
||||
} else if (op == "rng") {
|
||||
string group_id;
|
||||
string max_notification_id;
|
||||
|
Reference in New Issue
Block a user