use reverse layout
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ class SqlMessageStorage(
|
|||||||
queries.getInitialChatContext(
|
queries.getInitialChatContext(
|
||||||
chatId = chatId,
|
chatId = chatId,
|
||||||
limit = limit.toLong()
|
limit = limit.toLong()
|
||||||
).executeAsList().reversed().map { it.toMessage() }
|
).executeAsList().map { it.toMessage() }
|
||||||
} else {
|
} else {
|
||||||
queries.getNewMessages(
|
queries.getNewMessages(
|
||||||
chatId = chatId,
|
chatId = chatId,
|
||||||
|
|||||||
+2
-1
@@ -25,7 +25,8 @@ fun Route.setupChat(
|
|||||||
get("$DYNAMIC_PREFIX/chat/query") {
|
get("$DYNAMIC_PREFIX/chat/query") {
|
||||||
val repository = chatRepositoryFactory.create(call.obtainUserId())
|
val repository = chatRepositoryFactory.create(call.obtainUserId())
|
||||||
val afterId = call.queryParameters[ChatRepository.ARG_AFTER_ID]?.toLong()
|
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") {
|
post("$DYNAMIC_PREFIX/chat/send") {
|
||||||
val userId = call.obtainUserId()
|
val userId = call.obtainUserId()
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ class RemoteChatRepository(
|
|||||||
"${DYNAMIC_PREFIX}/chat/query",
|
"${DYNAMIC_PREFIX}/chat/query",
|
||||||
args,
|
args,
|
||||||
serverConfigurationRepository.getServerConfiguration()
|
serverConfigurationRepository.getServerConfiguration()
|
||||||
).content
|
).content.asReversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun send(message: Message) {
|
override suspend fun send(message: Message) {
|
||||||
|
|||||||
+2
-2
@@ -80,10 +80,10 @@ class ChatComponent(
|
|||||||
val currentState = _state.value as? ChatState.Data ?: return
|
val currentState = _state.value as? ChatState.Data ?: return
|
||||||
scope.launch {
|
scope.launch {
|
||||||
_state.value = currentState.copy(isSending = true)
|
_state.value = currentState.copy(isSending = true)
|
||||||
val latestMessageId = currentState.messages.lastOrNull()?.id
|
val latestMessageId = currentState.messages.firstOrNull()?.id
|
||||||
val freshMessages = repository.query(afterId = latestMessageId)
|
val freshMessages = repository.query(afterId = latestMessageId)
|
||||||
_state.value = currentState.copy(
|
_state.value = currentState.copy(
|
||||||
messages = currentState.messages + freshMessages,
|
messages = freshMessages + currentState.messages,
|
||||||
isSending = false
|
isSending = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -158,7 +158,8 @@ private fun ChatContent(
|
|||||||
.weight(1f)
|
.weight(1f)
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
contentPadding = contentPadding,
|
contentPadding = contentPadding,
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
reverseLayout = true
|
||||||
) {
|
) {
|
||||||
items(items = state.messages, key = { it.id ?: it.hashCode() }) { message ->
|
items(items = state.messages, key = { it.id ?: it.hashCode() }) { message ->
|
||||||
MessageBubble(
|
MessageBubble(
|
||||||
|
|||||||
Reference in New Issue
Block a user