Force list item update after changed chats

This commit is contained in:
Sebastian J. Wolf 2020-08-21 09:29:19 +02:00
parent 588fbd11a8
commit 543ba5d46b
4 changed files with 44 additions and 13 deletions

View file

@ -26,6 +26,7 @@ Item {
property variant photoData;
property string replacementStringHint: "X"
property bool forceElementUpdate: false
function getReplacementString() {
if (replacementStringHint.length > 2) {
@ -43,7 +44,7 @@ Item {
return replacementStringHint;
}
Component.onCompleted: {
function updatePicture() {
if (typeof photoData === "object") {
if (photoData.local.is_downloading_completed) {
singleImage.source = photoData.local.path;
@ -53,6 +54,27 @@ Item {
}
}
Timer {
id: updatePictureTimer
interval: 100
running: false
repeat: false
onTriggered: {
updatePicture();
}
}
Component.onCompleted: {
updatePictureTimer.start();
}
onPhotoDataChanged: {
if (profileThumbnail.forceElementUpdate) {
updatePictureTimer.stop();
updatePictureTimer.start();
}
}
Connections {
target: tdLibWrapper
onFileUpdated: {

View file

@ -44,16 +44,6 @@ Page {
}
}
Timer {
id: synchronizeChangesTimer
interval: 60000
running: false
repeat: true
onTriggered: {
chatListModel.enableDeltaUpdates();
}
}
Timer {
id: chatListCreatedTimer
interval: 500
@ -62,8 +52,6 @@ Page {
onTriggered: {
overviewPage.chatListCreated = true;
chatListModel.enableDeltaUpdates();
// Sometimes delta updates are not properly displayed, enforce list redraw from time to time
synchronizeChangesTimer.start();
}
}
@ -223,6 +211,20 @@ Page {
// pageStack.push(Qt.resolvedUrl("../pages/ConversationPage.qml"), { "conversationModel" : display, "myUserId": overviewPage.myUser.id_str, "configuration": overviewPage.configuration });
}
Connections {
target: chatListModel
onChatChanged: {
if (overviewPage.chatListCreated) {
// Force update of all list item elements. dataChanged() doesn't seem to trigger them all :(
chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : "";
chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count;
chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) : qsTr("Unknown");
chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getSimpleMessageText(display.last_message), Theme.fontSizeExtraSmall) : qsTr("Unknown");
messageContactTimeElapsedText.text = (typeof display.last_message !== "undefined") ? Functions.getDateTimeElapsed(display.last_message.date) : qsTr("Unknown");
}
}
}
Column {
id: chatListColumn
width: parent.width - ( 2 * Theme.horizontalPageMargin )
@ -255,6 +257,7 @@ Page {
replacementStringHint: chatListNameText.text
width: parent.width
height: parent.width
forceElementUpdate: overviewPage.chatListCreated
}
Rectangle {

View file

@ -85,6 +85,7 @@ void ChatListModel::handleChatLastMessageUpdated(const QString &chatId, const QS
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
this->updateChatOrder(chatIndex, currentChat);
emit chatChanged(chatId);
this->chatListMutex.unlock();
}
@ -100,6 +101,7 @@ void ChatListModel::handleChatOrderUpdated(const QString &chatId, const QString
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
this->updateChatOrder(chatIndex, currentChat);
emit chatChanged(chatId);
this->chatListMutex.unlock();
}
@ -113,6 +115,7 @@ void ChatListModel::handleChatReadInboxUpdated(const QString &chatId, const int
currentChat.insert("unread_count", unreadCount);
this->chatList.replace(chatIndex, currentChat);
emit dataChanged(this->index(chatIndex), this->index(chatIndex));
emit chatChanged(chatId);
this->chatListMutex.unlock();
}

View file

@ -19,6 +19,9 @@ public:
Q_INVOKABLE void enableDeltaUpdates();
signals:
void chatChanged(const QString &chatId);
public slots:
void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation);
void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage);