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 variant photoData;
property string replacementStringHint: "X" property string replacementStringHint: "X"
property bool forceElementUpdate: false
function getReplacementString() { function getReplacementString() {
if (replacementStringHint.length > 2) { if (replacementStringHint.length > 2) {
@ -43,7 +44,7 @@ Item {
return replacementStringHint; return replacementStringHint;
} }
Component.onCompleted: { function updatePicture() {
if (typeof photoData === "object") { if (typeof photoData === "object") {
if (photoData.local.is_downloading_completed) { if (photoData.local.is_downloading_completed) {
singleImage.source = photoData.local.path; 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 { Connections {
target: tdLibWrapper target: tdLibWrapper
onFileUpdated: { onFileUpdated: {

View file

@ -44,16 +44,6 @@ Page {
} }
} }
Timer {
id: synchronizeChangesTimer
interval: 60000
running: false
repeat: true
onTriggered: {
chatListModel.enableDeltaUpdates();
}
}
Timer { Timer {
id: chatListCreatedTimer id: chatListCreatedTimer
interval: 500 interval: 500
@ -62,8 +52,6 @@ Page {
onTriggered: { onTriggered: {
overviewPage.chatListCreated = true; overviewPage.chatListCreated = true;
chatListModel.enableDeltaUpdates(); 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 }); // 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 { Column {
id: chatListColumn id: chatListColumn
width: parent.width - ( 2 * Theme.horizontalPageMargin ) width: parent.width - ( 2 * Theme.horizontalPageMargin )
@ -255,6 +257,7 @@ Page {
replacementStringHint: chatListNameText.text replacementStringHint: chatListNameText.text
width: parent.width width: parent.width
height: parent.width height: parent.width
forceElementUpdate: overviewPage.chatListCreated
} }
Rectangle { Rectangle {

View file

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

View file

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