Try to fix duplicate messages in certain edge cases (i.e. sync and pagination at the same time)
This commit is contained in:
parent
f260b8b4ae
commit
4efac5a247
@ -324,10 +324,16 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
|
|||||||
QString id =
|
QString id =
|
||||||
boost::apply_visitor([](const auto &e) -> QString { return eventId(e); }, e);
|
boost::apply_visitor([](const auto &e) -> QString { return eventId(e); }, e);
|
||||||
|
|
||||||
|
if (this->events.contains(id))
|
||||||
|
continue;
|
||||||
|
|
||||||
this->events.insert(id, e);
|
this->events.insert(id, e);
|
||||||
ids.push_back(id);
|
ids.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ids.empty)
|
||||||
|
return;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(),
|
beginInsertRows(QModelIndex(),
|
||||||
static_cast<int>(this->eventOrder.size()),
|
static_cast<int>(this->eventOrder.size()),
|
||||||
static_cast<int>(this->eventOrder.size() + ids.size() - 1));
|
static_cast<int>(this->eventOrder.size() + ids.size() - 1));
|
||||||
@ -372,13 +378,18 @@ TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs)
|
|||||||
QString id =
|
QString id =
|
||||||
boost::apply_visitor([](const auto &e) -> QString { return eventId(e); }, e);
|
boost::apply_visitor([](const auto &e) -> QString { return eventId(e); }, e);
|
||||||
|
|
||||||
|
if (this->events.contains(id))
|
||||||
|
continue;
|
||||||
|
|
||||||
this->events.insert(id, e);
|
this->events.insert(id, e);
|
||||||
ids.push_back(id);
|
ids.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), 0, static_cast<int>(ids.size() - 1));
|
if (!ids.empty()) {
|
||||||
this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend());
|
beginInsertRows(QModelIndex(), 0, static_cast<int>(ids.size() - 1));
|
||||||
endInsertRows();
|
this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend());
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
|
||||||
prev_batch_token_ = QString::fromStdString(msgs.end);
|
prev_batch_token_ = QString::fromStdString(msgs.end);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user