mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add timeline day separators and read markers (#383)
* Add timeline day separators and read markers
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct ReadMarkerRoomTimelineItem: DecorationTimelineItemProtocol, Identifiable, Hashable {
|
||||
let id: String
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
import Foundation
|
||||
|
||||
struct RoomTimelineViewFactory: RoomTimelineViewFactoryProtocol {
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
func buildTimelineViewFor(timelineItem: RoomTimelineItemProtocol) -> RoomTimelineViewProvider {
|
||||
switch timelineItem {
|
||||
case let item as TextRoomTimelineItem:
|
||||
@@ -37,6 +38,8 @@ struct RoomTimelineViewFactory: RoomTimelineViewFactoryProtocol {
|
||||
return .redacted(item)
|
||||
case let item as EncryptedRoomTimelineItem:
|
||||
return .encrypted(item)
|
||||
case let item as ReadMarkerRoomTimelineItem:
|
||||
return .readMarker(item)
|
||||
default:
|
||||
fatalError("Unknown timeline item")
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ enum RoomTimelineViewProvider: Identifiable, Hashable {
|
||||
case notice(NoticeRoomTimelineItem)
|
||||
case redacted(RedactedRoomTimelineItem)
|
||||
case encrypted(EncryptedRoomTimelineItem)
|
||||
case readMarker(ReadMarkerRoomTimelineItem)
|
||||
case backPaginationIndicator(Bool)
|
||||
|
||||
var id: String {
|
||||
@@ -49,6 +50,8 @@ enum RoomTimelineViewProvider: Identifiable, Hashable {
|
||||
return item.id
|
||||
case .encrypted(let item):
|
||||
return item.id
|
||||
case .readMarker(let item):
|
||||
return item.id
|
||||
case .backPaginationIndicator:
|
||||
return "BackpaginationLoadingIndicator"
|
||||
}
|
||||
@@ -76,6 +79,8 @@ extension RoomTimelineViewProvider: View {
|
||||
RedactedRoomTimelineView(timelineItem: item)
|
||||
case .encrypted(let item):
|
||||
EncryptedRoomTimelineView(timelineItem: item)
|
||||
case .readMarker(let item):
|
||||
ReadMarkerRoomTimelineView(timelineItem: item)
|
||||
case .backPaginationIndicator(let isBackPaginating):
|
||||
ProgressView()
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
Reference in New Issue
Block a user