From 5a7d12a9a5896a7aa18d6c81dc1e865aad37faf5 Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Tue, 21 Dec 2021 20:04:50 +0200 Subject: [PATCH] Enhance RoomEventFilter with MSC3440 --- .../android/sdk/api/session/events/model/Event.kt | 4 ++-- .../sdk/api/session/events/model/RelationType.kt | 4 ++-- .../sdk/internal/session/filter/RoomEventFilter.kt | 10 ++++++++++ .../android/sdk/internal/session/room/RoomAPI.kt | 11 +++++++++++ .../session/room/send/LocalEchoEventFactory.kt | 10 +++++----- .../sdk/internal/session/room/send/TextContent.kt | 2 +- .../sync/handler/room/ThreadsAwarenessHandler.kt | 2 +- .../features/home/room/detail/RoomDetailViewModel.kt | 2 +- 8 files changed, 33 insertions(+), 12 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt index 5f9a15de02..7372a83873 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt @@ -367,9 +367,9 @@ fun Event.isReply(): Boolean { return getRelationContent()?.inReplyTo?.eventId != null } -fun Event.isThread(): Boolean = getRelationContentForType(RelationType.THREAD)?.eventId != null +fun Event.isThread(): Boolean = getRelationContentForType(RelationType.IO_THREAD)?.eventId != null -fun Event.getRootThreadEventId(): String? = getRelationContentForType(RelationType.THREAD)?.eventId +fun Event.getRootThreadEventId(): String? = getRelationContentForType(RelationType.IO_THREAD)?.eventId fun Event.isEdition(): Boolean { return getRelationContentForType(RelationType.REPLACE)?.eventId != null diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/RelationType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/RelationType.kt index 6546258766..18bb946462 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/RelationType.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/RelationType.kt @@ -29,8 +29,8 @@ object RelationType { const val REFERENCE = "m.reference" /** Lets you define an event which is a reply to an existing event.*/ -// const val THREAD = "m.thread" - const val THREAD = "io.element.thread" + const val THREAD = "m.thread" + const val IO_THREAD = "io.element.thread" /** Lets you define an event which adds a response to an existing event.*/ const val RESPONSE = "org.matrix.response" diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/RoomEventFilter.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/RoomEventFilter.kt index 7047d38260..f498322967 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/RoomEventFilter.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/filter/RoomEventFilter.kt @@ -48,6 +48,16 @@ data class RoomEventFilter( * a wildcard to match any sequence of characters. */ @Json(name = "types") val types: List? = null, + /** + * A list of relation types which must be exist pointing to the event being filtered. + * If this list is absent then no filtering is done on relation types. + */ + @Json(name = "relation_types") val relationTypes: List? = null, + /** + * A list of senders of relations which must exist pointing to the event being filtered. + * If this list is absent then no filtering is done on relation types. + */ + @Json(name = "relation_senders") val relationSenders: List? = null, /** * A list of room IDs to include. If this list is absent then all rooms are included. */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt index efc5166a0c..0017cdd917 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt @@ -376,4 +376,15 @@ internal interface RoomAPI { @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "im.nheko.summary/rooms/{roomIdOrAlias}/summary") suspend fun getRoomSummary(@Path("roomIdOrAlias") roomidOrAlias: String, @Query("via") viaServers: List?): RoomStrippedState + + // TODO add doc + /** + */ + @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "rooms/{roomId}/messages") + suspend fun getRoomThreadMessages(@Path("roomId") roomId: String, + @Query("from") from: String, + @Query("dir") dir: String, + @Query("limit") limit: Int, + @Query("filter") filter: String? + ): PaginationResponse } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt index 1046bcee49..aad1d422a6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt @@ -290,7 +290,7 @@ internal class LocalEchoEventFactory @Inject constructor( size = attachment.size ), url = attachment.queryUri.toString(), - relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.THREAD, it) } + relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.IO_THREAD, it) } ) return createMessageEvent(roomId, content) } @@ -327,7 +327,7 @@ internal class LocalEchoEventFactory @Inject constructor( thumbnailInfo = thumbnailInfo ), url = attachment.queryUri.toString(), - relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.THREAD, it) } + relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.IO_THREAD, it) } ) return createMessageEvent(roomId, content) } @@ -351,7 +351,7 @@ internal class LocalEchoEventFactory @Inject constructor( waveform = waveformSanitizer.sanitize(attachment.waveform) ), voiceMessageIndicator = if (!isVoiceMessage) null else emptyMap(), - relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.THREAD, it) } + relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.IO_THREAD, it) } ) return createMessageEvent(roomId, content) } @@ -365,7 +365,7 @@ internal class LocalEchoEventFactory @Inject constructor( size = attachment.size ), url = attachment.queryUri.toString(), - relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.THREAD, it) } + relatesTo = rootThreadEventId?.let { RelationDefaultContent(RelationType.IO_THREAD, it) } ) return createMessageEvent(roomId, content) } @@ -454,7 +454,7 @@ internal class LocalEchoEventFactory @Inject constructor( private fun generateReplyRelationContent(eventId: String, rootThreadEventId: String? = null): RelationDefaultContent = rootThreadEventId?.let { RelationDefaultContent( - type = RelationType.THREAD, + type = RelationType.IO_THREAD, eventId = it, inReplyTo = ReplyToContent(eventId)) } ?: RelationDefaultContent(null, null, ReplyToContent(eventId)) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/TextContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/TextContent.kt index d3e0189f4b..0bf0561599 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/TextContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/TextContent.kt @@ -48,7 +48,7 @@ fun TextContent.toThreadTextContent(rootThreadEventId: String, msgType: String = msgType = msgType, format = MessageFormat.FORMAT_MATRIX_HTML.takeIf { formattedText != null }, body = text, - relatesTo = RelationDefaultContent(RelationType.THREAD, rootThreadEventId), + relatesTo = RelationDefaultContent(RelationType.IO_THREAD, rootThreadEventId), formattedBody = formattedText ) } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt index a4ebfabc5c..24854b601f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/handler/room/ThreadsAwarenessHandler.kt @@ -272,7 +272,7 @@ internal class ThreadsAwarenessHandler @Inject constructor( * @param event */ private fun isThreadEvent(event: Event): Boolean = - event.content.toModel()?.relatesTo?.type == RelationType.THREAD + event.content.toModel()?.relatesTo?.type == RelationType.IO_THREAD /** * Returns the root thread eventId or null otherwise diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 3a19106312..62bcccb67a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -436,7 +436,7 @@ class RoomDetailViewModel @AssistedInject constructor( private fun handleSendSticker(action: RoomDetailAction.SendSticker) { val content = initialState.rootThreadEventId?.let { - action.stickerContent.copy(relatesTo = RelationDefaultContent(RelationType.THREAD, it)) + action.stickerContent.copy(relatesTo = RelationDefaultContent(RelationType.IO_THREAD, it)) } ?: action.stickerContent room.sendEvent(EventType.STICKER, content.toContent()) }