diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt index d052755d3d..5537ea3288 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt @@ -304,11 +304,9 @@ class MessagesPresenter @AssistedInject constructor( } private suspend fun handleActionRedact(event: TimelineItem.Event) { - if (event.failedToSend) { - // If the message hasn't been sent yet, just cancel it - event.transactionId?.let { room.cancelSend(it) } - } else if (event.eventId != null) { - room.redactEvent(event.eventId) + timelineController.invokeOnCurrentTimeline { + redactEvent(eventId = event.eventId, transactionId = event.transactionId, reason = null) + .onFailure { Timber.e(it) } } } diff --git a/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/data/PollRepository.kt b/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/data/PollRepository.kt index e8d2506408..d1902facb7 100644 --- a/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/data/PollRepository.kt +++ b/features/poll/impl/src/main/kotlin/io/element/android/features/poll/impl/data/PollRepository.kt @@ -68,8 +68,12 @@ class PollRepository @Inject constructor( suspend fun deletePoll( pollStartId: EventId, - ): Result = - room.redactEvent( - eventId = pollStartId, - ) + ): Result = + timelineProvider + .getActiveTimeline() + .redactEvent( + eventId = pollStartId, + transactionId = null, + reason = null, + ) } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt index 39484b69be..7ba0ad35ca 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt @@ -130,8 +130,6 @@ interface MatrixRoom : Closeable { suspend fun sendMessage(body: String, htmlBody: String?, mentions: List): Result - suspend fun redactEvent(eventId: EventId, reason: String? = null): Result - suspend fun sendImage( file: File, thumbnailFile: File?, diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt index 9600410557..e2a3ffef8c 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt @@ -324,12 +324,6 @@ class RustMatrixRoom( return liveTimeline.sendMessage(body, htmlBody, mentions) } - override suspend fun redactEvent(eventId: EventId, reason: String?) = withContext(roomDispatcher) { - runCatching { - innerRoom.redact(eventId.value, reason) - } - } - override suspend fun leave(): Result = withContext(roomDispatcher) { runCatching { innerRoom.leave() diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt index 4b4a8e1af0..c2db4b83dd 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/room/FakeMatrixRoom.kt @@ -112,7 +112,7 @@ class FakeMatrixRoom( private var updateUserRoleResult = Result.success(Unit) private var toggleReactionResult = Result.success(Unit) private var retrySendMessageResult = Result.success(Unit) - private var cancelSendResult = Result.success(Unit) + private var cancelSendResult = Result.success(true) private var forwardEventResult = Result.success(Unit) private var reportContentResult = Result.success(Unit) private var kickUserResult = Result.success(Unit) @@ -281,7 +281,7 @@ class FakeMatrixRoom( return retrySendMessageResult } - override suspend fun cancelSend(transactionId: TransactionId): Result { + override suspend fun cancelSend(transactionId: TransactionId): Result { cancelSendCount++ return cancelSendResult } @@ -294,14 +294,6 @@ class FakeMatrixRoom( return eventPermalinkResult(eventId) } - var redactEventEventIdParam: EventId? = null - private set - - override suspend fun redactEvent(eventId: EventId, reason: String?): Result { - redactEventEventIdParam = eventId - return Result.success(Unit) - } - override suspend fun leave(): Result { return leaveRoomLambda() } @@ -626,7 +618,7 @@ class FakeMatrixRoom( retrySendMessageResult = result } - fun givenCancelSendResult(result: Result) { + fun givenCancelSendResult(result: Result) { cancelSendResult = result }