fix: fix chat not scrolling to bottom on load

This commit is contained in:
Jonathan Rainville 2020-07-22 13:46:17 -04:00 committed by Iuri Matias
parent f2d345fe6e
commit e176443ceb
4 changed files with 18 additions and 7 deletions

View File

@ -25,6 +25,7 @@ proc handleChatEvents(self: ChatController) =
self.status.events.on("chatsLoaded") do(e:Args): self.status.events.on("chatsLoaded") do(e:Args):
self.view.setActiveChannelByIndex(0) self.view.setActiveChannelByIndex(0)
self.view.appReady()
self.status.events.on("channelJoined") do(e: Args): self.status.events.on("channelJoined") do(e: Args):
var channel = ChannelArgs(e) var channel = ChannelArgs(e)

View File

@ -119,6 +119,8 @@ QtObject:
proc sendingMessage*(self: ChatsView) {.signal.} proc sendingMessage*(self: ChatsView) {.signal.}
proc appReady*(self: ChatsView) {.signal.}
proc userNameOrAlias*(self: ChatsView, pubKey: string): string {.slot.} = proc userNameOrAlias*(self: ChatsView, pubKey: string): string {.slot.} =
if self.status.chat.contacts.hasKey(pubKey): if self.status.chat.contacts.hasKey(pubKey):
return status_ens.userNameOrAlias(self.status.chat.contacts[pubKey]) return status_ens.userNameOrAlias(self.status.chat.contacts[pubKey])

View File

@ -23,12 +23,7 @@ ScrollView {
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
function scrollToBottom(force, caller) { function scrollToBottom(force, caller) {
if(force){ if (!force && !chatLogView.atYEnd) {
Qt.callLater( chatLogView.positionViewAtEnd )
return;
}
if (!chatLogView.atYEnd) {
// User has scrolled up, we don't want to scroll back // User has scrolled up, we don't want to scroll back
return return
} }
@ -36,7 +31,7 @@ ScrollView {
// If we have a caller, only accept its request if it's the last message // If we have a caller, only accept its request if it's the last message
return return
} }
Qt.callLater( chatLogView.positionViewAtEnd ) Qt.callLater(chatLogView.positionViewAtEnd)
} }
ListView { ListView {
@ -48,7 +43,12 @@ ScrollView {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Timer {
id: timer
}
Connections { Connections {
target: chatsModel target: chatsModel
onMessagesLoaded: { onMessagesLoaded: {
loadingMessages = false; loadingMessages = false;
@ -66,6 +66,13 @@ ScrollView {
scrollToBottom() 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) { onMessageNotificationPushed: function(chatId, msg) {
notificationWindow.notifyUser(chatId, msg) notificationWindow.notifyUser(chatId, msg)
} }

View File

@ -116,6 +116,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
DISTFILES += \ DISTFILES += \
app/AppLayouts/Chat/ChatColumn/CompactMessage.qml \ app/AppLayouts/Chat/ChatColumn/CompactMessage.qml \
app/AppLayouts/Chat/ChatColumn/MessageComponents/ChannelIdentifier.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 \
app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply.qml \ app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatReply.qml \
app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml \ app/AppLayouts/Chat/ChatColumn/MessageComponents/ChatText.qml \