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.view.setActiveChannelByIndex(0)
self.view.appReady()
self.status.events.on("channelJoined") do(e: Args):
var channel = ChannelArgs(e)

View File

@ -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])

View File

@ -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)
}

View File

@ -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 \