From 543ba5d46b3e56f4e792643987e3355384b5a3fa Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Fri, 21 Aug 2020 09:29:19 +0200 Subject: [PATCH] Force list item update after changed chats --- qml/components/ProfileThumbnail.qml | 24 +++++++++++++++++++++++- qml/pages/OverviewPage.qml | 27 +++++++++++++++------------ src/chatlistmodel.cpp | 3 +++ src/chatlistmodel.h | 3 +++ 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/qml/components/ProfileThumbnail.qml b/qml/components/ProfileThumbnail.qml index c60fe42..ccce452 100644 --- a/qml/components/ProfileThumbnail.qml +++ b/qml/components/ProfileThumbnail.qml @@ -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: { diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index 0e01c51..b61a13d 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -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 { diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index 15f4196..04f2f53 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -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(); } diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 3ba9024..1b73c50 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -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);