fix(chat): fix switching back to chats is very slow

Fixes #5615
This commit is contained in:
Jonathan Rainville 2022-06-23 11:47:30 -04:00 committed by Iuri Matias
parent b550a23dfc
commit 8685ad92c9
4 changed files with 40 additions and 4 deletions

View File

@ -429,6 +429,7 @@ ColumnLayout {
stickersLoaded: chatContentRoot.stickersLoaded
isChatBlocked: chatContentRoot.isBlocked
channelEmoji: chatContentModule.chatDetails.emoji || ""
isActiveChannel: chatContentRoot.isActiveChannel
onShowReplyArea: {
let obj = messageStore.getMessageByIdAsJson(messageId)
if (!obj) {

View File

@ -14,6 +14,8 @@ import shared.popups 1.0
import shared.status 1.0
import shared.controls 1.0
import shared.views.chat 1.0
import StatusQ.Core 0.1
import StatusQ.Components 0.1
import "../controls"
@ -32,6 +34,7 @@ Item {
property bool stickersLoaded: false
property alias chatLogView: chatLogView
property bool isChatBlocked: false
property bool isActiveChannel: false
property var messageContextMenuInst
@ -42,6 +45,20 @@ Item {
signal openStickerPackPopup(string stickerPackId)
signal showReplyArea(string messageId, string author)
property bool allMessagesLoaded: false
onIsActiveChannelChanged: {
if (!isActiveChannel) {
root.allMessagesLoaded = false
return
}
// We wait to load all messages, because switching back to chats makes
// the scroll go crazy so it loads way too many messages making it slow
timer.setTimeout(function() {
root.allMessagesLoaded = true
}, 10);
}
Connections {
target: root.messageStore.messageModule
@ -91,6 +108,22 @@ Item {
}
}
Loader {
active: !root.allMessagesLoaded
anchors.centerIn: parent
sourceComponent: Item {
StatusBaseText {
id: loadingText
text: qsTr("Loading...")
}
StatusLoadingIndicator {
color: Theme.palette.directColor4
anchors.left: loadingText.right
anchors.leftMargin: 8
}
}
}
ListView {
id: chatLogView
anchors.top: loadingMessagesIndicator.bottom
@ -237,12 +270,15 @@ Item {
model: messageStore.messagesModel
// Not Refactored Yet
//Component.onCompleted: scrollToBottom(true)
Component.onCompleted: chatLogView.scrollToBottom(true)
delegate: MessageView {
id: msgDelegate
// We wait to load all messages, because switching back to chats makes
// the scroll go crazy so it loads way too many messages making it slow
visible: root.allMessagesLoaded
store: root.store
messageStore: root.messageStore
usersStore: root.usersStore

View File

@ -24,7 +24,7 @@ Loader {
signal clicked()
height: active ? item.height : 0
height: active && item ? item.height : 0
sourceComponent: StatusSmartIdenticon {
name: root.name

View File

@ -229,7 +229,6 @@ QtObject {
if(Number.isInteger(value) && value > 0) {
return true;
}
console.error(qsTr("timestamp must be type of int and greater than 0 (%1)").arg(errorLocation));
return false;
}