Better private method name
This commit is contained in:
parent
4deb7eb865
commit
acae0fad3e
|
@ -161,15 +161,16 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
||||||
|
|
||||||
override fun clearSendingQueue() {
|
override fun clearSendingQueue() {
|
||||||
TimelineSendEventWorkCommon.cancelAllWorks(context, roomId)
|
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>()
|
matrixOneTimeWorkRequestBuilder<FakeSendWorker>()
|
||||||
.build().let {
|
.build().let {
|
||||||
TimelineSendEventWorkCommon.postWork(context, roomId, it, ExistingWorkPolicy.REPLACE)
|
TimelineSendEventWorkCommon.postWork(context, roomId, it, ExistingWorkPolicy.REPLACE)
|
||||||
|
|
||||||
//need to clear also image sending queue
|
//need to clear also image sending queue
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(buildWorkIdentifier(UPLOAD_WORK), ExistingWorkPolicy.REPLACE, it)
|
.beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.REPLACE, it)
|
||||||
.enqueue()
|
.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 encryptWork = createEncryptEventWork(localEcho, false /*not start of chain, take input error*/)
|
||||||
|
|
||||||
val op: Operation = WorkManager.getInstance(context)
|
val op: Operation = WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(buildWorkIdentifier(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork)
|
.beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork)
|
||||||
.then(encryptWork)
|
.then(encryptWork)
|
||||||
.then(sendWork)
|
.then(sendWork)
|
||||||
.enqueue()
|
.enqueue()
|
||||||
op.result.addListener(Runnable {
|
op.result.addListener(Runnable {
|
||||||
if (op.result.isCancelled) {
|
if (op.result.isCancelled) {
|
||||||
Timber.e("CHAINE WAS CANCELLED")
|
Timber.e("CHAIN WAS CANCELLED")
|
||||||
} else if (op.state.value is Operation.State.FAILURE) {
|
} else if (op.state.value is Operation.State.FAILURE) {
|
||||||
Timber.e("CHAINE DID FAIL")
|
Timber.e("CHAIN DID FAIL")
|
||||||
}
|
}
|
||||||
}, workerFutureListenerExecutor)
|
}, workerFutureListenerExecutor)
|
||||||
} else {
|
} else {
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(buildWorkIdentifier(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork)
|
.beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork)
|
||||||
.then(sendWork)
|
.then(sendWork)
|
||||||
.enqueue()
|
.enqueue()
|
||||||
}
|
}
|
||||||
|
@ -274,7 +275,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
|
||||||
localEchoEventFactory.saveLocalEcho(monarchy, event)
|
localEchoEventFactory.saveLocalEcho(monarchy, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildWorkIdentifier(identifier: String): String {
|
private fun buildWorkName(identifier: String): String {
|
||||||
return "${roomId}_$identifier"
|
return "${roomId}_$identifier"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ internal object TimelineSendEventWorkCommon {
|
||||||
else -> {
|
else -> {
|
||||||
val firstWork = workRequests.first()
|
val firstWork = workRequests.first()
|
||||||
var continuation = WorkManager.getInstance(context)
|
var continuation = WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(buildWorkIdentifier(roomId), ExistingWorkPolicy.APPEND, firstWork)
|
.beginUniqueWork(buildWorkName(roomId), ExistingWorkPolicy.APPEND, firstWork)
|
||||||
for (i in 1 until workRequests.size) {
|
for (i in 1 until workRequests.size) {
|
||||||
val workRequest = workRequests[i]
|
val workRequest = workRequests[i]
|
||||||
continuation = continuation.then(workRequest)
|
continuation = continuation.then(workRequest)
|
||||||
|
@ -53,7 +53,7 @@ internal object TimelineSendEventWorkCommon {
|
||||||
|
|
||||||
fun postWork(context: Context, roomId: String, workRequest: OneTimeWorkRequest, policy: ExistingWorkPolicy = ExistingWorkPolicy.APPEND) {
|
fun postWork(context: Context, roomId: String, workRequest: OneTimeWorkRequest, policy: ExistingWorkPolicy = ExistingWorkPolicy.APPEND) {
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(buildWorkIdentifier(roomId), policy, workRequest)
|
.beginUniqueWork(buildWorkName(roomId), policy, workRequest)
|
||||||
.enqueue()
|
.enqueue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,11 +65,11 @@ internal object TimelineSendEventWorkCommon {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildWorkIdentifier(roomId: String): String {
|
private fun buildWorkName(roomId: String): String {
|
||||||
return "${roomId}_$SEND_WORK"
|
return "${roomId}_$SEND_WORK"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancelAllWorks(context: Context, roomId: String) {
|
fun cancelAllWorks(context: Context, roomId: String) {
|
||||||
WorkManager.getInstance(context).cancelUniqueWork(buildWorkIdentifier(roomId))
|
WorkManager.getInstance(context).cancelUniqueWork(buildWorkName(roomId))
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue