Skip to content

Commit

Permalink
Merge pull request #223 from ouchadam/bug/replying-to-author
Browse files Browse the repository at this point in the history
Fixes wrong author name in replies
  • Loading branch information
ouchadam committed Oct 24, 2022
2 parents 7a93d6a + c25171e commit c301563
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.*
import androidx.compose.foundation.shape.CircleShape
Expand Down Expand Up @@ -200,29 +199,31 @@ private fun ColumnScope.RoomContent(self: UserId, state: RoomState, messageActio
wasPreviousMessageSameSender = wasPreviousMessageSameSender,
onReply = { messageActions.onReply(item) },
) {
val event = BubbleModel.Event(item.author.id.value, item.author.displayName ?: item.author.id.value, item.edited, item.time)
val status = @Composable { SendStatus(item) }
MessageBubble(this, item.toModel(event), status, onLongClick = messageActions.onLongClick)
MessageBubble(this, item.toModel(), status, onLongClick = messageActions.onLongClick)
}
}
}
}

@Composable
private fun RoomEvent.toModel(event: BubbleModel.Event): BubbleModel = when (this) {
is RoomEvent.Message -> BubbleModel.Text(this.content, event)
is RoomEvent.Encrypted -> BubbleModel.Encrypted(event)
is RoomEvent.Image -> {
val imageRequest = LocalImageRequestFactory.current
.memoryCacheKey(this.imageMeta.url)
.data(this)
.build()
val imageContent = BubbleModel.Image.ImageContent(this.imageMeta.width, this.imageMeta.height, this.imageMeta.url)
BubbleModel.Image(imageContent, imageRequest, event)
}
private fun RoomEvent.toModel(): BubbleModel {
val event = BubbleModel.Event(this.author.id.value, this.author.displayName ?: this.author.id.value, this.edited, this.time)
return when (this) {
is RoomEvent.Message -> BubbleModel.Text(this.content, event)
is RoomEvent.Encrypted -> BubbleModel.Encrypted(event)
is RoomEvent.Image -> {
val imageRequest = LocalImageRequestFactory.current
.memoryCacheKey(this.imageMeta.url)
.data(this)
.build()
val imageContent = BubbleModel.Image.ImageContent(this.imageMeta.width, this.imageMeta.height, this.imageMeta.url)
BubbleModel.Image(imageContent, imageRequest, event)
}

is RoomEvent.Reply -> {
BubbleModel.Reply(this.replyingTo.toModel(event), this.message.toModel(event))
is RoomEvent.Reply -> {
BubbleModel.Reply(this.replyingTo.toModel(), this.message.toModel())
}
}
}

Expand Down

0 comments on commit c301563

Please sign in to comment.