supporting local echos for text replies
This commit is contained in:
parent
7a8b91a376
commit
933197dfd7
|
@ -11,14 +11,28 @@ internal class LocalEchoMapper(private val metaMapper: MetaMapper) {
|
||||||
fun MessageService.LocalEcho.toMessage(member: RoomMember): RoomEvent {
|
fun MessageService.LocalEcho.toMessage(member: RoomMember): RoomEvent {
|
||||||
return when (val message = this.message) {
|
return when (val message = this.message) {
|
||||||
is MessageService.Message.TextMessage -> {
|
is MessageService.Message.TextMessage -> {
|
||||||
RoomEvent.Message(
|
val mappedMessage = RoomEvent.Message(
|
||||||
eventId = this.eventId ?: EventId(this.localId),
|
eventId = this.eventId ?: EventId(this.localId),
|
||||||
content = message.content.body,
|
content = message.content.body,
|
||||||
author = member,
|
author = member,
|
||||||
utcTimestamp = message.timestampUtc,
|
utcTimestamp = message.timestampUtc,
|
||||||
meta = metaMapper.toMeta(this)
|
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 -> {
|
is MessageService.Message.ImageMessage -> {
|
||||||
RoomEvent.Image(
|
RoomEvent.Image(
|
||||||
eventId = this.eventId ?: EventId(this.localId),
|
eventId = this.eventId ?: EventId(this.localId),
|
||||||
|
|
|
@ -123,14 +123,15 @@ internal class MessengerViewModel(
|
||||||
timestampUtc = clock.millis(),
|
timestampUtc = clock.millis(),
|
||||||
reply = copy.reply?.let {
|
reply = copy.reply?.let {
|
||||||
MessageService.Message.TextMessage.Reply(
|
MessageService.Message.TextMessage.Reply(
|
||||||
authorId = it.author.id,
|
author = it.author,
|
||||||
originalMessage = when (it) {
|
originalMessage = when (it) {
|
||||||
is RoomEvent.Image -> TODO()
|
is RoomEvent.Image -> TODO()
|
||||||
is RoomEvent.Reply -> TODO()
|
is RoomEvent.Reply -> TODO()
|
||||||
is RoomEvent.Message -> it.content
|
is RoomEvent.Message -> it.content
|
||||||
},
|
},
|
||||||
copy.value,
|
replyContent = copy.value,
|
||||||
it.eventId
|
eventId = it.eventId,
|
||||||
|
timestampUtc = it.utcTimestamp,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -43,10 +43,11 @@ interface MessageService : MatrixService {
|
||||||
) : Message {
|
) : Message {
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Reply(
|
data class Reply(
|
||||||
val authorId: UserId,
|
val author: RoomMember,
|
||||||
val originalMessage: String,
|
val originalMessage: String,
|
||||||
val replyContent: String,
|
val replyContent: String,
|
||||||
val eventId: EventId
|
val eventId: EventId,
|
||||||
|
val timestampUtc: Long,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,9 +157,9 @@ class ApiMessageMapper {
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> ApiMessage.TextMessage.TextContent(
|
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)),
|
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"
|
format = "org.matrix.custom.html"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue