Add scheduled-safe MessageId comparison operators.
GitOrigin-RevId: edc6481519510a425bcf3f08bb46eaac1c923ee4
This commit is contained in:
parent
0c77eb2745
commit
3b1ab2ff8f
@ -138,6 +138,23 @@ class MessageId {
|
||||
return id != other.id;
|
||||
}
|
||||
|
||||
friend bool operator<(const MessageId &lhs, const MessageId &rhs) {
|
||||
CHECK(lhs.is_scheduled() == rhs.is_scheduled());
|
||||
return lhs.id < rhs.id;
|
||||
}
|
||||
|
||||
friend bool operator>(const MessageId &lhs, const MessageId &rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
friend bool operator<=(const MessageId &lhs, const MessageId &rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
friend bool operator>=(const MessageId &lhs, const MessageId &rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const {
|
||||
storer.store_long(id);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1216,7 +1216,7 @@ class MessagesManager : public Actor {
|
||||
while (root != nullptr) {
|
||||
// LOG(DEBUG) << "Have root->message_id = " << root->message_id;
|
||||
stack_.push_back(root);
|
||||
if (root->message_id.get() <= message_id.get()) {
|
||||
if (root->message_id <= message_id) {
|
||||
// LOG(DEBUG) << "Go right";
|
||||
last_right_pos = stack_.size();
|
||||
root = root->right.get();
|
||||
|
@ -598,7 +598,7 @@ void NotificationManager::on_get_message_notifications_from_database(Notificatio
|
||||
}
|
||||
auto first_message_id = get_first_message_id(group);
|
||||
if (first_message_id.is_valid()) {
|
||||
while (!notifications.empty() && notifications.back().type->get_message_id().get() >= first_message_id.get()) {
|
||||
while (!notifications.empty() && notifications.back().type->get_message_id() >= first_message_id) {
|
||||
// possible if notifications was added after the database request was sent
|
||||
notifications.pop_back();
|
||||
}
|
||||
@ -880,7 +880,7 @@ void NotificationManager::add_notification(NotificationGroupId group_id, Notific
|
||||
return;
|
||||
}
|
||||
auto message_id = type->get_message_id();
|
||||
if (message_id.is_valid() && message_id.get() <= get_last_message_id(group).get()) {
|
||||
if (message_id.is_valid() && message_id <= get_last_message_id(group)) {
|
||||
LOG(ERROR) << "Failed to add " << notification_id << " of type " << *type << " to " << group_id << " of type "
|
||||
<< group_type << " in " << dialog_id << ", because have already added notification about "
|
||||
<< get_last_message_id(group);
|
||||
@ -1961,7 +1961,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
|
||||
for (auto it = group_it->second.pending_notifications.begin(); it != group_it->second.pending_notifications.end();
|
||||
++it) {
|
||||
if (it->notification_id.get() <= max_notification_id.get() ||
|
||||
(max_message_id.is_valid() && it->type->get_message_id().get() <= max_message_id.get())) {
|
||||
(max_message_id.is_valid() && it->type->get_message_id() <= max_message_id)) {
|
||||
pending_delete_end = it + 1;
|
||||
on_notification_removed(it->notification_id);
|
||||
}
|
||||
@ -1988,7 +1988,7 @@ void NotificationManager::remove_notification_group(NotificationGroupId group_id
|
||||
for (size_t pos = 0; pos < notification_delete_end; pos++) {
|
||||
auto ¬ification = group_it->second.notifications[pos];
|
||||
if (notification.notification_id.get() > max_notification_id.get() &&
|
||||
(!max_message_id.is_valid() || notification.type->get_message_id().get() > max_message_id.get())) {
|
||||
(!max_message_id.is_valid() || notification.type->get_message_id() > max_message_id)) {
|
||||
notification_delete_end = pos;
|
||||
} else {
|
||||
on_notification_removed(notification.notification_id);
|
||||
|
Loading…
Reference in New Issue
Block a user