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): self.status.events.on("sendingMessage") do(e:Args):
var msg = MessageArgs(e) var msg = MessageArgs(e)
self.status.messages.trackMessage(msg.id, msg.channel) self.status.messages.trackMessage(msg.id, msg.channel)
self.view.sendingMessage()
self.status.events.on("messageSent") do(e:Args): self.status.events.on("messageSent") do(e:Args):
var msg = MessageSentArgs(e) var msg = MessageSentArgs(e)

View File

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

View File

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

View File

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