From 05683967c042b17edf03bd161d2f9f4a6a190266 Mon Sep 17 00:00:00 2001 From: onurays Date: Fri, 6 Mar 2020 12:07:38 +0100 Subject: [PATCH] Code review fixes. --- matrix-sdk-android/build.gradle | 2 +- .../DefaultContentUploadStateTracker.kt | 17 +++++++++++++-- .../session/content/UploadContentWorker.kt | 21 +++++++++---------- .../session/room/send/DefaultSendService.kt | 2 +- vector/build.gradle | 2 +- .../action/MessageActionsViewModel.kt | 6 ++---- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 062b590acf..f980279a8d 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -126,7 +126,7 @@ dependencies { kapt 'dk.ilios:realmfieldnameshelper:1.1.1' // Work - implementation "androidx.work:work-runtime-ktx:2.3.0" + implementation "androidx.work:work-runtime-ktx:2.3.3" // FP implementation "io.arrow-kt:arrow-core:$arrow_version" diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt index 66a8341801..7a13d5f8a5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/DefaultContentUploadStateTracker.kt @@ -20,6 +20,7 @@ import android.os.Handler import android.os.Looper import im.vector.matrix.android.api.session.content.ContentUploadStateTracker import im.vector.matrix.android.internal.session.SessionScope +import timber.log.Timber import javax.inject.Inject @SessionScope @@ -33,7 +34,13 @@ internal class DefaultContentUploadStateTracker @Inject constructor() : ContentU val listeners = listeners.getOrPut(key) { ArrayList() } listeners.add(updateListener) val currentState = states[key] ?: ContentUploadStateTracker.State.Idle - mainHandler.post { updateListener.onUpdate(currentState) } + mainHandler.post { + try { + updateListener.onUpdate(currentState) + } catch (e: Exception) { + Timber.e(e, "## ContentUploadStateTracker.onUpdate() failed") + } + } } override fun untrack(key: String, updateListener: ContentUploadStateTracker.UpdateListener) { @@ -79,7 +86,13 @@ internal class DefaultContentUploadStateTracker @Inject constructor() : ContentU private fun updateState(key: String, state: ContentUploadStateTracker.State) { states[key] = state mainHandler.post { - listeners[key]?.forEach { it.onUpdate(state) } + listeners[key]?.forEach { + try { + it.onUpdate(state) + } catch (e: Exception) { + Timber.e(e, "## ContentUploadStateTracker.onUpdate() failed") + } + } } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt index 1c73a76a07..1dde25fd78 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/UploadContentWorker.kt @@ -58,7 +58,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter override val sessionId: String, val events: List, val attachment: ContentAttachmentData, - val isRoomEncrypted: Boolean, + val isEncrypted: Boolean, val compressBeforeSending: Boolean, override val lastFailureMessage: String? = null ) : SessionWorkerParams @@ -90,9 +90,11 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter Timber.e(e) notifyTracker(params) { contentUploadStateTracker.setFailure(it, e) } return Result.success( - WorkerParamsFactory.toData(params.copy( - lastFailureMessage = e.localizedMessage - )) + WorkerParamsFactory.toData( + params.copy( + lastFailureMessage = e.localizedMessage + ) + ) ) } .let { originalFile -> @@ -136,7 +138,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter } try { - val contentUploadResponse = if (params.isRoomEncrypted) { + val contentUploadResponse = if (params.isEncrypted) { Timber.v("Encrypt thumbnail") notifyTracker(params) { contentUploadStateTracker.setEncryptingThumbnail(it) } val encryptionResult = MXEncryptedAttachments.encryptAttachment(ByteArrayInputStream(thumbnailData.bytes), thumbnailData.mimeType) @@ -174,7 +176,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter var uploadedFileEncryptedFileInfo: EncryptedFileInfo? = null return try { - val contentUploadResponse = if (params.isRoomEncrypted) { + val contentUploadResponse = if (params.isEncrypted) { Timber.v("Encrypt file") notifyTracker(params) { contentUploadStateTracker.setEncrypting(it) } @@ -205,10 +207,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter return Result.success( WorkerParamsFactory.toData( - MultipleEventSendingDispatcherWorker.Params( - sessionId = params.sessionId, - events = params.events, - isEncrypted = params.isRoomEncrypted, + params.copy( lastFailureMessage = failure.localizedMessage ) ) @@ -229,7 +228,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter updateEvent(it, attachmentUrl, encryptedFileInfo, thumbnailUrl, thumbnailEncryptedFileInfo, newImageAttributes) } - val sendParams = MultipleEventSendingDispatcherWorker.Params(params.sessionId, updatedEvents, params.isRoomEncrypted) + val sendParams = MultipleEventSendingDispatcherWorker.Params(params.sessionId, updatedEvents, params.isEncrypted) return Result.success(WorkerParamsFactory.toData(sendParams)) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt index 58f4d4fc5e..a99337695a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt @@ -233,7 +233,7 @@ internal class DefaultSendService @AssistedInject constructor( val dispatcherWork = createMultipleEventDispatcherWork(isRoomEncrypted) workManagerProvider.workManager - .beginWith(uploadWork) + .beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork) .then(dispatcherWork) .enqueue() .also { operation -> diff --git a/vector/build.gradle b/vector/build.gradle index 988712d87e..6d24a26838 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -296,7 +296,7 @@ dependencies { implementation 'com.airbnb.android:mvrx:1.3.0' // Work - implementation "androidx.work:work-runtime-ktx:2.3.0-beta02" + implementation "androidx.work:work-runtime-ktx:2.3.3" // Paging implementation "androidx.paging:paging-runtime-ktx:2.1.1" diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index 0693df2fb0..1fe1db27d7 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -260,10 +260,8 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted add(EventSharedAction.ViewEditHistory(informationData)) } - if (canShare(msgType)) { - if (messageContent is MessageWithAttachmentContent) { - add(EventSharedAction.Share(timelineEvent.eventId, messageContent)) - } + if (canShare(msgType) && messageContent is MessageWithAttachmentContent) { + add(EventSharedAction.Share(timelineEvent.eventId, messageContent)) } if (timelineEvent.root.sendState == SendState.SENT) {