[network/ruqola] src/core: Fix last/first message

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit ff7cfd8b8f9805b86342c62368b9b97745bc06f0 by Laurent Montel.
Committed on 27/07/2026 at 11:21.
Pushed by mlaurent into branch 'master'.

Fix last/first message

M  +7    -7    src/core/managelocaldatabase.cpp
M  +2    -2    src/core/model/messagesmodel.cpp

https://invent.kde.org/network/ruqola/-/commit/ff7cfd8b8f9805b86342c62368b9b97745bc06f0

diff --git a/src/core/managelocaldatabase.cpp b/src/core/managelocaldatabase.cpp
index ed605c58ef..24e60503e2 100644
--- a/src/core/managelocaldatabase.cpp
+++ b/src/core/managelocaldatabase.cpp
@@ -100,19 +100,19 @@ void ManageLocalDatabase::loadMessagesHistory(const ManageLocalDatabase::ManageL
             if (!lstMessages.isEmpty()) {
                 mRocketChatAccount->rocketChatBackend()->addMessagesFromLocalDataBase(lstMessages);
             }
-            // FIXME: don't use  info.lastSeenAt until we store room information in database
-            // We need to use last message timeStamp
+            // Check on network if message change. => we need to add timestamp.
+            // Use last message timeStamp to sync with server
 #if ADD_OFFLINE_SUPPORT
             if (mRocketChatAccount->offlineMode()) {
                 qCDebug(RUQOLA_OFFLINE_MODE_LOG) << " Offline mode we don't load messages from server";
                 return;
             }
 #endif
-            const qint64 firstDateTime = info.roomModel->firstTimestamp();
-            qCDebug(RUQOLA_LOAD_HISTORY_LOG) << "firstDateTime " << firstDateTime << "date " << QDateTime::fromMSecsSinceEpoch(firstDateTime);
-            if (firstDateTime != 0) {
-                qCDebug(RUQOLA_LOAD_HISTORY_LOG) << " sync " << firstDateTime;
-                syncMessage(info.roomId, /*info.lastSeenAt*/ firstDateTime);
+            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);
                 return;
             } else {
                 qCDebug(RUQOLA_LOAD_HISTORY_LOG) << " no sync message ";
diff --git a/src/core/model/messagesmodel.cpp b/src/core/model/messagesmodel.cpp
index 61b1d8c9ac..d5c410b717 100644
--- a/src/core/model/messagesmodel.cpp
+++ b/src/core/model/messagesmodel.cpp
@@ -125,7 +125,7 @@ qint64 MessagesModel::lastTimestamp() const
 {
     if (!mAllMessages.isEmpty()) {
         // qCDebug(RUQOLA_MESSAGEMODELS_LOG) << "returning timestamp" << mAllMessages.last().timeStamp();
-        return mAllMessages.constFirst().timeStamp();
+        return mAllMessages.at(mAllMessages.count() - 1).timeStamp();
     } else {
         return 0;
     }
@@ -135,7 +135,7 @@ qint64 MessagesModel::firstTimestamp() const
 {
     if (!mAllMessages.isEmpty()) {
         // qCDebug(RUQOLA_MESSAGEMODELS_LOG) << "returning timestamp" << mAllMessages.last().timeStamp();
-        return mAllMessages.at(mAllMessages.count() - 1).timeStamp();
+        return mAllMessages.constFirst().timeStamp();
     } else {
         return 0;
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.