From 825760d17e4f0eb376ecc7f8bd6eaf083ce1838d Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 27 Aug 2019 17:01:52 +0200 Subject: [PATCH 1/2] Fix / regression on e2e reply and edit of reply --- CHANGES.md | 1 + .../session/room/relation/DefaultRelationService.kt | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a3b3776156..d657337bdc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Bugfix: - Fix text diff linebreak display (#441) - Date change message repeats for each redaction until a normal message (#358) - Slide-in reply icon is distorted (#423) + - Regression / e2e replies not encrypted Translations: - 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 addad44bf9..9640cd4e80 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 @@ -136,7 +136,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv } if (cryptoService.isRoomEncrypted(roomId)) { val encryptWork = createEncryptEventWork(event, listOf("m.relates_to")) - val workRequest = createSendEventWork(event) + val workRequest = createSendEventWork(event, false) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, workRequest) return CancelableWork(context, encryptWork.id) @@ -162,7 +162,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv } if (cryptoService.isRoomEncrypted(roomId)) { val encryptWork = createEncryptEventWork(event, listOf("m.relates_to")) - val workRequest = createSendEventWork(event) + val workRequest = createSendEventWork(event, false) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, workRequest) return CancelableWork(context, encryptWork.id) @@ -189,7 +189,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv if (cryptoService.isRoomEncrypted(roomId)) { val encryptWork = createEncryptEventWork(event, listOf("m.relates_to")) - val workRequest = createSendEventWork(event) + val workRequest = createSendEventWork(event, false) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, workRequest) return CancelableWork(context, encryptWork.id) @@ -208,10 +208,10 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv return TimelineSendEventWorkCommon.createWork(sendWorkData, true) } - private fun createSendEventWork(event: Event): OneTimeWorkRequest { + private fun createSendEventWork(event: Event, startChain: Boolean = true): OneTimeWorkRequest { val sendContentWorkerParams = SendEventWorker.Params(credentials.userId, roomId, event) val sendWorkData = WorkerParamsFactory.toData(sendContentWorkerParams) - return TimelineSendEventWorkCommon.createWork(sendWorkData, true) + return TimelineSendEventWorkCommon.createWork(sendWorkData, startChain) } override fun getEventSummaryLive(eventId: String): LiveData { From 1b394527b6a0a7cec012e3293db5b1b3253bc937 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 28 Aug 2019 10:22:51 +0200 Subject: [PATCH 2/2] cleaning + code review --- .../room/relation/DefaultRelationService.kt | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) 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 9640cd4e80..0c8695cbcf 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 @@ -69,15 +69,11 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv .also { saveLocalEcho(it) } - val sendRelationWork = createSendRelationWork(event) + val sendRelationWork = createSendEventWork(event, true) TimelineSendEventWorkCommon.postWork(context, roomId, sendRelationWork) return CancelableWork(context, sendRelationWork.id) } - private fun createSendRelationWork(event: Event): OneTimeWorkRequest { - return createSendEventWork(event) - } - override fun undoReaction(reaction: String, targetEventId: String, myUserId: String)/*: Cancelable*/ { val params = FindReactionEventForUndoTask.Params( @@ -134,42 +130,42 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv .also { saveLocalEcho(it) } - if (cryptoService.isRoomEncrypted(roomId)) { + return if (cryptoService.isRoomEncrypted(roomId)) { val encryptWork = createEncryptEventWork(event, listOf("m.relates_to")) val workRequest = createSendEventWork(event, false) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, workRequest) - return CancelableWork(context, encryptWork.id) + CancelableWork(context, encryptWork.id) } else { - val workRequest = createSendEventWork(event) + val workRequest = createSendEventWork(event, true) TimelineSendEventWorkCommon.postWork(context, roomId, workRequest) - return CancelableWork(context, workRequest.id) + CancelableWork(context, workRequest.id) } } override fun editReply(replyToEdit: TimelineEvent, - originalEvent: TimelineEvent, + originalTimelineEvent: TimelineEvent, newBodyText: String, compatibilityBodyText: String): Cancelable { val event = eventFactory .createReplaceTextOfReply(roomId, - replyToEdit, - originalEvent, - newBodyText, true, MessageType.MSGTYPE_TEXT, compatibilityBodyText) + replyToEdit, + originalTimelineEvent, + newBodyText, true, MessageType.MSGTYPE_TEXT, compatibilityBodyText) .also { saveLocalEcho(it) } - if (cryptoService.isRoomEncrypted(roomId)) { + return if (cryptoService.isRoomEncrypted(roomId)) { val encryptWork = createEncryptEventWork(event, listOf("m.relates_to")) val workRequest = createSendEventWork(event, false) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, workRequest) - return CancelableWork(context, encryptWork.id) + CancelableWork(context, encryptWork.id) } else { - val workRequest = createSendEventWork(event) + val workRequest = createSendEventWork(event, true) TimelineSendEventWorkCommon.postWork(context, roomId, workRequest) - return CancelableWork(context, workRequest.id) + CancelableWork(context, workRequest.id) } } @@ -187,16 +183,16 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv saveLocalEcho(it) } ?: return null - if (cryptoService.isRoomEncrypted(roomId)) { + return if (cryptoService.isRoomEncrypted(roomId)) { val encryptWork = createEncryptEventWork(event, listOf("m.relates_to")) val workRequest = createSendEventWork(event, false) TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, workRequest) - return CancelableWork(context, encryptWork.id) + CancelableWork(context, encryptWork.id) } else { - val workRequest = createSendEventWork(event) + val workRequest = createSendEventWork(event, true) TimelineSendEventWorkCommon.postWork(context, roomId, workRequest) - return CancelableWork(context, workRequest.id) + CancelableWork(context, workRequest.id) } } @@ -208,7 +204,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv return TimelineSendEventWorkCommon.createWork(sendWorkData, true) } - private fun createSendEventWork(event: Event, startChain: Boolean = true): 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, startChain) @@ -220,7 +216,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv } return Transformations.map(liveEntity) { realmResults -> realmResults.firstOrNull()?.asDomain() - ?: EventAnnotationsSummary(eventId, emptyList(), null) + ?: EventAnnotationsSummary(eventId, emptyList(), null) } } @@ -233,7 +229,7 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv private fun saveLocalEcho(event: Event) { monarchy.writeAsync { realm -> val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() - ?: return@writeAsync + ?: return@writeAsync roomEntity.addSendingEvent(event) } }