From 4efac5a247721c1c5ba4c072be0bce21ee620039 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 9 Sep 2019 20:33:22 +0200 Subject: [PATCH] Try to fix duplicate messages in certain edge cases (i.e. sync and pagination at the same time) --- src/timeline2/TimelineModel.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index d3d6f5c7..54f03b56 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -324,10 +324,16 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) QString id = boost::apply_visitor([](const auto &e) -> QString { return eventId(e); }, e); + if (this->events.contains(id)) + continue; + this->events.insert(id, e); ids.push_back(id); } + if (ids.empty) + return; + beginInsertRows(QModelIndex(), static_cast(this->eventOrder.size()), static_cast(this->eventOrder.size() + ids.size() - 1)); @@ -372,13 +378,18 @@ TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs) QString id = boost::apply_visitor([](const auto &e) -> QString { return eventId(e); }, e); + if (this->events.contains(id)) + continue; + this->events.insert(id, e); ids.push_back(id); } - beginInsertRows(QModelIndex(), 0, static_cast(ids.size() - 1)); - this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend()); - endInsertRows(); + if (!ids.empty()) { + beginInsertRows(QModelIndex(), 0, static_cast(ids.size() - 1)); + this->eventOrder.insert(this->eventOrder.begin(), ids.rbegin(), ids.rend()); + endInsertRows(); + } prev_batch_token_ = QString::fromStdString(msgs.end);