[network/ruqola] src/core: Fix load message. Use updated time to get list of messages
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 2f55b7780d3384576dcc628ef94f64be17b082b0 by Laurent Montel.
Committed on 27/07/2026 at 11:21.
Pushed by mlaurent into branch 'master'.
Fix load message. Use updated time to get list of messages
=> don't reload last one
M +10 -6 src/core/managelocaldatabase.cpp
M +9 -0 src/core/model/messagesmodel.cpp
M +7 -0 src/core/model/messagesmodel.h
https://invent.kde.org/network/ruqola/-/commit/2f55b7780d3384576dcc628ef94f64be17b082b0
diff --git a/src/core/managelocaldatabase.cpp b/src/core/managelocaldatabase.cpp
index 24e60503e2..53eb5ef5b3 100644
--- a/src/core/managelocaldatabase.cpp
+++ b/src/core/managelocaldatabase.cpp
@@ -108,14 +108,18 @@ void ManageLocalDatabase::loadMessagesHistory(const ManageLocalDatabase::ManageL
return;
}
#endif
- const qint64 lastDateTime = info.roomModel->lastTimestamp();
- qCDebug(RUQOLA_LOAD_HISTORY_LOG) << "lastDateTime " << lastDateTime << "date " << QDateTime::fromMSecsSinceEpoch(lastDateTime);
- if (lastDateTime != 0) {
- qCDebug(RUQOLA_LOAD_HISTORY_LOG) << " sync " << lastDateTime;
- syncMessage(info.roomId, lastDateTime);
+ // Sync from just after the last message's updatedAt to avoid reloading it if it was edited on server
+ // Use updatedAt instead of timestamp because SyncMessagesJob uses updatedAt to determine which messages to return
+ const qint64 lastUpdatedAt = info.roomModel->lastUpdatedAtTimestamp();
+ qCDebug(RUQOLA_LOAD_HISTORY_LOG) << "lastUpdatedAt " << lastUpdatedAt << "date " << QDateTime::fromMSecsSinceEpoch(lastUpdatedAt);
+ if (lastUpdatedAt != 0) {
+ // Add 1ms to avoid syncing the last message itself while still getting newer messages
+ const qint64 syncFromDateTime = lastUpdatedAt + 1;
+ qCDebug(RUQOLA_LOAD_HISTORY_LOG) << " sync from " << syncFromDateTime;
+ syncMessage(info.roomId, syncFromDateTime);
return;
} else {
- qCDebug(RUQOLA_LOAD_HISTORY_LOG) << " no sync message ";
+ qCDebug(RUQOLA_LOAD_HISTORY_LOG) << " no messages in database ";
}
#endif
} else if (mRocketChatAccount->offlineMode()) {
diff --git a/src/core/model/messagesmodel.cpp b/src/core/model/messagesmodel.cpp
index d5c410b717..9242c1d4dc 100644
--- a/src/core/model/messagesmodel.cpp
+++ b/src/core/model/messagesmodel.cpp
@@ -131,6 +131,15 @@ qint64 MessagesModel::lastTimestamp() const
}
}
+qint64 MessagesModel::lastUpdatedAtTimestamp() const
+{
+ if (!mAllMessages.isEmpty()) {
+ return mAllMessages.at(mAllMessages.count() - 1).updatedAt();
+ } else {
+ return 0;
+ }
+}
+
qint64 MessagesModel::firstTimestamp() const
{
if (!mAllMessages.isEmpty()) {
diff --git a/src/core/model/messagesmodel.h b/src/core/model/messagesmodel.h
index f732b7e0f1..ee7ee2d98f 100644
--- a/src/core/model/messagesmodel.h
+++ b/src/core/model/messagesmodel.h
@@ -121,6 +121,13 @@ public:
*/
[[nodiscard]] qint64 lastTimestamp() const;
+ /**
+ * @brief Returns last updatedAt timestamp of last message in QList mAllMessages
+ *
+ * @return qint64 The last updatedAt timestamp
+ */
+ [[nodiscard]] qint64 lastUpdatedAtTimestamp() const;
+
void deleteMessage(const QByteArray &messageId);
[[nodiscard]] qint64 generateNewStartTimeStamp(qint64 lastTimeStamp);