A little bit of lazy loading for the chat view...

This commit is contained in:
Sebastian J. Wolf 2020-08-29 18:04:23 +02:00
parent a527009f86
commit 63833b3c5c
5 changed files with 231 additions and 192 deletions

View file

@ -84,7 +84,6 @@ Page {
}
function initializePage() {
chatModel.initialize(chatInformation.id);
var chatType = chatInformation.type['@type'];
isPrivateChat = ( chatType === "chatTypePrivate" );
isBasicGroup = ( chatType === "chatTypeBasicGroup" );
@ -102,8 +101,6 @@ Page {
isChannel = chatGroupInformation.is_channel;
updateGroupStatusText();
}
tdLibWrapper.getChatHistory(chatInformation.id);
chatPage.loading = false;
}
Component.onCompleted: {
@ -114,6 +111,9 @@ Page {
if (status === PageStatus.Activating) {
tdLibWrapper.openChat(chatInformation.id);
}
if (status === PageStatus.Active) {
chatModel.initialize(chatInformation.id);
}
if (status === PageStatus.Deactivating) {
tdLibWrapper.closeChat(chatInformation.id);
}
@ -151,6 +151,7 @@ Page {
Connections {
target: chatModel
onMessagesReceived: {
chatPage.loading = false;
chatView.positionViewAtEnd();
}
onNewMessageReceived: {
@ -173,7 +174,6 @@ Page {
contentHeight: parent.height
contentWidth: parent.width
anchors.fill: parent
visible: !chatPage.loading
Column {
id: chatColumn
@ -235,14 +235,21 @@ Page {
}
}
SilicaListView {
id: chatView
Item {
id: chatViewItem
width: parent.width
height: parent.height - ( 2 * Theme.paddingMedium ) - headerRow.height - newMessageColumn.height
SilicaListView {
id: chatView
anchors.fill: parent
opacity: chatPage.loading ? 0 : 1
Behavior on opacity { NumberAnimation {} }
visible: !chatPage.loading
clip: true
visible: count > 0
function handleScrollPositionChanged() {
tdLibWrapper.viewMessage(chatInformation.id, chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin )).myMessage.id);
@ -262,7 +269,6 @@ Page {
}
onCurrentIndexChanged: {
console.log("Current index: " + currentIndex);
tdLibWrapper.viewMessage(chatInformation.id, currentItem.myMessage.id);
}
@ -464,6 +470,31 @@ Page {
VerticalScrollDecorator {}
}
Column {
width: parent.width
height: loadingLabel.height + loadingBusyIndicator.height + Theme.paddingMedium
spacing: Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
opacity: chatPage.loading ? 1 : 0
Behavior on opacity { NumberAnimation {} }
visible: chatPage.loading
InfoLabel {
id: loadingLabel
text: qsTr("Loading messages...")
}
BusyIndicator {
id: loadingBusyIndicator
anchors.horizontalCenter: parent.horizontalCenter
running: chatPage.loading
size: BusyIndicatorSize.Large
}
}
}
Column {
id: newMessageColumn
spacing: Theme.paddingMedium

View file

@ -38,7 +38,6 @@ Page {
property bool chatListCreated: false;
onStatusChanged: {
console.log("[OverviewPage] Status changed: " + status + ", initialization completed: " + initializationCompleted);
if (status === PageStatus.Active && initializationCompleted && !chatListCreated) {
updateContent();
}

View file

@ -52,6 +52,7 @@ void ChatModel::initialize(const QString &chatId)
this->messages.clear();
this->messageIndexMap.clear();
this->messagesToBeAdded.clear();
tdLibWrapper->getChatHistory(chatId);
}
void ChatModel::triggerLoadMoreHistory()

View file

@ -141,12 +141,16 @@
<source>%1 subscribers</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reply to Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reply to Message</source>
<source>Loading messages...</source>
<translation type="unfinished"></translation>
</message>
</context>

View file

@ -141,12 +141,16 @@
<source>%1 subscribers</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reply to Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reply to Message</source>
<source>Loading messages...</source>
<translation type="unfinished"></translation>
</message>
</context>