From e66a0541bea50e1e8d320b657a6bfd5f882c3599 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 16 Nov 2022 10:56:10 +0100 Subject: [PATCH] Add changelog, some cleaning --- changelog.d/7594.misc | 1 + .../sdk/internal/database/migration/MigrateSessionTo043.kt | 2 +- .../android/sdk/internal/session/room/EventEditValidator.kt | 6 ++++-- .../session/room/EventRelationsAggregationProcessor.kt | 4 ++-- .../android/sdk/internal/session/room/EditValidationTest.kt | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 changelog.d/7594.misc diff --git a/changelog.d/7594.misc b/changelog.d/7594.misc new file mode 100644 index 0000000000..5c5771d8d0 --- /dev/null +++ b/changelog.d/7594.misc @@ -0,0 +1 @@ +Better validation of edits diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo043.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo043.kt index a27d4fda3a..d11a671c55 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo043.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo043.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventEditValidator.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventEditValidator.kt index dcf6ad54a0..940da25f11 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventEditValidator.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventEditValidator.kt @@ -33,13 +33,15 @@ internal class EventEditValidator @Inject constructor(val cryptoStore: IMXCrypto } /** - *There are a number of requirements on replacement events, which must be satisfied for the replacement to be considered valid: + * There are a number of requirements on replacement events, which must be satisfied for the replacement + * to be considered valid: * As with all event relationships, the original event and replacement event must have the same room_id * (i.e. you cannot send an event in one room and then an edited version in a different room). * The original event and replacement event must have the same sender (i.e. you cannot edit someone else’s messages). * The replacement and original events must have the same type (i.e. you cannot change the original event’s type). * The replacement and original events must not have a state_key property (i.e. you cannot edit state events at all). - * The original event must not, itself, have a rel_type of m.replace (i.e. you cannot edit an edit — though you can send multiple edits for a single original event). + * The original event must not, itself, have a rel_type of m.replace + * (i.e. you cannot edit an edit — though you can send multiple edits for a single original event). * The replacement event (once decrypted, if appropriate) must have an m.new_content property. * * If the original event was encrypted, the replacement should be too. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt index ef1d8c1430..837d00720b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/EventRelationsAggregationProcessor.kt @@ -213,7 +213,7 @@ internal class EventRelationsAggregationProcessor @Inject constructor( if (content?.relatesTo?.type == RelationType.REPLACE) { Timber.v("###REPLACE in room $roomId for event ${event.eventId}") // A replace! - handleReplace(realm, event, roomId, isLocalEcho, content?.relatesTo.eventId) + handleReplace(realm, event, roomId, isLocalEcho, content.relatesTo.eventId) } } in EventType.POLL_RESPONSE -> { @@ -474,7 +474,7 @@ internal class EventRelationsAggregationProcessor @Inject constructor( } val sourceToDiscard = eventSummary.editSummary?.editions?.firstOrNull { it.eventId == redacted.eventId } if (sourceToDiscard == null) { - Timber.w("Redaction of a replace that was not known in aggregation $sourceToDiscard") + Timber.w("Redaction of a replace that was not known in aggregation") return } // Need to remove this event from the edition list diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/EditValidationTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/EditValidationTest.kt index 99942d967e..429e6625ab 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/EditValidationTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/room/EditValidationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.