mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Refactor theTimelineItemIdentifier handling; stop relying on optional EventOrTransactionIds and be explicit when setting composer modes from the draft service.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// Copyright 2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
/// A timeline item identifier
|
||||
/// - uniqueID: Stable id across state changes of the timeline item, it uniquely identifies an item in a timeline.
|
||||
/// Its value is consistent only per timeline instance, it should **not** be used to identify an item across timeline instances.
|
||||
/// - eventOrTransactionID: Contains the 2 possible identifiers of an event, either it has a remote event id or
|
||||
/// a local transaction id, never both or none.
|
||||
enum TimelineItemIdentifier: Hashable {
|
||||
case event(uniqueID: String, eventOrTransactionID: EventOrTransactionId)
|
||||
case virtual(uniqueID: String)
|
||||
|
||||
var uniqueID: String {
|
||||
switch self {
|
||||
case .event(let uniqueID, _):
|
||||
return uniqueID
|
||||
case .virtual(let uniqueID):
|
||||
return uniqueID
|
||||
}
|
||||
}
|
||||
|
||||
var eventID: String? {
|
||||
guard case let .event(_, eventOrTransactionID) = self else {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch eventOrTransactionID {
|
||||
case .eventId(let eventID):
|
||||
return eventID
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var transactionID: String? {
|
||||
guard case let .event(_, eventOrTransactionID) = self else {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch eventOrTransactionID {
|
||||
case .transactionId(let transactionID):
|
||||
return transactionID
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Mocks
|
||||
|
||||
extension TimelineItemIdentifier {
|
||||
static var randomEvent: Self {
|
||||
.event(uniqueID: UUID().uuidString, eventOrTransactionID: .eventId(eventId: UUID().uuidString))
|
||||
}
|
||||
|
||||
static var randomVirtual: Self {
|
||||
.virtual(uniqueID: UUID().uuidString)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user