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)
|
|
|
|
//
|
|
|
|
#include "td/telegram/NotificationGroupInfo.h"
|
|
|
|
|
2023-08-21 18:28:05 +02:00
|
|
|
#include "td/utils/logging.h"
|
|
|
|
|
2023-08-21 17:52:56 +02:00
|
|
|
namespace td {
|
|
|
|
|
2023-08-21 18:28:05 +02:00
|
|
|
void NotificationGroupInfo::try_reuse() {
|
2023-08-21 18:36:43 +02:00
|
|
|
CHECK(group_id_.is_valid());
|
|
|
|
CHECK(last_notification_date_ == 0);
|
2023-08-21 18:28:05 +02:00
|
|
|
if (!try_reuse_) {
|
|
|
|
try_reuse_ = true;
|
2023-08-21 18:36:43 +02:00
|
|
|
is_changed_ = true;
|
2023-08-21 18:28:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotificationGroupInfo::add_group_key_if_changed(vector<NotificationGroupKey> &group_keys, DialogId dialog_id) {
|
2023-08-21 18:36:43 +02:00
|
|
|
if (!is_changed_) {
|
2023-08-21 18:28:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-08-21 18:36:43 +02:00
|
|
|
is_changed_ = false;
|
2023-08-21 18:28:05 +02:00
|
|
|
|
2023-08-21 18:36:43 +02:00
|
|
|
group_keys.emplace_back(group_id_, try_reuse_ ? DialogId() : dialog_id, last_notification_date_);
|
2023-08-21 18:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NotificationGroupId NotificationGroupInfo::get_reused_group_id() {
|
|
|
|
if (!try_reuse_) {
|
|
|
|
return {};
|
|
|
|
}
|
2023-08-21 18:36:43 +02:00
|
|
|
if (is_changed_) {
|
|
|
|
LOG(ERROR) << "Failed to reuse changed " << group_id_;
|
2023-08-21 18:28:05 +02:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
try_reuse_ = false;
|
2023-08-21 18:36:43 +02:00
|
|
|
if (!group_id_.is_valid()) {
|
|
|
|
LOG(ERROR) << "Failed to reuse invalid " << group_id_;
|
2023-08-21 18:28:05 +02:00
|
|
|
return {};
|
|
|
|
}
|
2023-08-21 18:36:43 +02:00
|
|
|
CHECK(last_notification_id_ == NotificationId());
|
|
|
|
CHECK(last_notification_date_ == 0);
|
|
|
|
auto result = group_id_;
|
|
|
|
group_id_ = NotificationGroupId();
|
|
|
|
max_removed_notification_id_ = NotificationId();
|
|
|
|
max_removed_message_id_ = MessageId();
|
2023-08-21 18:28:05 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-08-21 17:52:56 +02:00
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const NotificationGroupInfo &group_info) {
|
2023-08-21 18:36:43 +02:00
|
|
|
return string_builder << group_info.group_id_ << " with last " << group_info.last_notification_id_ << " sent at "
|
|
|
|
<< group_info.last_notification_date_ << ", max removed "
|
|
|
|
<< group_info.max_removed_notification_id_ << '/' << group_info.max_removed_message_id_;
|
2023-08-21 17:52:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|