use reverse layout

This commit is contained in:
2026-08-07 21:52:22 +03:00
parent e210e773e9
commit 7aa84674f5
5 changed files with 8 additions and 6 deletions
@@ -23,7 +23,7 @@ class SqlMessageStorage(
queries.getInitialChatContext(
chatId = chatId,
limit = limit.toLong()
).executeAsList().reversed().map { it.toMessage() }
).executeAsList().map { it.toMessage() }
} else {
queries.getNewMessages(
chatId = chatId,
@@ -25,7 +25,8 @@ fun Route.setupChat(
get("$DYNAMIC_PREFIX/chat/query") {
val repository = chatRepositoryFactory.create(call.obtainUserId())
val afterId = call.queryParameters[ChatRepository.ARG_AFTER_ID]?.toLong()
call.respond(MessagesResponse(repository.query(afterId)))
val list = repository.query(afterId)
call.respond(MessagesResponse(list))
}
post("$DYNAMIC_PREFIX/chat/send") {
val userId = call.obtainUserId()
@@ -30,7 +30,7 @@ class RemoteChatRepository(
"${DYNAMIC_PREFIX}/chat/query",
args,
serverConfigurationRepository.getServerConfiguration()
).content
).content.asReversed()
}
override suspend fun send(message: Message) {
@@ -80,10 +80,10 @@ class ChatComponent(
val currentState = _state.value as? ChatState.Data ?: return
scope.launch {
_state.value = currentState.copy(isSending = true)
val latestMessageId = currentState.messages.lastOrNull()?.id
val latestMessageId = currentState.messages.firstOrNull()?.id
val freshMessages = repository.query(afterId = latestMessageId)
_state.value = currentState.copy(
messages = currentState.messages + freshMessages,
messages = freshMessages + currentState.messages,
isSending = false
)
}
@@ -158,7 +158,8 @@ private fun ChatContent(
.weight(1f)
.fillMaxWidth(),
contentPadding = contentPadding,
verticalArrangement = Arrangement.spacedBy(8.dp)
verticalArrangement = Arrangement.spacedBy(8.dp),
reverseLayout = true
) {
items(items = state.messages, key = { it.id ?: it.hashCode() }) { message ->
MessageBubble(