Add more logic to OrderedMessages::insert.
This commit is contained in:
parent
b8cd0bb597
commit
85aedaa8c0
@ -34906,28 +34906,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
|
||||
}
|
||||
|
||||
if (!is_attached && !have_next && !have_previous) {
|
||||
auto it = d->ordered_messages.get_iterator(m->message_id);
|
||||
if (*it != nullptr && (*it)->have_next_) {
|
||||
// need to drop a connection between messages
|
||||
auto previous_message = *it;
|
||||
++it;
|
||||
auto next_message = *it;
|
||||
if (next_message != nullptr) {
|
||||
if (next_message->get_message_id().is_server() &&
|
||||
!(td_->auth_manager_->is_bot() && Slice(source) == Slice("GetRepliedChannelMessageQuery"))) {
|
||||
LOG(ERROR) << "Can't attach " << m->message_id << " of type " << m->content->get_type() << " from " << source
|
||||
<< " from " << (m->from_database ? "database" : "server") << " before "
|
||||
<< next_message->get_message_id() << " and after " << previous_message->get_message_id() << " in "
|
||||
<< dialog_id;
|
||||
}
|
||||
|
||||
next_message->have_previous_ = false;
|
||||
previous_message->have_next_ = false;
|
||||
} else {
|
||||
LOG(ERROR) << "Have_next is true, but there is no next message after " << previous_message->get_message_id()
|
||||
<< " from " << source << " in " << dialog_id;
|
||||
}
|
||||
} else if (m->message_id.is_server() && d->last_message_id.is_valid() && m->message_id > d->last_message_id) {
|
||||
if (m->message_id.is_server() && d->last_message_id.is_valid() && m->message_id > d->last_message_id) {
|
||||
LOG(INFO) << "Receive " << m->message_id << ", which is newer than the last " << d->last_message_id
|
||||
<< " not from update";
|
||||
set_dialog_last_message_id(d, MessageId(), source);
|
||||
|
@ -11,6 +11,22 @@
|
||||
namespace td {
|
||||
|
||||
void OrderedMessages::insert(MessageId message_id, bool was_auto_attached, bool have_previous, bool have_next) {
|
||||
if (!was_auto_attached && !have_previous && !have_next) {
|
||||
auto it = get_iterator(message_id);
|
||||
if (*it != nullptr && (*it)->have_next_) {
|
||||
// need to drop a connection between messages
|
||||
auto previous_message = *it;
|
||||
CHECK(previous_message->message_id_ < message_id);
|
||||
++it;
|
||||
auto next_message = *it;
|
||||
CHECK(next_message != nullptr);
|
||||
CHECK(next_message->message_id_ > message_id);
|
||||
|
||||
next_message->have_previous_ = false;
|
||||
previous_message->have_next_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
auto random_y = static_cast<int32>(static_cast<uint32>(message_id.get() * 2101234567u));
|
||||
unique_ptr<OrderedMessage> *v = &messages_;
|
||||
while (*v != nullptr && (*v)->random_y_ >= random_y) {
|
||||
@ -73,7 +89,7 @@ void OrderedMessages::erase(MessageId message_id, bool only_from_memory) {
|
||||
|
||||
CHECK(*v != nullptr);
|
||||
if ((*v)->have_previous_ && (only_from_memory || !(*v)->have_next_)) {
|
||||
Iterator it(messages_.get(), message_id);
|
||||
auto it = get_iterator(message_id);
|
||||
CHECK(*it == v->get());
|
||||
--it;
|
||||
OrderedMessage *prev_m = *it;
|
||||
@ -81,7 +97,7 @@ void OrderedMessages::erase(MessageId message_id, bool only_from_memory) {
|
||||
prev_m->have_next_ = false;
|
||||
}
|
||||
if ((*v)->have_next_ && (only_from_memory || !(*v)->have_previous_)) {
|
||||
Iterator it(messages_.get(), message_id);
|
||||
auto it = get_iterator(message_id);
|
||||
CHECK(*it == v->get());
|
||||
++it;
|
||||
OrderedMessage *next_m = *it;
|
||||
|
Loading…
Reference in New Issue
Block a user