From a7e06a65299fbc72fa8c06980f2b16fe621f9874 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sun, 22 Nov 2020 14:51:25 +0000 Subject: [PATCH] Improve sections Now they are displayed for each day (if there was at least one message on that day) instead of every few hours --- imports/NeoChat/Component/Timeline/SectionDelegate.qml | 3 +-- src/messageeventmodel.cpp | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/imports/NeoChat/Component/Timeline/SectionDelegate.qml b/imports/NeoChat/Component/Timeline/SectionDelegate.qml index 472c12c9b..380733a0a 100644 --- a/imports/NeoChat/Component/Timeline/SectionDelegate.qml +++ b/imports/NeoChat/Component/Timeline/SectionDelegate.qml @@ -10,8 +10,7 @@ import org.kde.kirigami 2.13 as Kirigami Kirigami.Heading { level: 4 - text: section + " • " + Qt.formatTime(time) - font.capitalization: Font.AllUppercase + text: section verticalAlignment: Text.AlignVCenter topPadding: Kirigami.Units.largeSpacing * 2 bottomPadding: Kirigami.Units.smallSpacing diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index c5ee2d15d..5f0d720ad 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -15,6 +15,7 @@ #include #include +#include #include // for qmlRegisterType() #include @@ -452,7 +453,9 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const for (auto r = row + 1; r < rowCount(); ++r) { auto i = index(r); if (data(i, SpecialMarksRole) != EventStatus::Hidden) { - return data(i, TimeRole).toDateTime().msecsTo(data(idx, TimeRole).toDateTime()) > 600000; + const auto day = data(idx, TimeRole).toDateTime().toLocalTime().date().dayOfYear(); + const auto previousEventDay = data(i, TimeRole).toDateTime().toLocalTime().date().dayOfYear(); + return day != previousEventDay; } }