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 stickersLoaded: chatContentRoot.stickersLoaded
isChatBlocked: chatContentRoot.isBlocked isChatBlocked: chatContentRoot.isBlocked
channelEmoji: chatContentModule.chatDetails.emoji || "" channelEmoji: chatContentModule.chatDetails.emoji || ""
isActiveChannel: chatContentRoot.isActiveChannel
onShowReplyArea: { onShowReplyArea: {
let obj = messageStore.getMessageByIdAsJson(messageId) let obj = messageStore.getMessageByIdAsJson(messageId)
if (!obj) { if (!obj) {

View File

@ -14,6 +14,8 @@ import shared.popups 1.0
import shared.status 1.0 import shared.status 1.0
import shared.controls 1.0 import shared.controls 1.0
import shared.views.chat 1.0 import shared.views.chat 1.0
import StatusQ.Core 0.1
import StatusQ.Components 0.1
import "../controls" import "../controls"
@ -32,6 +34,7 @@ Item {
property bool stickersLoaded: false property bool stickersLoaded: false
property alias chatLogView: chatLogView property alias chatLogView: chatLogView
property bool isChatBlocked: false property bool isChatBlocked: false
property bool isActiveChannel: false
property var messageContextMenuInst property var messageContextMenuInst
@ -42,6 +45,20 @@ Item {
signal openStickerPackPopup(string stickerPackId) signal openStickerPackPopup(string stickerPackId)
signal showReplyArea(string messageId, string author) 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 { Connections {
target: root.messageStore.messageModule 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 { ListView {
id: chatLogView id: chatLogView
anchors.top: loadingMessagesIndicator.bottom anchors.top: loadingMessagesIndicator.bottom
@ -237,12 +270,15 @@ Item {
model: messageStore.messagesModel model: messageStore.messagesModel
// Not Refactored Yet Component.onCompleted: chatLogView.scrollToBottom(true)
//Component.onCompleted: scrollToBottom(true)
delegate: MessageView { delegate: MessageView {
id: msgDelegate 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 store: root.store
messageStore: root.messageStore messageStore: root.messageStore
usersStore: root.usersStore usersStore: root.usersStore

View File

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

View File

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