Better private method name

This commit is contained in:
Benoit Marty 2019-08-05 16:50:25 +02:00
parent 4deb7eb865
commit acae0fad3e
2 changed files with 12 additions and 11 deletions

View File

@ -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<FakeSendWorker>()
.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"
}


View File

@ -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))
}
}