From d82fd10f3b3e29f2f6184bf4ea9ffd25814bf7c0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 6 Aug 2019 15:15:40 +0200 Subject: [PATCH] Start chain: add missing cases --- .../room/relation/DefaultRelationService.kt | 7 +++---- .../session/room/send/DefaultSendService.kt | 12 ++++++------ .../timeline/TimelineSendEventWorkCommon.kt | 8 +++++++- .../android/internal/worker/Extensions.kt | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Extensions.kt diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt index b5a0e50e12..cd31c9780f 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/relation/DefaultRelationService.kt @@ -115,7 +115,7 @@ internal class DefaultRelationService @Inject constructor(private val context: C eventId, reason) val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) - return TimelineSendEventWorkCommon.createWork(redactWorkData) + return TimelineSendEventWorkCommon.createWork(redactWorkData, true) } override fun editTextMessage(targetEventId: String, @@ -199,14 +199,13 @@ internal class DefaultRelationService @Inject constructor(private val context: C // Same parameter val params = EncryptEventWorker.Params(credentials.userId, roomId, event, keepKeys) val sendWorkData = WorkerParamsFactory.toData(params) - return TimelineSendEventWorkCommon.createWork(sendWorkData) + return TimelineSendEventWorkCommon.createWork(sendWorkData, true) } private fun createSendEventWork(event: Event): OneTimeWorkRequest { val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) - val workRequest = TimelineSendEventWorkCommon.createWork(sendWorkData) - return workRequest + return TimelineSendEventWorkCommon.createWork(sendWorkData, true) } override fun getEventSummaryLive(eventId: String): LiveData { 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 b4759c416b..34260cb2be 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 @@ -80,11 +80,11 @@ internal class DefaultSendService @Inject constructor(private val context: Conte return if (cryptoService.isRoomEncrypted(roomId)) { Timber.v("Send event in encrypted room") val encryptWork = createEncryptEventWork(event, true) - val sendWork = createSendEventWork(event) + val sendWork = createSendEventWork(event, false) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, sendWork) CancelableWork(context, encryptWork.id) } else { - val sendWork = createSendEventWork(event) + val sendWork = createSendEventWork(event, true) TimelineSendEventWorkCommon.postWork(context, roomId, sendWork) CancelableWork(context, sendWork.id) } @@ -245,7 +245,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte val isRoomEncrypted = cryptoService.isRoomEncrypted(roomId) val uploadWork = createUploadMediaWork(localEcho, attachment, isRoomEncrypted, startChain = true) - val sendWork = createSendEventWork(localEcho) + val sendWork = createSendEventWork(localEcho, false) if (isRoomEncrypted) { val encryptWork = createEncryptEventWork(localEcho, false /*not start of chain, take input error*/) @@ -297,11 +297,11 @@ internal class DefaultSendService @Inject constructor(private val context: Conte .build() } - private fun createSendEventWork(event: Event): OneTimeWorkRequest { + private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest { val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) - return TimelineSendEventWorkCommon.createWork(sendWorkData) + return TimelineSendEventWorkCommon.createWork(sendWorkData, startChain) } private fun createRedactEventWork(event: Event, reason: String?): OneTimeWorkRequest { @@ -310,7 +310,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte } val sendContentWorkerParams = RedactEventWorker.Params(credentials.userId, redactEvent.eventId!!, roomId, event.eventId, reason) val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) - return TimelineSendEventWorkCommon.createWork(redactWorkData) + return TimelineSendEventWorkCommon.createWork(redactWorkData, true) } private fun createUploadMediaWork(event: Event, 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 2a72d3ff88..71d6f5d48d 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 @@ -17,6 +17,7 @@ package im.vector.matrix.android.internal.session.room.timeline import android.content.Context import androidx.work.* +import im.vector.matrix.android.internal.session.room.send.NoMerger import im.vector.matrix.android.internal.worker.WorkManagerUtil import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder import java.util.concurrent.TimeUnit @@ -57,9 +58,14 @@ internal object TimelineSendEventWorkCommon { .enqueue() } - inline fun createWork(data: Data): OneTimeWorkRequest { + inline fun createWork(data: Data, startChain: Boolean): OneTimeWorkRequest { return matrixOneTimeWorkRequestBuilder() .setConstraints(WorkManagerUtil.workConstraints) + .apply { + if (startChain) { + setInputMerger(NoMerger::class.java) + } + } .setInputData(data) .setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS) .build() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Extensions.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Extensions.kt new file mode 100644 index 0000000000..286303953b --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/worker/Extensions.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.matrix.android.internal.worker +