2023-08-21 17:52:56 +02:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2023-08-21 18:28:05 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
2023-08-21 17:52:56 +02:00
|
|
|
#include "td/telegram/NotificationGroupId.h"
|
2023-08-21 18:28:05 +02:00
|
|
|
#include "td/telegram/NotificationGroupKey.h"
|
2023-08-21 17:52:56 +02:00
|
|
|
#include "td/telegram/NotificationId.h"
|
2023-08-25 23:48:57 +02:00
|
|
|
#include "td/telegram/NotificationObjectId.h"
|
2023-08-21 17:52:56 +02:00
|
|
|
|
2023-08-22 18:10:22 +02:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
|
2023-08-21 17:52:56 +02:00
|
|
|
namespace td {
|
|
|
|
|
2023-08-21 18:28:05 +02:00
|
|
|
class NotificationGroupInfo {
|
2023-08-21 23:01:29 +02:00
|
|
|
NotificationGroupId group_id_;
|
2023-08-21 21:21:06 +02:00
|
|
|
int32 last_notification_date_ = 0; // date of the last notification in the group
|
2023-08-21 23:01:29 +02:00
|
|
|
NotificationId last_notification_id_; // identifier of the last notification in the group
|
2023-08-21 21:13:19 +02:00
|
|
|
NotificationId max_removed_notification_id_; // notification identifier, up to which all notifications are removed
|
2023-08-25 23:48:57 +02:00
|
|
|
NotificationObjectId max_removed_object_id_; // object identifier, up to which all notifications are removed
|
2023-08-21 21:16:42 +02:00
|
|
|
bool is_key_changed_ = false; // true, if the group needs to be saved to database
|
|
|
|
bool try_reuse_ = false; // true, if the group needs to be deleted from database and tried to be reused
|
2023-08-21 20:43:26 +02:00
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const NotificationGroupInfo &group_info);
|
2023-08-21 18:28:05 +02:00
|
|
|
|
|
|
|
public:
|
2023-08-21 18:54:12 +02:00
|
|
|
NotificationGroupInfo() = default;
|
|
|
|
|
2023-08-21 21:16:42 +02:00
|
|
|
explicit NotificationGroupInfo(NotificationGroupId group_id) : group_id_(group_id), is_key_changed_(true) {
|
2023-08-21 18:54:12 +02:00
|
|
|
}
|
|
|
|
|
2023-08-21 22:03:55 +02:00
|
|
|
bool is_valid() const {
|
|
|
|
return group_id_.is_valid();
|
|
|
|
}
|
|
|
|
|
2023-08-21 18:28:05 +02:00
|
|
|
bool is_active() const {
|
2023-08-21 22:03:55 +02:00
|
|
|
return is_valid() && !try_reuse_;
|
2023-08-21 18:28:05 +02:00
|
|
|
}
|
|
|
|
|
2023-08-21 23:01:29 +02:00
|
|
|
NotificationGroupId get_group_id() const {
|
|
|
|
return group_id_;
|
|
|
|
}
|
|
|
|
|
2023-08-22 01:34:26 +02:00
|
|
|
bool has_group_id(NotificationGroupId group_id) const {
|
|
|
|
return group_id_ == group_id;
|
|
|
|
}
|
|
|
|
|
2023-08-21 23:01:29 +02:00
|
|
|
NotificationId get_last_notification_id() const {
|
|
|
|
return last_notification_id_;
|
|
|
|
}
|
|
|
|
|
2023-08-21 18:46:09 +02:00
|
|
|
bool set_last_notification(int32 last_notification_date, NotificationId last_notification_id, const char *source);
|
|
|
|
|
2023-08-25 23:48:57 +02:00
|
|
|
bool set_max_removed_notification_id(NotificationId max_removed_notification_id,
|
|
|
|
NotificationObjectId max_removed_object_id, const char *source);
|
2023-08-21 19:12:30 +02:00
|
|
|
|
|
|
|
void drop_max_removed_notification_id();
|
|
|
|
|
2023-08-25 23:48:57 +02:00
|
|
|
bool is_removed_notification(NotificationId notification_id, NotificationObjectId object_id) const;
|
2023-08-21 20:37:52 +02:00
|
|
|
|
2023-08-21 20:43:26 +02:00
|
|
|
bool is_removed_notification_id(NotificationId notification_id) const;
|
|
|
|
|
2023-08-25 23:48:57 +02:00
|
|
|
bool is_removed_object_id(NotificationObjectId object_id) const;
|
2023-08-21 20:43:26 +02:00
|
|
|
|
2023-08-21 20:37:52 +02:00
|
|
|
bool is_used_notification_id(NotificationId notification_id) const;
|
|
|
|
|
2023-08-21 18:28:05 +02:00
|
|
|
void try_reuse();
|
|
|
|
|
|
|
|
void add_group_key_if_changed(vector<NotificationGroupKey> &group_keys, DialogId dialog_id);
|
|
|
|
|
|
|
|
NotificationGroupId get_reused_group_id();
|
2023-08-21 17:52:56 +02:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
|
|
|
};
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const NotificationGroupInfo &group_info);
|
|
|
|
|
|
|
|
} // namespace td
|