diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/LocalEchoMapper.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/LocalEchoMapper.kt index a27894f..e65bb0d 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/LocalEchoMapper.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/LocalEchoMapper.kt @@ -11,14 +11,28 @@ internal class LocalEchoMapper(private val metaMapper: MetaMapper) { fun MessageService.LocalEcho.toMessage(member: RoomMember): RoomEvent { return when (val message = this.message) { is MessageService.Message.TextMessage -> { - RoomEvent.Message( + val mappedMessage = RoomEvent.Message( eventId = this.eventId ?: EventId(this.localId), content = message.content.body, author = member, utcTimestamp = message.timestampUtc, meta = metaMapper.toMeta(this) ) + + when (val reply = message.reply) { + null -> mappedMessage + else -> RoomEvent.Reply( + mappedMessage, RoomEvent.Message( + eventId = reply.eventId, + content = reply.originalMessage, + author = reply.author, + utcTimestamp = reply.timestampUtc, + meta = MessageMeta.FromServer + ) + ) + } } + is MessageService.Message.ImageMessage -> { RoomEvent.Image( eventId = this.eventId ?: EventId(this.localId), diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt index a31b1b0..e01b55a 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerViewModel.kt @@ -123,14 +123,15 @@ internal class MessengerViewModel( timestampUtc = clock.millis(), reply = copy.reply?.let { MessageService.Message.TextMessage.Reply( - authorId = it.author.id, + author = it.author, originalMessage = when (it) { is RoomEvent.Image -> TODO() is RoomEvent.Reply -> TODO() is RoomEvent.Message -> it.content }, - copy.value, - it.eventId + replyContent = copy.value, + eventId = it.eventId, + timestampUtc = it.utcTimestamp, ) } ) diff --git a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/MessageService.kt b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/MessageService.kt index e488b04..475ae1f 100644 --- a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/MessageService.kt +++ b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/MessageService.kt @@ -43,10 +43,11 @@ interface MessageService : MatrixService { ) : Message { @Serializable data class Reply( - val authorId: UserId, + val author: RoomMember, val originalMessage: String, val replyContent: String, - val eventId: EventId + val eventId: EventId, + val timestampUtc: Long, ) } diff --git a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt index aa573f2..385fffb 100644 --- a/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt +++ b/matrix/services/message/src/main/kotlin/app/dapk/st/matrix/message/internal/SendMessageUseCase.kt @@ -157,9 +157,9 @@ class ApiMessageMapper { ) else -> ApiMessage.TextMessage.TextContent( - body = buildReplyFallback(reply.originalMessage, reply.authorId, reply.replyContent), + body = buildReplyFallback(reply.originalMessage, reply.author.id, reply.replyContent), relatesTo = ApiMessage.RelatesTo(ApiMessage.RelatesTo.InReplyTo(reply.eventId)), - formattedBody = buildFormattedReply(reply.authorId, reply.originalMessage, reply.replyContent, this.roomId, reply.eventId), + formattedBody = buildFormattedReply(reply.author.id, reply.originalMessage, reply.replyContent, this.roomId, reply.eventId), format = "org.matrix.custom.html" ) }