Editing a failed echo, just cancels and resends it (#1207)

* editing a failed message means cancelling and resending it

* changelog
This commit is contained in:
Mauro 2023-06-29 16:37:52 +02:00 committed by GitHub
parent 3a6876f385
commit b2ab6103c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -64,7 +64,7 @@ enum TimelineItemMenuAction: Identifiable, Hashable {
var canAppearInFailedEcho: Bool {
switch self {
case .copy, .redact, .viewSource:
case .copy, .edit, .redact, .viewSource:
return true
default:
return false

View File

@ -151,11 +151,20 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
func editMessage(_ newMessage: String, original itemID: String) async {
MXLog.info("Edit message in \(roomID)")
switch await roomProxy.editMessage(newMessage, original: itemID) {
case .success:
MXLog.info("Finished editing message")
case .failure(let error):
MXLog.error("Failed editing message with error: \(error)")
if let timelineItem = timelineItems.first(where: { $0.id == itemID }),
let item = timelineItem as? EventBasedTimelineItemProtocol,
item.hasFailedToSend,
let transactionID = item.properties.transactionID {
MXLog.info("Editing a failed echo, will cancel and resend it as a new message")
await cancelSend(transactionID)
await sendMessage(newMessage)
} else {
switch await roomProxy.editMessage(newMessage, original: itemID) {
case .success:
MXLog.info("Finished editing message")
case .failure(let error):
MXLog.error("Failed editing message with error: \(error)")
}
}
}

View File

@ -0,0 +1 @@
Failed local echoes can be edited, they will just get cancelled and resent with the new content.