From acae0fad3ec8dee042b7a600b4b5b38491d13c5b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 5 Aug 2019 16:50:25 +0200 Subject: [PATCH] Better private method name --- .../session/room/send/DefaultSendService.kt | 15 ++++++++------- .../room/timeline/TimelineSendEventWorkCommon.kt | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) 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 b1b2d7a3b4..1d8eaf3f20 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 @@ -161,15 +161,16 @@ internal class DefaultSendService @Inject constructor(private val context: Conte override fun clearSendingQueue() { TimelineSendEventWorkCommon.cancelAllWorks(context, roomId) - WorkManager.getInstance(context).cancelUniqueWork(buildWorkIdentifier(UPLOAD_WORK)) + WorkManager.getInstance(context).cancelUniqueWork(buildWorkName(UPLOAD_WORK)) + // TODO Valere: what is the aim of this code ? Cancellation above is not enough? matrixOneTimeWorkRequestBuilder() .build().let { TimelineSendEventWorkCommon.postWork(context, roomId, it, ExistingWorkPolicy.REPLACE) //need to clear also image sending queue WorkManager.getInstance(context) - .beginUniqueWork(buildWorkIdentifier(UPLOAD_WORK), ExistingWorkPolicy.REPLACE, it) + .beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.REPLACE, it) .enqueue() } @@ -249,20 +250,20 @@ internal class DefaultSendService @Inject constructor(private val context: Conte val encryptWork = createEncryptEventWork(localEcho, false /*not start of chain, take input error*/) val op: Operation = WorkManager.getInstance(context) - .beginUniqueWork(buildWorkIdentifier(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork) + .beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork) .then(encryptWork) .then(sendWork) .enqueue() op.result.addListener(Runnable { if (op.result.isCancelled) { - Timber.e("CHAINE WAS CANCELLED") + Timber.e("CHAIN WAS CANCELLED") } else if (op.state.value is Operation.State.FAILURE) { - Timber.e("CHAINE DID FAIL") + Timber.e("CHAIN DID FAIL") } }, workerFutureListenerExecutor) } else { WorkManager.getInstance(context) - .beginUniqueWork(buildWorkIdentifier(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork) + .beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork) .then(sendWork) .enqueue() } @@ -274,7 +275,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte localEchoEventFactory.saveLocalEcho(monarchy, event) } - private fun buildWorkIdentifier(identifier: String): String { + private fun buildWorkName(identifier: String): String { return "${roomId}_$identifier" } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt index e75bb91bf0..2a72d3ff88 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineSendEventWorkCommon.kt @@ -41,7 +41,7 @@ internal object TimelineSendEventWorkCommon { else -> { val firstWork = workRequests.first() var continuation = WorkManager.getInstance(context) - .beginUniqueWork(buildWorkIdentifier(roomId), ExistingWorkPolicy.APPEND, firstWork) + .beginUniqueWork(buildWorkName(roomId), ExistingWorkPolicy.APPEND, firstWork) for (i in 1 until workRequests.size) { val workRequest = workRequests[i] continuation = continuation.then(workRequest) @@ -53,7 +53,7 @@ internal object TimelineSendEventWorkCommon { fun postWork(context: Context, roomId: String, workRequest: OneTimeWorkRequest, policy: ExistingWorkPolicy = ExistingWorkPolicy.APPEND) { WorkManager.getInstance(context) - .beginUniqueWork(buildWorkIdentifier(roomId), policy, workRequest) + .beginUniqueWork(buildWorkName(roomId), policy, workRequest) .enqueue() } @@ -65,11 +65,11 @@ internal object TimelineSendEventWorkCommon { .build() } - private fun buildWorkIdentifier(roomId: String): String { + private fun buildWorkName(roomId: String): String { return "${roomId}_$SEND_WORK" } fun cancelAllWorks(context: Context, roomId: String) { - WorkManager.getInstance(context).cancelUniqueWork(buildWorkIdentifier(roomId)) + WorkManager.getInstance(context).cancelUniqueWork(buildWorkName(roomId)) } } \ No newline at end of file