supporting local echos for text replies

This commit is contained in:
Adam Brown 2022-10-01 11:47:42 +01:00 committed by Adam Brown
parent 7a8b91a376
commit 933197dfd7
4 changed files with 24 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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