mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
New timeline items (#424)
* Cleanup session verification state machine configuration * Add support for new timeline items: loading indicators, stickers and invalid/unsupported events * Add sticker accessibility label, fix session verification ones * Add support for the new TimelineStart timeline item and new pagination API. Remove identifiers from individual timeline items and only set them in the TimelineTableViewController * Add changelog
This commit is contained in:
committed by
Stefan Ceriu
parent
956e92a9ac
commit
d70a240869
@@ -19,12 +19,11 @@ import Foundation
|
||||
enum RoomTimelineItemFixtures {
|
||||
/// The default timeline items used in Xcode previews etc.
|
||||
static var `default`: [RoomTimelineItemProtocol] = [
|
||||
SeparatorRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "Yesterday"),
|
||||
SeparatorRoomTimelineItem(text: "Yesterday"),
|
||||
TextRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "That looks so good!",
|
||||
timestamp: "10:10 AM",
|
||||
inGroupState: .single,
|
||||
groupState: .single,
|
||||
isOutgoing: false,
|
||||
isEditable: false,
|
||||
senderId: "",
|
||||
@@ -33,7 +32,7 @@ enum RoomTimelineItemFixtures {
|
||||
TextRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "Let’s get lunch soon! New salad place opened up 🥗. When are y’all free? 🤗",
|
||||
timestamp: "10:11 AM",
|
||||
inGroupState: .beginning,
|
||||
groupState: .beginning,
|
||||
isOutgoing: false,
|
||||
isEditable: false,
|
||||
senderId: "",
|
||||
@@ -44,7 +43,7 @@ enum RoomTimelineItemFixtures {
|
||||
TextRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "I can be around on Wednesday. How about some 🌮 instead? Like https://www.tortilla.co.uk/",
|
||||
timestamp: "10:11 AM",
|
||||
inGroupState: .end,
|
||||
groupState: .end,
|
||||
isOutgoing: false,
|
||||
isEditable: false,
|
||||
senderId: "",
|
||||
@@ -53,12 +52,11 @@ enum RoomTimelineItemFixtures {
|
||||
AggregatedReaction(key: "🙏", count: 1, isHighlighted: false),
|
||||
AggregatedReaction(key: "🙌", count: 2, isHighlighted: true)
|
||||
])),
|
||||
SeparatorRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "Today"),
|
||||
SeparatorRoomTimelineItem(text: "Today"),
|
||||
TextRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "Wow, cool. Ok, lets go the usual place tomorrow?! Is that too soon? Here’s the menu, let me know what you want it’s on me!",
|
||||
timestamp: "5 PM",
|
||||
inGroupState: .single,
|
||||
groupState: .single,
|
||||
isOutgoing: false,
|
||||
isEditable: false,
|
||||
senderId: "",
|
||||
@@ -66,7 +64,7 @@ enum RoomTimelineItemFixtures {
|
||||
TextRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "And John's speech was amazing!",
|
||||
timestamp: "5 PM",
|
||||
inGroupState: .beginning,
|
||||
groupState: .beginning,
|
||||
isOutgoing: true,
|
||||
isEditable: true,
|
||||
senderId: "",
|
||||
@@ -74,7 +72,7 @@ enum RoomTimelineItemFixtures {
|
||||
TextRoomTimelineItem(id: UUID().uuidString,
|
||||
text: "New home office set up!",
|
||||
timestamp: "5 PM",
|
||||
inGroupState: .end,
|
||||
groupState: .end,
|
||||
isOutgoing: true,
|
||||
isEditable: true,
|
||||
senderId: "",
|
||||
@@ -91,7 +89,7 @@ enum RoomTimelineItemFixtures {
|
||||
AttributedStringBuilderComponent(attributedString: "That's amazing! Congrats 🥳", isBlockquote: false)
|
||||
],
|
||||
timestamp: "5 PM",
|
||||
inGroupState: .single,
|
||||
groupState: .single,
|
||||
isOutgoing: false,
|
||||
isEditable: false,
|
||||
senderId: "",
|
||||
@@ -101,24 +99,24 @@ enum RoomTimelineItemFixtures {
|
||||
/// A small chunk of events, containing 2 text items.
|
||||
static var smallChunk: [RoomTimelineItemProtocol] {
|
||||
[TextRoomTimelineItem(text: "Hey there 👋",
|
||||
inGroupState: .beginning,
|
||||
groupState: .beginning,
|
||||
senderDisplayName: "Alice"),
|
||||
TextRoomTimelineItem(text: "How are you?",
|
||||
inGroupState: .end,
|
||||
groupState: .end,
|
||||
senderDisplayName: "Alice")]
|
||||
}
|
||||
|
||||
/// A chunk of events that contains a single text item.
|
||||
static var singleMessageChunk: [RoomTimelineItemProtocol] {
|
||||
[TextRoomTimelineItem(text: "Tap tap tap 🎙️. Is this thing on?",
|
||||
inGroupState: .single,
|
||||
groupState: .single,
|
||||
senderDisplayName: "Helena")]
|
||||
}
|
||||
|
||||
/// A single text item.
|
||||
static var incomingMessage: RoomTimelineItemProtocol {
|
||||
TextRoomTimelineItem(text: "Hello, World!",
|
||||
inGroupState: .single,
|
||||
groupState: .single,
|
||||
senderDisplayName: "Bob")
|
||||
}
|
||||
|
||||
@@ -209,11 +207,11 @@ enum RoomTimelineItemFixtures {
|
||||
}
|
||||
|
||||
private extension TextRoomTimelineItem {
|
||||
init(text: String, inGroupState: TimelineItemInGroupState = .single, senderDisplayName: String) {
|
||||
init(text: String, groupState: TimelineItemGroupState = .single, senderDisplayName: String) {
|
||||
self.init(id: UUID().uuidString,
|
||||
text: text,
|
||||
timestamp: "10:47 am",
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: senderDisplayName == "Alice",
|
||||
isEditable: false,
|
||||
senderId: "",
|
||||
|
||||
@@ -23,7 +23,7 @@ struct MockRoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
|
||||
private var itemProxies = [TimelineItemProxy]()
|
||||
|
||||
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineProviderError> {
|
||||
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineProviderError> {
|
||||
.failure(.failedPaginatingBackwards)
|
||||
}
|
||||
|
||||
|
||||
@@ -68,18 +68,14 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineProviderError> {
|
||||
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineProviderError> {
|
||||
// Set this back to false after actually updating the items or if failed
|
||||
backPaginationPublisher.send(true)
|
||||
|
||||
MXLog.info("Started back pagination request")
|
||||
switch await roomProxy.paginateBackwards(count: count) {
|
||||
case .success(let numberOfUpdates):
|
||||
MXLog.info("Finished back pagination request. Got \(numberOfUpdates) updates")
|
||||
|
||||
if numberOfUpdates == 0 {
|
||||
backPaginationPublisher.send(false)
|
||||
}
|
||||
switch await roomProxy.paginateBackwards(requestSize: requestSize, untilNumberOfItems: untilNumberOfItems) {
|
||||
case .success:
|
||||
MXLog.info("Finished back pagination request")
|
||||
return .success(())
|
||||
case .failure(let error):
|
||||
MXLog.error("Failed back pagination request with error: \(error)")
|
||||
@@ -152,7 +148,7 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
// MARK: - Private
|
||||
|
||||
private func updateItemsWithDiffs(_ diffs: [TimelineDiff]) {
|
||||
MXLog.info("Received timeline diffs")
|
||||
MXLog.verbose("Received timeline diffs")
|
||||
|
||||
itemProxies = diffs
|
||||
.reduce(itemProxies) { currentItems, diff in
|
||||
@@ -171,7 +167,7 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
return updatedItems
|
||||
}
|
||||
|
||||
MXLog.info("Finished applying diffs")
|
||||
MXLog.verbose("Finished applying diffs")
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity function_body_length
|
||||
|
||||
@@ -31,7 +31,7 @@ protocol RoomTimelineProviderProtocol {
|
||||
|
||||
var backPaginationPublisher: CurrentValueSubject<Bool, Never> { get }
|
||||
|
||||
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineProviderError>
|
||||
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineProviderError>
|
||||
|
||||
func sendMessage(_ message: String, inReplyToItemId: String?) async -> Result<Void, RoomTimelineProviderError>
|
||||
|
||||
|
||||
@@ -23,13 +23,6 @@ protocol MessageContentProtocol: RoomMessageEventContentProtocol {
|
||||
var body: String { get }
|
||||
}
|
||||
|
||||
/// The delivery status for the item.
|
||||
enum MessageTimelineItemDeliveryStatus: Hashable {
|
||||
case unknown
|
||||
case sending
|
||||
case sent(elapsedTime: TimeInterval)
|
||||
}
|
||||
|
||||
/// A timeline item that represents an `m.room.message` event.
|
||||
struct MessageTimelineItem<Content: MessageContentProtocol> {
|
||||
let item: MatrixRustSDK.EventTimelineItem
|
||||
@@ -43,15 +36,6 @@ struct MessageTimelineItem<Content: MessageContentProtocol> {
|
||||
return eventID
|
||||
}
|
||||
}
|
||||
|
||||
var deliveryStatus: MessageTimelineItemDeliveryStatus {
|
||||
switch item.key() {
|
||||
case .transactionId:
|
||||
return .sending
|
||||
case .eventId:
|
||||
return .sent(elapsedTime: Date().timeIntervalSince1970 - timestamp.timeIntervalSince1970)
|
||||
}
|
||||
}
|
||||
|
||||
var body: String {
|
||||
content.body
|
||||
@@ -61,18 +45,10 @@ struct MessageTimelineItem<Content: MessageContentProtocol> {
|
||||
item.content().asMessage()?.isEdited() == true
|
||||
}
|
||||
|
||||
var isEditable: Bool {
|
||||
item.isEditable()
|
||||
}
|
||||
|
||||
var inReplyTo: String? {
|
||||
item.content().asMessage()?.inReplyTo()
|
||||
}
|
||||
|
||||
var reactions: [Reaction] {
|
||||
item.reactions()
|
||||
}
|
||||
|
||||
var sender: String {
|
||||
item.sender()
|
||||
}
|
||||
|
||||
+19
-2
@@ -20,6 +20,9 @@ import Foundation
|
||||
class MockRoomTimelineController: RoomTimelineControllerProtocol {
|
||||
/// An array of timeline item arrays that will be inserted in order for each back pagination request.
|
||||
var backPaginationResponses: [[RoomTimelineItemProtocol]] = []
|
||||
/// The time delay added to each back pagination request.
|
||||
var backPaginationDelay: Duration = .milliseconds(500)
|
||||
|
||||
/// An array of timeline items that will be appended in order when ``simulateIncomingItems()`` is called.
|
||||
var incomingItems: [RoomTimelineItemProtocol] = []
|
||||
|
||||
@@ -38,8 +41,22 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineControllerError> {
|
||||
.failure(.generic)
|
||||
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineControllerError> {
|
||||
callbacks.send(.startedBackPaginating)
|
||||
|
||||
guard !backPaginationResponses.isEmpty else {
|
||||
callbacks.send(.finishedBackPaginating)
|
||||
return .failure(.generic)
|
||||
}
|
||||
|
||||
let newItems = backPaginationResponses.removeFirst()
|
||||
|
||||
try? await Task.sleep(for: backPaginationDelay)
|
||||
timelineItems.insert(contentsOf: newItems, at: 0)
|
||||
callbacks.send(.updatedTimelineItems)
|
||||
callbacks.send(.finishedBackPaginating)
|
||||
|
||||
return .success(())
|
||||
}
|
||||
|
||||
func processItemAppearance(_ itemId: String) async { }
|
||||
|
||||
+41
-10
@@ -78,8 +78,8 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
|
||||
}
|
||||
|
||||
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineControllerError> {
|
||||
switch await timelineProvider.paginateBackwards(count) {
|
||||
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineControllerError> {
|
||||
switch await timelineProvider.paginateBackwards(requestSize: requestSize, untilNumberOfItems: untilNumberOfItems) {
|
||||
case .success:
|
||||
return .success(())
|
||||
case .failure(let error):
|
||||
@@ -105,6 +105,8 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
await loadThumbnailForImageTimelineItem(item)
|
||||
case let item as VideoRoomTimelineItem:
|
||||
await loadThumbnailForVideoTimelineItem(item)
|
||||
case let item as StickerRoomTimelineItem:
|
||||
await loadThumbnailForStickerTimelineItem(item)
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -225,6 +227,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
private func asyncUpdateTimelineItems() async {
|
||||
var newTimelineItems = [RoomTimelineItemProtocol]()
|
||||
|
||||
@@ -236,27 +239,31 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
let previousItemProxy = timelineProvider.itemsPublisher.value[safe: index - 1]
|
||||
let nextItemProxy = timelineProvider.itemsPublisher.value[safe: index + 1]
|
||||
|
||||
let inGroupState = inGroupState(for: itemProxy, previousItemProxy: previousItemProxy, nextItemProxy: nextItemProxy)
|
||||
let groupState = computeGroupState(for: itemProxy, previousItemProxy: previousItemProxy, nextItemProxy: nextItemProxy)
|
||||
|
||||
switch itemProxy {
|
||||
case .event(let eventItem):
|
||||
newTimelineItems.append(timelineItemFactory.buildTimelineItemFor(eventItemProxy: eventItem,
|
||||
inGroupState: inGroupState))
|
||||
groupState: groupState))
|
||||
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))
|
||||
newTimelineItems.append(SeparatorRoomTimelineItem(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))
|
||||
newTimelineItems.append(ReadMarkerRoomTimelineItem())
|
||||
}
|
||||
case .loadingIndicator:
|
||||
newTimelineItems.append(PaginationIndicatorRoomTimelineItem())
|
||||
case .timelineStart:
|
||||
newTimelineItems.append(TimelineStartRoomTimelineItem(name: roomProxy.displayName ?? roomProxy.name))
|
||||
}
|
||||
default:
|
||||
break
|
||||
@@ -271,10 +278,10 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
|
||||
callbacks.send(.updatedTimelineItems)
|
||||
}
|
||||
|
||||
private func inGroupState(for itemProxy: TimelineItemProxy,
|
||||
previousItemProxy: TimelineItemProxy?,
|
||||
nextItemProxy: TimelineItemProxy?) -> TimelineItemInGroupState {
|
||||
|
||||
private func computeGroupState(for itemProxy: TimelineItemProxy,
|
||||
previousItemProxy: TimelineItemProxy?,
|
||||
nextItemProxy: TimelineItemProxy?) -> TimelineItemGroupState {
|
||||
guard let previousItem = previousItemProxy else {
|
||||
// no previous item, check next item
|
||||
guard let nextItem = nextItemProxy else {
|
||||
@@ -364,6 +371,30 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
private func loadThumbnailForStickerTimelineItem(_ timelineItem: StickerRoomTimelineItem) async {
|
||||
if timelineItem.image != nil {
|
||||
return
|
||||
}
|
||||
|
||||
guard let urlString = timelineItem.urlString else {
|
||||
return
|
||||
}
|
||||
|
||||
switch await mediaProvider.loadImageFromURLString(urlString) {
|
||||
case .success(let image):
|
||||
guard let index = timelineItems.firstIndex(where: { $0.id == timelineItem.id }),
|
||||
var item = timelineItems[index] as? StickerRoomTimelineItem else {
|
||||
return
|
||||
}
|
||||
|
||||
item.image = image
|
||||
timelineItems[index] = item
|
||||
callbacks.send(.updatedTimelineItem(timelineItem.id))
|
||||
case .failure:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
private func loadVideoForTimelineItem(_ timelineItem: VideoRoomTimelineItem) async {
|
||||
if timelineItem.cachedVideoURL != nil {
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ protocol RoomTimelineControllerProtocol {
|
||||
|
||||
func processItemTap(_ itemId: String) async -> RoomTimelineControllerAction
|
||||
|
||||
func paginateBackwards(_ count: UInt) async -> Result<Void, RoomTimelineControllerError>
|
||||
func paginateBackwards(requestSize: UInt, untilNumberOfItems: UInt) async -> Result<Void, RoomTimelineControllerError>
|
||||
|
||||
func sendMessage(_ message: String) async
|
||||
|
||||
|
||||
@@ -42,6 +42,13 @@ enum TimelineItemProxy {
|
||||
}
|
||||
}
|
||||
|
||||
/// The delivery status for the item.
|
||||
enum TimelineItemDeliveryStatus: Hashable {
|
||||
case unknown
|
||||
case sending
|
||||
case sent(elapsedTime: TimeInterval)
|
||||
}
|
||||
|
||||
/// A light wrapper around event timeline items returned from Rust.
|
||||
struct EventTimelineItemProxy: CustomDebugStringConvertible {
|
||||
let item: MatrixRustSDK.EventTimelineItem
|
||||
@@ -59,6 +66,15 @@ struct EventTimelineItemProxy: CustomDebugStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
var deliveryStatus: TimelineItemDeliveryStatus {
|
||||
switch item.key() {
|
||||
case .transactionId:
|
||||
return .sending
|
||||
case .eventId:
|
||||
return .sent(elapsedTime: Date().timeIntervalSince1970 - timestamp.timeIntervalSince1970)
|
||||
}
|
||||
}
|
||||
|
||||
var body: String? {
|
||||
content.asMessage()?.body()
|
||||
}
|
||||
@@ -71,10 +87,6 @@ struct EventTimelineItemProxy: CustomDebugStringConvertible {
|
||||
item.content()
|
||||
}
|
||||
|
||||
var isRedacted: Bool {
|
||||
content.isRedactedMessage()
|
||||
}
|
||||
|
||||
var isOwn: Bool {
|
||||
item.isOwn()
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,7 +17,7 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
enum TimelineItemInGroupState: Hashable {
|
||||
enum TimelineItemGroupState: Hashable {
|
||||
case single
|
||||
case beginning
|
||||
case middle
|
||||
@@ -37,7 +37,7 @@ protocol EventBasedTimelineItemProtocol: RoomTimelineItemProtocol {
|
||||
var text: String { get }
|
||||
var timestamp: String { get }
|
||||
var shouldShowSenderDetails: Bool { get }
|
||||
var inGroupState: TimelineItemInGroupState { get }
|
||||
var groupState: TimelineItemGroupState { get }
|
||||
var isOutgoing: Bool { get }
|
||||
var isEditable: Bool { get }
|
||||
|
||||
@@ -50,11 +50,11 @@ protocol EventBasedTimelineItemProtocol: RoomTimelineItemProtocol {
|
||||
|
||||
extension EventBasedTimelineItemProtocol {
|
||||
var shouldShowSenderDetails: Bool {
|
||||
inGroupState.shouldShowSenderDetails
|
||||
groupState.shouldShowSenderDetails
|
||||
}
|
||||
|
||||
var roundedCorners: UIRectCorner {
|
||||
switch inGroupState {
|
||||
switch groupState {
|
||||
case .single:
|
||||
return .allCorners
|
||||
case .beginning:
|
||||
|
||||
@@ -22,7 +22,7 @@ struct EmoteRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hash
|
||||
let text: String
|
||||
var attributedComponents: [AttributedStringBuilderComponent]?
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ struct EncryptedRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable,
|
||||
let text: String
|
||||
let encryptionType: EncryptionType
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ struct FileRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hasha
|
||||
let id: String
|
||||
let text: String
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ struct ImageRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hash
|
||||
let id: String
|
||||
let text: String
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ struct NoticeRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Has
|
||||
let text: String
|
||||
var attributedComponents: [AttributedStringBuilderComponent]?
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Copyright 2023 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 PaginationIndicatorRoomTimelineItem: DecorationTimelineItemProtocol, Identifiable, Hashable {
|
||||
let id: String = UUID().uuidString
|
||||
}
|
||||
+1
-1
@@ -17,5 +17,5 @@
|
||||
import Foundation
|
||||
|
||||
struct ReadMarkerRoomTimelineItem: DecorationTimelineItemProtocol, Identifiable, Hashable {
|
||||
let id: String
|
||||
let id: String = UUID().uuidString
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ struct RedactedRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, H
|
||||
let id: String
|
||||
let text: String
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
+1
-1
@@ -23,5 +23,5 @@ struct RoomTimelineItemProperties: Hashable {
|
||||
/// The aggregated reactions that have been sent for this item.
|
||||
var reactions: [AggregatedReaction] = []
|
||||
/// The delivery status for this item.
|
||||
var deliveryStatus: MessageTimelineItemDeliveryStatus = .unknown
|
||||
var deliveryStatus: TimelineItemDeliveryStatus = .unknown
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,6 +17,6 @@
|
||||
import Foundation
|
||||
|
||||
struct SeparatorRoomTimelineItem: DecorationTimelineItemProtocol, Identifiable, Hashable {
|
||||
let id: String
|
||||
let id: String = UUID().uuidString
|
||||
let text: String
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// Copyright 2023 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 UIKit
|
||||
|
||||
struct StickerRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
||||
let id: String
|
||||
let text: String
|
||||
let timestamp: String
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
let senderId: String
|
||||
var senderDisplayName: String?
|
||||
var senderAvatar: UIImage?
|
||||
|
||||
let urlString: String?
|
||||
var image: UIImage?
|
||||
|
||||
var width: CGFloat?
|
||||
var height: CGFloat?
|
||||
var aspectRatio: CGFloat?
|
||||
var blurhash: String?
|
||||
|
||||
var properties = RoomTimelineItemProperties()
|
||||
}
|
||||
@@ -22,7 +22,7 @@ struct TextRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hasha
|
||||
let text: String
|
||||
var attributedComponents: [AttributedStringBuilderComponent]?
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Copyright 2023 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 TimelineStartRoomTimelineItem: DecorationTimelineItemProtocol, Identifiable, Hashable {
|
||||
let id: String = UUID().uuidString
|
||||
let name: String?
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright 2023 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 UIKit
|
||||
|
||||
struct UnsupportedRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
||||
let id: String
|
||||
let text: String
|
||||
|
||||
let eventType: String
|
||||
let error: String
|
||||
|
||||
let timestamp: String
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
let senderId: String
|
||||
var senderDisplayName: String?
|
||||
var senderAvatar: UIImage?
|
||||
|
||||
var properties = RoomTimelineItemProperties()
|
||||
}
|
||||
@@ -21,7 +21,7 @@ struct VideoRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hash
|
||||
let id: String
|
||||
let text: String
|
||||
let timestamp: String
|
||||
let inGroupState: TimelineItemInGroupState
|
||||
let groupState: TimelineItemGroupState
|
||||
let isOutgoing: Bool
|
||||
let isEditable: Bool
|
||||
|
||||
|
||||
@@ -35,54 +35,117 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
self.attributedStringBuilder = attributedStringBuilder
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
func buildTimelineItemFor(eventItemProxy: EventTimelineItemProxy,
|
||||
inGroupState: TimelineItemInGroupState) -> RoomTimelineItemProtocol {
|
||||
groupState: TimelineItemGroupState) -> RoomTimelineItemProtocol {
|
||||
let displayName = roomProxy.displayNameForUserId(eventItemProxy.sender)
|
||||
let avatarURL = roomProxy.avatarURLStringForUserId(eventItemProxy.sender)
|
||||
let avatarImage = mediaProvider.imageFromURLString(avatarURL, avatarSize: .user(on: .timeline))
|
||||
let isOutgoing = eventItemProxy.isOwn
|
||||
|
||||
if let encryptedMessage = eventItemProxy.content.asUnableToDecrypt() {
|
||||
return buildEncryptedTimelineItem(eventItemProxy, encryptedMessage, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
}
|
||||
|
||||
if eventItemProxy.isRedacted {
|
||||
return buildRedactedTimelineItem(eventItemProxy, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
}
|
||||
|
||||
guard let messageContent = eventItemProxy.content.asMessage() else { fatalError("Must be a message for now.") }
|
||||
|
||||
switch messageContent.msgtype() {
|
||||
case .text(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildTextTimelineItemFromMessage(message, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
case .image(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildImageTimelineItemFromMessage(message, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
case .video(let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildVideoTimelineItemFromMessage(message, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
case .file(let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildFileTimelineItemFromMessage(message, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
case .notice(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildNoticeTimelineItemFromMessage(message, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
case .emote(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildEmoteTimelineItemFromMessage(message, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
case .none:
|
||||
return buildFallbackTimelineItem(eventItemProxy, isOutgoing, inGroupState, displayName, avatarImage)
|
||||
switch eventItemProxy.content.kind() {
|
||||
case .unableToDecrypt(let encryptedMessage):
|
||||
return buildEncryptedTimelineItem(eventItemProxy, encryptedMessage, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .redactedMessage:
|
||||
return buildRedactedTimelineItem(eventItemProxy, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .sticker(let body, let imageInfo, let url):
|
||||
return buildStickerTimelineItem(eventItemProxy, body, imageInfo, url, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .failedToParseMessageLike(let eventType, let error):
|
||||
return buildUnsupportedTimelineItem(eventItemProxy, eventType, error, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .failedToParseState(let eventType, _, let error):
|
||||
return buildUnsupportedTimelineItem(eventItemProxy, eventType, error, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .message:
|
||||
guard let messageContent = eventItemProxy.content.asMessage() else { fatalError("Invalid message timeline item: \(eventItemProxy)") }
|
||||
|
||||
switch messageContent.msgtype() {
|
||||
case .text(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildTextTimelineItemFromMessage(eventItemProxy, message, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .image(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildImageTimelineItemFromMessage(eventItemProxy, message, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .video(let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildVideoTimelineItemFromMessage(eventItemProxy, message, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .file(let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildFileTimelineItemFromMessage(eventItemProxy, message, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .notice(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildNoticeTimelineItemFromMessage(eventItemProxy, message, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .emote(content: let content):
|
||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
||||
return buildEmoteTimelineItemFromMessage(eventItemProxy, message, isOutgoing, groupState, displayName, avatarImage)
|
||||
case .none:
|
||||
return buildFallbackTimelineItem(eventItemProxy, isOutgoing, groupState, displayName, avatarImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildUnsupportedTimelineItem(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ eventType: String,
|
||||
_ error: String,
|
||||
_ isOutgoing: Bool,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
UnsupportedRoomTimelineItem(id: eventItemProxy.id,
|
||||
text: ElementL10n.roomTimelineItemUnsupported,
|
||||
eventType: eventType,
|
||||
error: error,
|
||||
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: eventItemProxy.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
properties: RoomTimelineItemProperties())
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildStickerTimelineItem(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ body: String,
|
||||
_ imageInfo: ImageInfo,
|
||||
_ urlString: String,
|
||||
_ isOutgoing: Bool,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
var aspectRatio: CGFloat?
|
||||
let width = imageInfo.width.map(CGFloat.init)
|
||||
let height = imageInfo.height.map(CGFloat.init)
|
||||
if let width, let height {
|
||||
aspectRatio = width / height
|
||||
}
|
||||
|
||||
return StickerRoomTimelineItem(id: eventItemProxy.id,
|
||||
text: body,
|
||||
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: eventItemProxy.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
urlString: urlString,
|
||||
image: mediaProvider.imageFromURLString(urlString),
|
||||
width: width,
|
||||
height: height,
|
||||
aspectRatio: aspectRatio,
|
||||
blurhash: imageInfo.blurhash,
|
||||
properties: RoomTimelineItemProperties(reactions: aggregateReactions(eventItemProxy.reactions),
|
||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildEncryptedTimelineItem(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ encryptedMessage: EncryptedMessage,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
var encryptionType = EncryptedRoomTimelineItem.EncryptionType.unknown
|
||||
@@ -99,7 +162,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
text: ElementL10n.encryptionInformationDecryptionError,
|
||||
encryptionType: encryptionType,
|
||||
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: eventItemProxy.sender,
|
||||
@@ -110,13 +173,13 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
|
||||
private func buildRedactedTimelineItem(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
RedactedRoomTimelineItem(id: eventItemProxy.id,
|
||||
text: ElementL10n.eventRedacted,
|
||||
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: eventItemProxy.sender,
|
||||
@@ -127,7 +190,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
|
||||
private func buildFallbackTimelineItem(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
let attributedText = attributedStringBuilder.fromPlain(eventItemProxy.body)
|
||||
@@ -137,7 +200,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
text: eventItemProxy.body ?? "",
|
||||
attributedComponents: attributedComponents,
|
||||
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: eventItemProxy.sender,
|
||||
@@ -147,9 +210,11 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
reactions: aggregateReactions(eventItemProxy.reactions)))
|
||||
}
|
||||
|
||||
private func buildTextTimelineItemFromMessage(_ message: MessageTimelineItem<TextMessageContent>,
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildTextTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ message: MessageTimelineItem<TextMessageContent>,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
let attributedText = (message.htmlBody != nil ? attributedStringBuilder.fromHTML(message.htmlBody) : attributedStringBuilder.fromPlain(message.body))
|
||||
@@ -159,20 +224,22 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
text: message.body,
|
||||
attributedComponents: attributedComponents,
|
||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: message.isEditable,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: message.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
||||
reactions: aggregateReactions(message.reactions),
|
||||
deliveryStatus: message.deliveryStatus))
|
||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||
}
|
||||
|
||||
private func buildImageTimelineItemFromMessage(_ message: MessageTimelineItem<ImageMessageContent>,
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildImageTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ message: MessageTimelineItem<ImageMessageContent>,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
var aspectRatio: CGFloat?
|
||||
@@ -184,9 +251,9 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
return ImageRoomTimelineItem(id: message.id,
|
||||
text: message.body,
|
||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: message.isEditable,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: message.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
@@ -197,13 +264,15 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
aspectRatio: aspectRatio,
|
||||
blurhash: message.blurhash,
|
||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
||||
reactions: aggregateReactions(message.reactions),
|
||||
deliveryStatus: message.deliveryStatus))
|
||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||
}
|
||||
|
||||
private func buildVideoTimelineItemFromMessage(_ message: MessageTimelineItem<VideoMessageContent>,
|
||||
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildVideoTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ message: MessageTimelineItem<VideoMessageContent>,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
var aspectRatio: CGFloat?
|
||||
@@ -215,9 +284,9 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
return VideoRoomTimelineItem(id: message.id,
|
||||
text: message.body,
|
||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: message.isEditable,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: message.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
@@ -230,34 +299,38 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
aspectRatio: aspectRatio,
|
||||
blurhash: message.blurhash,
|
||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
||||
reactions: aggregateReactions(message.reactions),
|
||||
deliveryStatus: message.deliveryStatus))
|
||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||
}
|
||||
|
||||
private func buildFileTimelineItemFromMessage(_ message: MessageTimelineItem<FileMessageContent>,
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildFileTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ message: MessageTimelineItem<FileMessageContent>,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
FileRoomTimelineItem(id: message.id,
|
||||
text: message.body,
|
||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: message.isEditable,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: message.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
source: message.source,
|
||||
thumbnailSource: message.thumbnailSource,
|
||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
||||
reactions: aggregateReactions(message.reactions),
|
||||
deliveryStatus: message.deliveryStatus))
|
||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||
}
|
||||
|
||||
private func buildNoticeTimelineItemFromMessage(_ message: MessageTimelineItem<NoticeMessageContent>,
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildNoticeTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ message: MessageTimelineItem<NoticeMessageContent>,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
let attributedText = (message.htmlBody != nil ? attributedStringBuilder.fromHTML(message.htmlBody) : attributedStringBuilder.fromPlain(message.body))
|
||||
@@ -267,20 +340,22 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
text: message.body,
|
||||
attributedComponents: attributedComponents,
|
||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: message.isEditable,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: message.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
||||
reactions: aggregateReactions(message.reactions),
|
||||
deliveryStatus: message.deliveryStatus))
|
||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||
}
|
||||
|
||||
private func buildEmoteTimelineItemFromMessage(_ message: MessageTimelineItem<EmoteMessageContent>,
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
private func buildEmoteTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
||||
_ message: MessageTimelineItem<EmoteMessageContent>,
|
||||
_ isOutgoing: Bool,
|
||||
_ inGroupState: TimelineItemInGroupState,
|
||||
_ groupState: TimelineItemGroupState,
|
||||
_ displayName: String?,
|
||||
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
|
||||
let attributedText = (message.htmlBody != nil ? attributedStringBuilder.fromHTML(message.htmlBody) : attributedStringBuilder.fromPlain(message.body))
|
||||
@@ -290,15 +365,15 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
text: message.body,
|
||||
attributedComponents: attributedComponents,
|
||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
||||
inGroupState: inGroupState,
|
||||
groupState: groupState,
|
||||
isOutgoing: isOutgoing,
|
||||
isEditable: message.isEditable,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
senderId: message.sender,
|
||||
senderDisplayName: displayName,
|
||||
senderAvatar: avatarImage,
|
||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
||||
reactions: aggregateReactions(message.reactions),
|
||||
deliveryStatus: message.deliveryStatus))
|
||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||
}
|
||||
|
||||
private func aggregateReactions(_ reactions: [Reaction]) -> [AggregatedReaction] {
|
||||
|
||||
+1
-1
@@ -19,5 +19,5 @@ import Foundation
|
||||
@MainActor
|
||||
protocol RoomTimelineItemFactoryProtocol {
|
||||
func buildTimelineItemFor(eventItemProxy: EventTimelineItemProxy,
|
||||
inGroupState: TimelineItemInGroupState) -> RoomTimelineItemProtocol
|
||||
groupState: TimelineItemGroupState) -> RoomTimelineItemProtocol
|
||||
}
|
||||
|
||||
@@ -40,6 +40,14 @@ struct RoomTimelineViewFactory: RoomTimelineViewFactoryProtocol {
|
||||
return .encrypted(item)
|
||||
case let item as ReadMarkerRoomTimelineItem:
|
||||
return .readMarker(item)
|
||||
case let item as PaginationIndicatorRoomTimelineItem:
|
||||
return .paginationIndicator(item)
|
||||
case let item as StickerRoomTimelineItem:
|
||||
return .sticker(item)
|
||||
case let item as UnsupportedRoomTimelineItem:
|
||||
return .unsupported(item)
|
||||
case let item as TimelineStartRoomTimelineItem:
|
||||
return .timelineStart(item)
|
||||
default:
|
||||
fatalError("Unknown timeline item")
|
||||
}
|
||||
|
||||
@@ -28,7 +28,10 @@ enum RoomTimelineViewProvider: Identifiable, Hashable {
|
||||
case redacted(RedactedRoomTimelineItem)
|
||||
case encrypted(EncryptedRoomTimelineItem)
|
||||
case readMarker(ReadMarkerRoomTimelineItem)
|
||||
case backPaginationIndicator(Bool)
|
||||
case paginationIndicator(PaginationIndicatorRoomTimelineItem)
|
||||
case sticker(StickerRoomTimelineItem)
|
||||
case unsupported(UnsupportedRoomTimelineItem)
|
||||
case timelineStart(TimelineStartRoomTimelineItem)
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
@@ -52,8 +55,14 @@ enum RoomTimelineViewProvider: Identifiable, Hashable {
|
||||
return item.id
|
||||
case .readMarker(let item):
|
||||
return item.id
|
||||
case .backPaginationIndicator:
|
||||
return "BackpaginationLoadingIndicator"
|
||||
case .paginationIndicator(let item):
|
||||
return item.id
|
||||
case .sticker(let item):
|
||||
return item.id
|
||||
case .unsupported(let item):
|
||||
return item.id
|
||||
case .timelineStart(let item):
|
||||
return item.id
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,10 +90,14 @@ extension RoomTimelineViewProvider: View {
|
||||
EncryptedRoomTimelineView(timelineItem: item)
|
||||
case .readMarker(let item):
|
||||
ReadMarkerRoomTimelineView(timelineItem: item)
|
||||
case .backPaginationIndicator(let isBackPaginating):
|
||||
ProgressView()
|
||||
.frame(maxWidth: .infinity)
|
||||
.opacity(isBackPaginating ? 1.0 : 0.0)
|
||||
case .paginationIndicator(let item):
|
||||
PaginationIndicatorRoomTimelineView(timelineItem: item)
|
||||
case .sticker(let item):
|
||||
StickerRoomTimelineView(timelineItem: item)
|
||||
case .unsupported(let item):
|
||||
UnsupportedRoomTimelineView(timelineItem: item)
|
||||
case .timelineStart(let item):
|
||||
TimelineStartRoomTimelineView(timelineItem: item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user