Code review fixes.

This commit is contained in:
onurays 2020-03-06 12:07:38 +01:00
parent 03d2cd0639
commit 05683967c0
6 changed files with 30 additions and 20 deletions

View File

@ -126,7 +126,7 @@ dependencies {
kapt 'dk.ilios:realmfieldnameshelper:1.1.1' kapt 'dk.ilios:realmfieldnameshelper:1.1.1'
// Work // Work
implementation "androidx.work:work-runtime-ktx:2.3.0" implementation "androidx.work:work-runtime-ktx:2.3.3"
// FP // FP
implementation "io.arrow-kt:arrow-core:$arrow_version" implementation "io.arrow-kt:arrow-core:$arrow_version"

View File

@ -20,6 +20,7 @@ import android.os.Handler
import android.os.Looper import android.os.Looper
import im.vector.matrix.android.api.session.content.ContentUploadStateTracker import im.vector.matrix.android.api.session.content.ContentUploadStateTracker
import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.SessionScope
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@SessionScope @SessionScope
@ -33,7 +34,13 @@ internal class DefaultContentUploadStateTracker @Inject constructor() : ContentU
val listeners = listeners.getOrPut(key) { ArrayList() } val listeners = listeners.getOrPut(key) { ArrayList() }
listeners.add(updateListener) listeners.add(updateListener)
val currentState = states[key] ?: ContentUploadStateTracker.State.Idle val currentState = states[key] ?: ContentUploadStateTracker.State.Idle
mainHandler.post { updateListener.onUpdate(currentState) } mainHandler.post {
try {
updateListener.onUpdate(currentState)
} catch (e: Exception) {
Timber.e(e, "## ContentUploadStateTracker.onUpdate() failed")
}
}
} }
override fun untrack(key: String, updateListener: ContentUploadStateTracker.UpdateListener) { override fun untrack(key: String, updateListener: ContentUploadStateTracker.UpdateListener) {
@ -79,7 +86,13 @@ internal class DefaultContentUploadStateTracker @Inject constructor() : ContentU
private fun updateState(key: String, state: ContentUploadStateTracker.State) { private fun updateState(key: String, state: ContentUploadStateTracker.State) {
states[key] = state states[key] = state
mainHandler.post { mainHandler.post {
listeners[key]?.forEach { it.onUpdate(state) } listeners[key]?.forEach {
try {
it.onUpdate(state)
} catch (e: Exception) {
Timber.e(e, "## ContentUploadStateTracker.onUpdate() failed")
}
}
} }
} }
} }

View File

@ -58,7 +58,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
override val sessionId: String, override val sessionId: String,
val events: List<Event>, val events: List<Event>,
val attachment: ContentAttachmentData, val attachment: ContentAttachmentData,
val isRoomEncrypted: Boolean, val isEncrypted: Boolean,
val compressBeforeSending: Boolean, val compressBeforeSending: Boolean,
override val lastFailureMessage: String? = null override val lastFailureMessage: String? = null
) : SessionWorkerParams ) : SessionWorkerParams
@ -90,9 +90,11 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
Timber.e(e) Timber.e(e)
notifyTracker(params) { contentUploadStateTracker.setFailure(it, e) } notifyTracker(params) { contentUploadStateTracker.setFailure(it, e) }
return Result.success( return Result.success(
WorkerParamsFactory.toData(params.copy( WorkerParamsFactory.toData(
params.copy(
lastFailureMessage = e.localizedMessage lastFailureMessage = e.localizedMessage
)) )
)
) )
} }
.let { originalFile -> .let { originalFile ->
@ -136,7 +138,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
} }
try { try {
val contentUploadResponse = if (params.isRoomEncrypted) { val contentUploadResponse = if (params.isEncrypted) {
Timber.v("Encrypt thumbnail") Timber.v("Encrypt thumbnail")
notifyTracker(params) { contentUploadStateTracker.setEncryptingThumbnail(it) } notifyTracker(params) { contentUploadStateTracker.setEncryptingThumbnail(it) }
val encryptionResult = MXEncryptedAttachments.encryptAttachment(ByteArrayInputStream(thumbnailData.bytes), thumbnailData.mimeType) val encryptionResult = MXEncryptedAttachments.encryptAttachment(ByteArrayInputStream(thumbnailData.bytes), thumbnailData.mimeType)
@ -174,7 +176,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
var uploadedFileEncryptedFileInfo: EncryptedFileInfo? = null var uploadedFileEncryptedFileInfo: EncryptedFileInfo? = null
return try { return try {
val contentUploadResponse = if (params.isRoomEncrypted) { val contentUploadResponse = if (params.isEncrypted) {
Timber.v("Encrypt file") Timber.v("Encrypt file")
notifyTracker(params) { contentUploadStateTracker.setEncrypting(it) } notifyTracker(params) { contentUploadStateTracker.setEncrypting(it) }
@ -205,10 +207,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
return Result.success( return Result.success(
WorkerParamsFactory.toData( WorkerParamsFactory.toData(
MultipleEventSendingDispatcherWorker.Params( params.copy(
sessionId = params.sessionId,
events = params.events,
isEncrypted = params.isRoomEncrypted,
lastFailureMessage = failure.localizedMessage lastFailureMessage = failure.localizedMessage
) )
) )
@ -229,7 +228,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
updateEvent(it, attachmentUrl, encryptedFileInfo, thumbnailUrl, thumbnailEncryptedFileInfo, newImageAttributes) updateEvent(it, attachmentUrl, encryptedFileInfo, thumbnailUrl, thumbnailEncryptedFileInfo, newImageAttributes)
} }
val sendParams = MultipleEventSendingDispatcherWorker.Params(params.sessionId, updatedEvents, params.isRoomEncrypted) val sendParams = MultipleEventSendingDispatcherWorker.Params(params.sessionId, updatedEvents, params.isEncrypted)
return Result.success(WorkerParamsFactory.toData(sendParams)) return Result.success(WorkerParamsFactory.toData(sendParams))
} }

View File

@ -233,7 +233,7 @@ internal class DefaultSendService @AssistedInject constructor(
val dispatcherWork = createMultipleEventDispatcherWork(isRoomEncrypted) val dispatcherWork = createMultipleEventDispatcherWork(isRoomEncrypted)
workManagerProvider.workManager workManagerProvider.workManager
.beginWith(uploadWork) .beginUniqueWork(buildWorkName(UPLOAD_WORK), ExistingWorkPolicy.APPEND, uploadWork)
.then(dispatcherWork) .then(dispatcherWork)
.enqueue() .enqueue()
.also { operation -> .also { operation ->

View File

@ -296,7 +296,7 @@ dependencies {
implementation 'com.airbnb.android:mvrx:1.3.0' implementation 'com.airbnb.android:mvrx:1.3.0'
// Work // Work
implementation "androidx.work:work-runtime-ktx:2.3.0-beta02" implementation "androidx.work:work-runtime-ktx:2.3.3"
// Paging // Paging
implementation "androidx.paging:paging-runtime-ktx:2.1.1" implementation "androidx.paging:paging-runtime-ktx:2.1.1"

View File

@ -260,11 +260,9 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
add(EventSharedAction.ViewEditHistory(informationData)) add(EventSharedAction.ViewEditHistory(informationData))
} }
if (canShare(msgType)) { if (canShare(msgType) && messageContent is MessageWithAttachmentContent) {
if (messageContent is MessageWithAttachmentContent) {
add(EventSharedAction.Share(timelineEvent.eventId, messageContent)) add(EventSharedAction.Share(timelineEvent.eventId, messageContent))
} }
}
if (timelineEvent.root.sendState == SendState.SENT) { if (timelineEvent.root.sendState == SendState.SENT) {
// TODO Can be redacted // TODO Can be redacted