Enhance RoomEventFilter with MSC3440

This commit is contained in:
ariskotsomitopoulos 2021-12-21 20:04:50 +02:00
parent 7048080ee0
commit 5a7d12a9a5
8 changed files with 33 additions and 12 deletions

View file

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

View file

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

View file

@ -48,6 +48,16 @@ data class RoomEventFilter(
* a wildcard to match any sequence of characters.
*/
@Json(name = "types") val types: List<String>? = 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<String>? = 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<String>? = null,
/**
* A list of room IDs to include. If this list is absent then all rooms are included.
*/

View file

@ -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<String>?): 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
}

View file

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

View file

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

View file

@ -272,7 +272,7 @@ internal class ThreadsAwarenessHandler @Inject constructor(
* @param event
*/
private fun isThreadEvent(event: Event): Boolean =
event.content.toModel<MessageRelationContent>()?.relatesTo?.type == RelationType.THREAD
event.content.toModel<MessageRelationContent>()?.relatesTo?.type == RelationType.IO_THREAD
/**
* Returns the root thread eventId or null otherwise

View file

@ -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())
}