mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +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:
+3
-2
@@ -81,12 +81,13 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
|
||||
|
||||
func sendMessage(_ message: String,
|
||||
html: String?,
|
||||
inReplyTo itemID: TimelineItemIdentifier?,
|
||||
inReplyToEventID: String?,
|
||||
intentionalMentions: IntentionalMentions) async { }
|
||||
|
||||
func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async { }
|
||||
|
||||
func edit(_ timelineItemID: TimelineItemIdentifier,
|
||||
func edit(_ eventOrTransactionID: EventOrTransactionId,
|
||||
useTimeline: Bool,
|
||||
message: String,
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async { }
|
||||
|
||||
+16
-36
@@ -143,22 +143,13 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
|
||||
func sendMessage(_ message: String,
|
||||
html: String?,
|
||||
inReplyTo itemID: TimelineItemIdentifier?,
|
||||
inReplyToEventID: String?,
|
||||
intentionalMentions: IntentionalMentions) async {
|
||||
var inReplyTo: String?
|
||||
if itemID == nil {
|
||||
MXLog.info("Send message in \(roomID)")
|
||||
} else if let eventID = itemID?.eventID {
|
||||
inReplyTo = eventID
|
||||
MXLog.info("Send reply in \(roomID)")
|
||||
} else {
|
||||
MXLog.error("Send reply in \(roomID) failed: missing event ID")
|
||||
return
|
||||
}
|
||||
MXLog.info("Send message in \(roomID)")
|
||||
|
||||
switch await activeTimeline.sendMessage(message,
|
||||
html: html,
|
||||
inReplyTo: inReplyTo,
|
||||
inReplyToEventID: inReplyToEventID,
|
||||
intentionalMentions: intentionalMentions) {
|
||||
case .success:
|
||||
MXLog.info("Finished sending message")
|
||||
@@ -178,37 +169,31 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func edit(_ timelineItemID: TimelineItemIdentifier,
|
||||
func edit(_ eventOrTransactionID: EventOrTransactionId,
|
||||
useTimeline: Bool,
|
||||
message: String,
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async {
|
||||
MXLog.info("Edit message in \(roomID)")
|
||||
MXLog.info("Editing timeline item: \(timelineItemID)")
|
||||
|
||||
let editMode: EditMode
|
||||
if !timelineItemID.uniqueID.isEmpty,
|
||||
let timelineItem = liveTimelineProvider.itemProxies.firstEventTimelineItemUsingStableID(timelineItemID) {
|
||||
editMode = .byEvent(timelineItem)
|
||||
} else if let eventID = timelineItemID.eventID {
|
||||
editMode = .byID(eventID)
|
||||
} else {
|
||||
MXLog.error("Unknown timeline item: \(timelineItemID)")
|
||||
return
|
||||
}
|
||||
MXLog.info("Editing timeline item: \(eventOrTransactionID)")
|
||||
|
||||
let messageContent = activeTimeline.buildMessageContentFor(message,
|
||||
html: html,
|
||||
intentionalMentions: intentionalMentions.toRustMentions())
|
||||
|
||||
switch editMode {
|
||||
case let .byEvent(item):
|
||||
switch await activeTimeline.edit(item, newContent: messageContent) {
|
||||
if useTimeline {
|
||||
switch await activeTimeline.edit(eventOrTransactionID, newContent: messageContent) {
|
||||
case .success:
|
||||
MXLog.info("Finished editing message by event")
|
||||
case let .failure(error):
|
||||
MXLog.error("Failed editing message by event with error: \(error)")
|
||||
}
|
||||
case let .byID(eventID):
|
||||
} else {
|
||||
guard case let .eventId(eventID) = eventOrTransactionID else {
|
||||
MXLog.error("Failed editing message, missing eventID.")
|
||||
return
|
||||
}
|
||||
|
||||
switch await roomProxy.edit(eventID: eventID, newContent: messageContent) {
|
||||
case .success:
|
||||
MXLog.info("Finished editing message by event ID")
|
||||
@@ -398,9 +383,9 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
let date = Date(timeIntervalSince1970: TimeInterval(timestamp / 1000))
|
||||
let dateString = date.formatted(date: .complete, time: .omitted)
|
||||
|
||||
return SeparatorRoomTimelineItem(id: .init(uniqueID: dateString), text: dateString)
|
||||
return SeparatorRoomTimelineItem(id: .virtual(uniqueID: uniqueID), text: dateString)
|
||||
case .readMarker:
|
||||
return ReadMarkerRoomTimelineItem(id: .init(uniqueID: uniqueID))
|
||||
return ReadMarkerRoomTimelineItem(id: .virtual(uniqueID: uniqueID))
|
||||
}
|
||||
case .unknown:
|
||||
return nil
|
||||
@@ -453,8 +438,3 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private enum EditMode {
|
||||
case byEvent(EventTimelineItem)
|
||||
case byID(String)
|
||||
}
|
||||
|
||||
+3
-13
@@ -48,10 +48,11 @@ protocol RoomTimelineControllerProtocol {
|
||||
|
||||
func sendMessage(_ message: String,
|
||||
html: String?,
|
||||
inReplyTo itemID: TimelineItemIdentifier?,
|
||||
inReplyToEventID: String?,
|
||||
intentionalMentions: IntentionalMentions) async
|
||||
|
||||
func edit(_ timelineItemID: TimelineItemIdentifier,
|
||||
func edit(_ eventOrTransactionID: EventOrTransactionId,
|
||||
useTimeline: Bool,
|
||||
message: String,
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async
|
||||
@@ -72,14 +73,3 @@ protocol RoomTimelineControllerProtocol {
|
||||
|
||||
func eventTimestamp(for itemID: TimelineItemIdentifier) -> Date?
|
||||
}
|
||||
|
||||
extension RoomTimelineControllerProtocol {
|
||||
func sendMessage(_ message: String,
|
||||
html: String?,
|
||||
intentionalMentions: IntentionalMentions) async {
|
||||
await sendMessage(message,
|
||||
html: html,
|
||||
inReplyTo: nil,
|
||||
intentionalMentions: intentionalMentions)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user