Start chain: add missing cases

This commit is contained in:
Benoit Marty 2019-08-06 15:15:40 +02:00
parent 4009f2c176
commit d82fd10f3b
4 changed files with 34 additions and 11 deletions

View File

@ -115,7 +115,7 @@ internal class DefaultRelationService @Inject constructor(private val context: C
eventId, eventId,
reason) reason)
val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
return TimelineSendEventWorkCommon.createWork<RedactEventWorker>(redactWorkData) return TimelineSendEventWorkCommon.createWork<RedactEventWorker>(redactWorkData, true)
} }


override fun editTextMessage(targetEventId: String, override fun editTextMessage(targetEventId: String,
@ -199,14 +199,13 @@ internal class DefaultRelationService @Inject constructor(private val context: C
// Same parameter // Same parameter
val params = EncryptEventWorker.Params(credentials.userId, roomId, event, keepKeys) val params = EncryptEventWorker.Params(credentials.userId, roomId, event, keepKeys)
val sendWorkData = WorkerParamsFactory.toData(params) val sendWorkData = WorkerParamsFactory.toData(params)
return TimelineSendEventWorkCommon.createWork<EncryptEventWorker>(sendWorkData) return TimelineSendEventWorkCommon.createWork<EncryptEventWorker>(sendWorkData, true)
} }


private fun createSendEventWork(event: Event): OneTimeWorkRequest { private fun createSendEventWork(event: Event): OneTimeWorkRequest {
val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event) val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event)
val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
val workRequest = TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData) return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData, true)
return workRequest
} }


override fun getEventSummaryLive(eventId: String): LiveData<EventAnnotationsSummary> { override fun getEventSummaryLive(eventId: String): LiveData<EventAnnotationsSummary> {

View File

@ -80,11 +80,11 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
return if (cryptoService.isRoomEncrypted(roomId)) { return if (cryptoService.isRoomEncrypted(roomId)) {
Timber.v("Send event in encrypted room") Timber.v("Send event in encrypted room")
val encryptWork = createEncryptEventWork(event, true) val encryptWork = createEncryptEventWork(event, true)
val sendWork = createSendEventWork(event) val sendWork = createSendEventWork(event, false)
TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, sendWork) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, sendWork)
CancelableWork(context, encryptWork.id) CancelableWork(context, encryptWork.id)
} else { } else {
val sendWork = createSendEventWork(event) val sendWork = createSendEventWork(event, true)
TimelineSendEventWorkCommon.postWork(context, roomId, sendWork) TimelineSendEventWorkCommon.postWork(context, roomId, sendWork)
CancelableWork(context, sendWork.id) CancelableWork(context, sendWork.id)
} }
@ -245,7 +245,7 @@ internal class DefaultSendService @Inject constructor(private val context: Conte
val isRoomEncrypted = cryptoService.isRoomEncrypted(roomId) val isRoomEncrypted = cryptoService.isRoomEncrypted(roomId)


val uploadWork = createUploadMediaWork(localEcho, attachment, isRoomEncrypted, startChain = true) val uploadWork = createUploadMediaWork(localEcho, attachment, isRoomEncrypted, startChain = true)
val sendWork = createSendEventWork(localEcho) val sendWork = createSendEventWork(localEcho, false)


if (isRoomEncrypted) { if (isRoomEncrypted) {
val encryptWork = createEncryptEventWork(localEcho, false /*not start of chain, take input error*/) 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() .build()
} }


private fun createSendEventWork(event: Event): OneTimeWorkRequest { private fun createSendEventWork(event: Event, startChain: Boolean): OneTimeWorkRequest {
val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event) val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event)
val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)


return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData) return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData, startChain)
} }


private fun createRedactEventWork(event: Event, reason: String?): OneTimeWorkRequest { 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 sendContentWorkerParams = RedactEventWorker.Params(credentials.userId, redactEvent.eventId!!, roomId, event.eventId, reason)
val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) val redactWorkData = WorkerParamsFactory.toData(sendContentWorkerParams)
return TimelineSendEventWorkCommon.createWork<RedactEventWorker>(redactWorkData) return TimelineSendEventWorkCommon.createWork<RedactEventWorker>(redactWorkData, true)
} }


private fun createUploadMediaWork(event: Event, private fun createUploadMediaWork(event: Event,

View File

@ -17,6 +17,7 @@ package im.vector.matrix.android.internal.session.room.timeline


import android.content.Context import android.content.Context
import androidx.work.* 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
import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder import im.vector.matrix.android.internal.worker.WorkManagerUtil.matrixOneTimeWorkRequestBuilder
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -57,9 +58,14 @@ internal object TimelineSendEventWorkCommon {
.enqueue() .enqueue()
} }


inline fun <reified W : ListenableWorker> createWork(data: Data): OneTimeWorkRequest { inline fun <reified W : ListenableWorker> createWork(data: Data, startChain: Boolean): OneTimeWorkRequest {
return matrixOneTimeWorkRequestBuilder<W>() return matrixOneTimeWorkRequestBuilder<W>()
.setConstraints(WorkManagerUtil.workConstraints) .setConstraints(WorkManagerUtil.workConstraints)
.apply {
if (startChain) {
setInputMerger(NoMerger::class.java)
}
}
.setInputData(data) .setInputData(data)
.setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS) .setBackoffCriteria(BackoffPolicy.LINEAR, BACKOFF_DELAY, TimeUnit.MILLISECONDS)
.build() .build()

View File

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