fix: load messages on scroll up, scroll down when sending messages and hide sending status for expired messages

This commit is contained in:
Richard Ramos 2020-07-22 11:12:24 -04:00 committed by Iuri Matias
parent 192fbbea69
commit 7ca512661b
6 changed files with 23 additions and 6 deletions

View File

@ -41,6 +41,7 @@ proc handleChatEvents(self: ChatController) =
self.status.events.on("sendingMessage") do(e:Args):
var msg = MessageArgs(e)
self.status.messages.trackMessage(msg.id, msg.channel)
self.view.sendingMessage()
self.status.events.on("messageSent") do(e:Args):
var msg = MessageSentArgs(e)

View File

@ -117,6 +117,8 @@ QtObject:
proc activeChannelChanged*(self: ChatsView) {.signal.}
proc sendingMessage*(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,6 +23,11 @@ ScrollView {
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
function scrollToBottom(force, caller) {
if(force){
Qt.callLater( chatLogView.positionViewAtEnd )
return;
}
if (!chatLogView.atYEnd) {
// User has scrolled up, we don't want to scroll back
return
@ -53,6 +58,10 @@ ScrollView {
scrollToBottom(true)
}
onSendingMessage: {
scrollToBottom(true)
}
onMessagePushed: {
scrollToBottom()
}
@ -62,10 +71,15 @@ ScrollView {
}
}
property var loadMsgs : Backpressure.oneInTime(chatLogView, 500, function() {
if(loadingMessages) return;
loadingMessages = true;
chatsModel.loadMoreMessages();
});
onContentYChanged: {
if(atYBeginning && !loadingMessages){
loadingMessages = true;
chatsModel.loadMoreMessages();
if(scrollY < 500){
loadMsgs();
}
}

View File

@ -30,7 +30,7 @@ Rectangle {
imageChatBox.height = 0
imageChatBox.visible = false
} else if (imageMessage.status == Image.Ready) {
messageItem.scrollToBottom(true, messageItem)
messageItem.scrollToBottom(false, messageItem)
}
}
}

View File

@ -44,7 +44,7 @@ Rectangle {
imageChatBox.height = 0
imageChatBox.visible = false
} else if (imageMessage.status == Image.Ready) {
messageItem.scrollToBottom(true, messageItem)
messageItem.scrollToBottom(false, messageItem)
}
}
}

View File

@ -4,7 +4,7 @@ import "../../../../../imports"
StyledText {
id: sentMessage
visible: isCurrentUser && !timeout && isMessage
visible: isCurrentUser && !timeout && !isExpired && isMessage
color: Style.current.darkGrey
text: outgoingStatus == "sent" ?
//% "Sent"