From 7cfc0e24e243e8108ab5f3b78db7345f4cb69dd0 Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 7 Oct 2022 13:32:05 +0000 Subject: [PATCH] Fix Section After Read Marker Removal After the readmarker is removed it leaves a gap in the indexs until the model is refreshed. Add check to ignore the gap for the purpose of show author and show section roles. Closes network/neochat#295 BUG: 454885 --- src/messageeventmodel.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index e006b88e1..f9e0ca870 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -720,7 +720,10 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const if (role == ShowAuthorRole) { for (auto r = row + 1; r < rowCount(); ++r) { auto i = index(r); - if (data(i, SpecialMarksRole) != EventStatus::Hidden) { + // Note !itemData(i).empty() is a check for instances where rows have been removed, e.g. when the read marker is moved. + // While the row is removed the subsequent row indexes are not changed so we need to skip over the removed index. + // See - https://doc.qt.io/qt-5/qabstractitemmodel.html#beginRemoveRows + if (data(i, SpecialMarksRole) != EventStatus::Hidden && !itemData(i).empty()) { return data(i, AuthorRole) != data(idx, AuthorRole) || data(i, EventTypeRole) == "state" || data(i, TimeRole).toDateTime().msecsTo(data(idx, TimeRole).toDateTime()) > 600000 || data(i, TimeRole).toDateTime().toLocalTime().date().day() != data(idx, TimeRole).toDateTime().toLocalTime().date().day(); @@ -733,7 +736,10 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const if (role == ShowSectionRole) { for (auto r = row + 1; r < rowCount(); ++r) { auto i = index(r); - if (data(i, SpecialMarksRole) != EventStatus::Hidden) { + // Note !itemData(i).empty() is a check for instances where rows have been removed, e.g. when the read marker is moved. + // While the row is removed the subsequent row indexes are not changed so we need to skip over the removed index. + // See - https://doc.qt.io/qt-5/qabstractitemmodel.html#beginRemoveRows + if (data(i, SpecialMarksRole) != EventStatus::Hidden && !itemData(i).empty()) { const auto day = data(idx, TimeRole).toDateTime().toLocalTime().date().dayOfYear(); const auto previousEventDay = data(i, TimeRole).toDateTime().toLocalTime().date().dayOfYear(); return day != previousEventDay;