diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/SendService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/SendService.kt index fd596de328..b8e536cb33 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/SendService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/send/SendService.kt @@ -110,13 +110,13 @@ interface SendService { * Schedule this message to be resent * @param localEcho the unsent local echo */ - fun resendTextMessage(localEcho: TimelineEvent): Cancelable? + fun resendTextMessage(localEcho: TimelineEvent): Cancelable /** * Schedule this message to be resent * @param localEcho the unsent local echo */ - fun resendMediaMessage(localEcho: TimelineEvent): Cancelable? + fun resendMediaMessage(localEcho: TimelineEvent): Cancelable /** * Remove this failed message from the timeline diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt index 4ac3beb432..95cd1c699c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/DefaultSendService.kt @@ -45,6 +45,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.util.Cancelable import org.matrix.android.sdk.api.util.CancelableBag import org.matrix.android.sdk.api.util.JsonDict +import org.matrix.android.sdk.api.util.NoOpCancellable import org.matrix.android.sdk.internal.di.SessionId import org.matrix.android.sdk.internal.di.WorkManagerProvider import org.matrix.android.sdk.internal.session.content.UploadContentWorker @@ -137,28 +138,28 @@ internal class DefaultSendService @AssistedInject constructor( .let { timelineSendEventWorkCommon.postWork(roomId, it) } } - override fun resendTextMessage(localEcho: TimelineEvent): Cancelable? { + override fun resendTextMessage(localEcho: TimelineEvent): Cancelable { if (localEcho.root.isTextMessage() && localEcho.root.sendState.hasFailed()) { localEchoRepository.updateSendState(localEcho.eventId, SendState.UNSENT) return sendEvent(localEcho.root) } - return null + return NoOpCancellable } - override fun resendMediaMessage(localEcho: TimelineEvent): Cancelable? { + override fun resendMediaMessage(localEcho: TimelineEvent): Cancelable { if (localEcho.root.sendState.hasFailed()) { val clearContent = localEcho.root.getClearContent() - val messageContent = clearContent?.toModel() as? MessageWithAttachmentContent ?: return null + val messageContent = clearContent?.toModel() as? MessageWithAttachmentContent ?: return NoOpCancellable - val url = messageContent.getFileUrl() ?: return null + val url = messageContent.getFileUrl() ?: return NoOpCancellable if (url.startsWith("mxc://")) { // We need to resend only the message as the attachment is ok localEchoRepository.updateSendState(localEcho.eventId, SendState.UNSENT) return sendEvent(localEcho.root) } - // we need to resend the media - when (messageContent) { + // we need to resend the media + return when (messageContent) { is MessageImageContent -> { // The image has not yet been sent val attachmentData = ContentAttachmentData( @@ -171,7 +172,7 @@ internal class DefaultSendService @AssistedInject constructor( type = ContentAttachmentData.Type.IMAGE ) localEchoRepository.updateSendState(localEcho.eventId, SendState.UNSENT) - return internalSendMedia(listOf(localEcho.root), attachmentData, true) + internalSendMedia(listOf(localEcho.root), attachmentData, true) } is MessageVideoContent -> { val attachmentData = ContentAttachmentData( @@ -185,9 +186,9 @@ internal class DefaultSendService @AssistedInject constructor( type = ContentAttachmentData.Type.VIDEO ) localEchoRepository.updateSendState(localEcho.eventId, SendState.UNSENT) - return internalSendMedia(listOf(localEcho.root), attachmentData, true) + internalSendMedia(listOf(localEcho.root), attachmentData, true) } - is MessageFileContent -> { + is MessageFileContent -> { val attachmentData = ContentAttachmentData( size = messageContent.info!!.size, mimeType = messageContent.info.mimeType!!, @@ -196,7 +197,7 @@ internal class DefaultSendService @AssistedInject constructor( type = ContentAttachmentData.Type.FILE ) localEchoRepository.updateSendState(localEcho.eventId, SendState.UNSENT) - return internalSendMedia(listOf(localEcho.root), attachmentData, true) + internalSendMedia(listOf(localEcho.root), attachmentData, true) } is MessageAudioContent -> { val attachmentData = ContentAttachmentData( @@ -208,12 +209,12 @@ internal class DefaultSendService @AssistedInject constructor( type = ContentAttachmentData.Type.AUDIO ) localEchoRepository.updateSendState(localEcho.eventId, SendState.UNSENT) - return internalSendMedia(listOf(localEcho.root), attachmentData, true) + internalSendMedia(listOf(localEcho.root), attachmentData, true) } + else -> NoOpCancellable } - return null } - return null + return NoOpCancellable } override fun deleteFailedEcho(localEcho: TimelineEvent) {