Add NotificationObjectFullId class.

This commit is contained in:
levlam 2023-08-26 03:13:39 +03:00
parent 989dc3d8a6
commit f7887181c4
4 changed files with 71 additions and 9 deletions

View File

@ -723,6 +723,7 @@ set(TDLIB_SOURCE
td/telegram/NotificationGroupType.h
td/telegram/NotificationId.h
td/telegram/NotificationManager.h
td/telegram/NotificationObjectFullId.h
td/telegram/NotificationObjectId.h
td/telegram/NotificationSettingsScope.h
td/telegram/NotificationSettingsManager.h

View File

@ -1729,8 +1729,8 @@ void NotificationManager::on_notification_removed(NotificationId notification_id
}
temporary_notification_log_event_ids_.erase(add_it);
auto erased_notification_count = temporary_notifications_.erase(temporary_notification_message_ids_[notification_id]);
auto erased_message_id_count = temporary_notification_message_ids_.erase(notification_id);
auto erased_notification_count = temporary_notifications_.erase(temporary_notification_object_ids_[notification_id]);
auto erased_message_id_count = temporary_notification_object_ids_.erase(notification_id);
CHECK(erased_notification_count > 0);
CHECK(erased_message_id_count > 0);
@ -3849,10 +3849,11 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess
sender_user_id.is_valid() ? td_->contacts_manager_->get_my_id() == sender_user_id : is_from_scheduled;
if (log_event_id != 0) {
VLOG(notifications) << "Register temporary " << notification_id << " with log event " << log_event_id;
NotificationObjectFullId object_full_id(dialog_id, message_id);
temporary_notification_log_event_ids_[notification_id] = log_event_id;
temporary_notifications_[FullMessageId(dialog_id, message_id)] = {group_id, notification_id, sender_user_id,
sender_dialog_id, sender_name, is_outgoing};
temporary_notification_message_ids_[notification_id] = FullMessageId(dialog_id, message_id);
temporary_notifications_[object_full_id] = {group_id, notification_id, sender_user_id,
sender_dialog_id, sender_name, is_outgoing};
temporary_notification_object_ids_[notification_id] = object_full_id;
}
push_notification_promises_[notification_id].push_back(std::move(promise));
@ -3948,7 +3949,7 @@ void NotificationManager::edit_message_push_notification(DialogId dialog_id, Mes
return promise.set_error(Status::Error(200, "Immediate success"));
}
auto it = temporary_notifications_.find(FullMessageId(dialog_id, message_id));
auto it = temporary_notifications_.find({dialog_id, message_id});
if (it == temporary_notifications_.end()) {
VLOG(notifications) << "Ignore edit of message push notification for " << message_id << " in " << dialog_id
<< " edited at " << edit_date;

View File

@ -9,13 +9,13 @@
#include "td/telegram/CallId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/Document.h"
#include "td/telegram/FullMessageId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/Notification.h"
#include "td/telegram/NotificationGroupId.h"
#include "td/telegram/NotificationGroupKey.h"
#include "td/telegram/NotificationGroupType.h"
#include "td/telegram/NotificationId.h"
#include "td/telegram/NotificationObjectFullId.h"
#include "td/telegram/NotificationObjectId.h"
#include "td/telegram/NotificationType.h"
#include "td/telegram/Photo.h"
@ -401,8 +401,8 @@ class NotificationManager final : public Actor {
string sender_name;
bool is_outgoing;
};
FlatHashMap<FullMessageId, TemporaryNotification, FullMessageIdHash> temporary_notifications_;
FlatHashMap<NotificationId, FullMessageId, NotificationIdHash> temporary_notification_message_ids_;
FlatHashMap<NotificationObjectFullId, TemporaryNotification, NotificationObjectFullIdHash> temporary_notifications_;
FlatHashMap<NotificationId, NotificationObjectFullId, NotificationIdHash> temporary_notification_object_ids_;
FlatHashMap<NotificationId, vector<Promise<Unit>>, NotificationIdHash> push_notification_promises_;
struct ActiveCallNotification {

View File

@ -0,0 +1,60 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/NotificationObjectId.h"
#include "td/utils/common.h"
#include "td/utils/HashTableUtils.h"
#include "td/utils/StringBuilder.h"
namespace td {
struct NotificationObjectFullId {
private:
DialogId dialog_id;
NotificationObjectId notification_object_id;
public:
NotificationObjectFullId() : dialog_id(), notification_object_id() {
}
NotificationObjectFullId(DialogId dialog_id, NotificationObjectId notification_object_id)
: dialog_id(dialog_id), notification_object_id(notification_object_id) {
}
bool operator==(const NotificationObjectFullId &other) const {
return dialog_id == other.dialog_id && notification_object_id == other.notification_object_id;
}
bool operator!=(const NotificationObjectFullId &other) const {
return !(*this == other);
}
DialogId get_dialog_id() const {
return dialog_id;
}
NotificationObjectId get_notification_object_id() const {
return notification_object_id;
}
};
struct NotificationObjectFullIdHash {
uint32 operator()(NotificationObjectFullId full_notification_object_id) const {
return combine_hashes(DialogIdHash()(full_notification_object_id.get_dialog_id()),
NotificationObjectIdHash()(full_notification_object_id.get_notification_object_id()));
}
};
inline StringBuilder &operator<<(StringBuilder &string_builder, NotificationObjectFullId full_notification_object_id) {
return string_builder << full_notification_object_id.get_notification_object_id() << " in "
<< full_notification_object_id.get_dialog_id();
}
} // namespace td