Add add_group/delete_group methods.

GitOrigin-RevId: 71539381c1b3600bc18b8c79c6cdb63ffff1cb0f
This commit is contained in:
levlam 2018-12-02 23:03:05 +03:00
parent 7466a29da7
commit 7ce70d8056
3 changed files with 19 additions and 9 deletions

View File

@ -17785,11 +17785,10 @@ int32 MessagesManager::get_dialog_pending_notification_count(Dialog *d) {
CHECK(d != nullptr); CHECK(d != nullptr);
if (is_dialog_muted(d)) { if (is_dialog_muted(d)) {
// TODO pinned message? // TODO pinned message?
// TODO hidden notifications?
return d->unread_mention_count; return d->unread_mention_count;
} }
return d->server_unread_count + d->local_unread_count; // TODO remove/add some messages with unread mentions return d->server_unread_count + d->local_unread_count; // TODO remove/add messages with unread mentions
} }
bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool force) { bool MessagesManager::add_new_message_notification(Dialog *d, Message *m, bool force) {

View File

@ -154,6 +154,11 @@ void NotificationManager::tear_down() {
parent_.reset(); parent_.reset();
} }
NotificationManager::NotificationGroups::iterator NotificationManager::add_group(NotificationGroupKey &&group_key,
NotificationGroup &&group) {
return groups_.emplace(std::move(group_key), std::move(group)).first;
}
NotificationManager::NotificationGroups::iterator NotificationManager::get_group(NotificationGroupId group_id) { NotificationManager::NotificationGroups::iterator NotificationManager::get_group(NotificationGroupId group_id) {
// TODO optimize // TODO optimize
for (auto it = groups_.begin(); it != groups_.end(); ++it) { for (auto it = groups_.begin(); it != groups_.end(); ++it) {
@ -198,8 +203,11 @@ NotificationManager::NotificationGroups::iterator NotificationManager::get_group
<< " and notifications " << group.notifications; << " and notifications " << group.notifications;
// TODO send update about the new group, if needed // TODO send update about the new group, if needed
return add_group(std::move(group_key), std::move(group));
}
return groups_.emplace(std::move(group_key), std::move(group)).first; void NotificationManager::delete_group(NotificationGroups::iterator &&group_it) {
groups_.erase(group_it);
} }
int32 NotificationManager::load_message_notification_groups_from_database(int32 limit, bool send_update) { int32 NotificationManager::load_message_notification_groups_from_database(int32 limit, bool send_update) {
@ -331,8 +339,7 @@ void NotificationManager::add_notification(NotificationGroupId group_id, DialogI
auto group_it = get_group_force(group_id); auto group_it = get_group_force(group_id);
if (group_it == groups_.end()) { if (group_it == groups_.end()) {
NotificationGroupKey group_key(group_id, dialog_id, 0); group_it = add_group(NotificationGroupKey(group_id, dialog_id, 0), NotificationGroup());
group_it = std::move(groups_.emplace(group_key, NotificationGroup()).first);
} }
PendingNotification notification; PendingNotification notification;
@ -857,7 +864,7 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_
auto group_key = group_it->first; auto group_key = group_it->first;
auto group = std::move(group_it->second); auto group = std::move(group_it->second);
groups_.erase(group_it); delete_group(std::move(group_it));
auto final_group_key = group_key; auto final_group_key = group_key;
for (auto &pending_notification : group.pending_notifications) { for (auto &pending_notification : group.pending_notifications) {
@ -919,7 +926,7 @@ void NotificationManager::flush_pending_notifications(NotificationGroupId group_
group.notifications.begin() + (group.notifications.size() - keep_notification_group_size_)); group.notifications.begin() + (group.notifications.size() - keep_notification_group_size_));
} }
groups_.emplace(std::move(final_group_key), std::move(group)); add_group(std::move(final_group_key), std::move(group));
} }
void NotificationManager::flush_all_pending_notifications() { void NotificationManager::flush_all_pending_notifications() {
@ -990,7 +997,7 @@ void NotificationManager::on_notifications_removed(
NotificationGroup group = std::move(group_it->second); NotificationGroup group = std::move(group_it->second);
if (is_position_changed) { if (is_position_changed) {
VLOG(notifications) << "Position of notification group is changed from " << group_key << " to " << final_group_key; VLOG(notifications) << "Position of notification group is changed from " << group_key << " to " << final_group_key;
groups_.erase(group_it); delete_group(std::move(group_it));
} }
auto last_group_key = get_last_updated_group_key(); auto last_group_key = get_last_updated_group_key();
@ -1023,7 +1030,7 @@ void NotificationManager::on_notifications_removed(
} }
if (is_position_changed) { if (is_position_changed) {
groups_.emplace(std::move(final_group_key), std::move(group)); add_group(std::move(final_group_key), std::move(group));
last_group_key = get_last_updated_group_key(); last_group_key = get_last_updated_group_key();
} else { } else {

View File

@ -130,10 +130,14 @@ class NotificationManager : public Actor {
void add_update_notification(NotificationGroupId notification_group_id, DialogId dialog_id, void add_update_notification(NotificationGroupId notification_group_id, DialogId dialog_id,
const Notification &notification); const Notification &notification);
NotificationGroups::iterator add_group(NotificationGroupKey &&group_key, NotificationGroup &&group);
NotificationGroups::iterator get_group(NotificationGroupId group_id); NotificationGroups::iterator get_group(NotificationGroupId group_id);
NotificationGroups::iterator get_group_force(NotificationGroupId group_id, bool send_update = true); NotificationGroups::iterator get_group_force(NotificationGroupId group_id, bool send_update = true);
void delete_group(NotificationGroups::iterator &&group_it);
int32 load_message_notification_groups_from_database(int32 limit, bool send_update); int32 load_message_notification_groups_from_database(int32 limit, bool send_update);
NotificationGroupKey get_last_updated_group_key() const; NotificationGroupKey get_last_updated_group_key() const;