From e176443ceb65caa9728da70f20cfc5c315364b03 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 22 Jul 2020 13:46:17 -0400 Subject: [PATCH] fix: fix chat not scrolling to bottom on load --- src/app/chat/event_handling.nim | 1 + src/app/chat/view.nim | 2 ++ .../Chat/ChatColumn/ChatMessages.qml | 21 ++++++++++++------- ui/nim-status-client.pro | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/app/chat/event_handling.nim b/src/app/chat/event_handling.nim index cab28e0c05..64d26a1060 100644 --- a/src/app/chat/event_handling.nim +++ b/src/app/chat/event_handling.nim @@ -25,6 +25,7 @@ proc handleChatEvents(self: ChatController) = self.status.events.on("chatsLoaded") do(e:Args): self.view.setActiveChannelByIndex(0) + self.view.appReady() self.status.events.on("channelJoined") do(e: Args): var channel = ChannelArgs(e) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index d12bea23ba..2eec5dc0d3 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -119,6 +119,8 @@ QtObject: proc sendingMessage*(self: ChatsView) {.signal.} + proc appReady*(self: ChatsView) {.signal.} + proc userNameOrAlias*(self: ChatsView, pubKey: string): string {.slot.} = if self.status.chat.contacts.hasKey(pubKey): return status_ens.userNameOrAlias(self.status.chat.contacts[pubKey]) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml index 4efdb3042d..f0f54af761 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/ChatMessages.qml @@ -23,12 +23,7 @@ ScrollView { ScrollBar.horizontal.policy: ScrollBar.AlwaysOff function scrollToBottom(force, caller) { - if(force){ - Qt.callLater( chatLogView.positionViewAtEnd ) - return; - } - - if (!chatLogView.atYEnd) { + if (!force && !chatLogView.atYEnd) { // User has scrolled up, we don't want to scroll back return } @@ -36,7 +31,7 @@ ScrollView { // If we have a caller, only accept its request if it's the last message return } - Qt.callLater( chatLogView.positionViewAtEnd ) + Qt.callLater(chatLogView.positionViewAtEnd) } ListView { @@ -48,7 +43,12 @@ ScrollView { Layout.fillWidth: true Layout.fillHeight: true + Timer { + id: timer + } + Connections { + target: chatsModel onMessagesLoaded: { loadingMessages = false; @@ -66,6 +66,13 @@ ScrollView { scrollToBottom() } + onAppReady: { + // Add an additionnal delay, since the app can be "ready" just milliseconds before the UI updated to show the chat + timer.setTimeout(function() { + scrollToBottom(true) + }, 500); + } + onMessageNotificationPushed: function(chatId, msg) { notificationWindow.notifyUser(chatId, msg) } diff --git a/ui/nim-status-client.pro b/ui/nim-status-client.pro index 1556a9fc58..6eb54a0843 100644 --- a/ui/nim-status-client.pro +++ b/ui/nim-status-client.pro @@ -116,6 +116,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin DISTFILES += \ app/AppLayouts/Chat/ChatColumn/CompactMessage.qml \ app/AppLayouts/Chat/ChatColumn/MessageComponents/ChannelIdentifier.qml \ + app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatImage.qml \ app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply \ app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply.qml \ app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml \