Add timeline day separators and read markers (#383)

* Add timeline day separators and read markers
This commit is contained in:
Stefan Ceriu
2022-12-21 15:35:45 +02:00
committed by GitHub
parent a9f2e1bdf8
commit 131197b7d7
10 changed files with 113 additions and 29 deletions
@@ -235,6 +235,22 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
case .event(let eventItem):
newTimelineItems.append(timelineItemFactory.buildTimelineItemFor(eventItemProxy: eventItem,
inGroupState: inGroupState))
case .virtual(let virtualItem):
switch virtualItem {
case .dayDivider(let year, let month, let day):
// These components will be replaced by a timestamp in upcoming releases
let dateComponents = DateComponents(calendar: .current, year: Int(year), month: Int(month), day: Int(day))
if let dateString = dateComponents.date?.formatted(date: .complete, time: .omitted) {
newTimelineItems.append(SeparatorRoomTimelineItem(id: UUID().uuidString, text: dateString))
} else {
MXLog.error("Failed formatting separator date")
}
case .readMarker:
// Don't show the read marker if it's the last item in the timeline
if index != timelineProvider.itemsPublisher.value.indices.last {
newTimelineItems.append(ReadMarkerRoomTimelineItem(id: UUID().uuidString))
}
}
default:
break
}