Fixes #691 - missing messages when using unread message requester
authorMarcus Eggenberger <egs@quassel-irc.org>
Sun, 28 Jun 2009 15:11:00 +0000 (17:11 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sun, 28 Jun 2009 15:11:00 +0000 (17:11 +0200)
src/core/corebacklogmanager.cpp

index d9f3d90..39feb2a 100644 (file)
@@ -43,23 +43,30 @@ QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first,
   }
 
   if(additional) {
   }
 
   if(additional) {
+    MsgId oldestMessage;
+    if(!msgList.isEmpty()) {
+      if(msgList.first().msgId() < msgList.last().msgId())
+        oldestMessage = msgList.first().msgId();
+      else
+        oldestMessage = msgList.last().msgId();
+    }
+
     if(first != -1) {
       last = first;
     } else {
     if(first != -1) {
       last = first;
     } else {
-      last = -1;
-      if(!msgList.isEmpty()) {
-       if(msgList.first().msgId() < msgList.last().msgId())
-         last = msgList.first().msgId();
-       else
-         last = msgList.last().msgId();
-      }
+      last = oldestMessage;
     }
     }
-    msgList = Core::requestMsgs(coreSession()->user(), bufferId, -1, last, additional);
-    msgIter = msgList.constBegin();
-    msgListEnd = msgList.constEnd();
-    while(msgIter != msgListEnd) {
-      backlog << qVariantFromValue(*msgIter);
-      msgIter++;
+
+    // only fetch additional messages if they they continue seemlessly
+    // that is, if the list of messages is not truncated by the limit
+    if(last.isValid() && last == oldestMessage) {
+      msgList = Core::requestMsgs(coreSession()->user(), bufferId, -1, last, additional);
+      msgIter = msgList.constBegin();
+      msgListEnd = msgList.constEnd();
+      while(msgIter != msgListEnd) {
+        backlog << qVariantFromValue(*msgIter);
+        msgIter++;
+      }
     }
   }
 
     }
   }