properly fixing dupes ;)
[quassel.git] / src / client / messagemodel.cpp
index 245a787..c989212 100644 (file)
@@ -94,19 +94,6 @@ void MessageModel::insertMessages(const QList<Message> &msglist) {
   }
 
   bool inOrder = (msglist.first().msgId() < msglist.last().msgId());
-  
-  // check if the whole bunch fits in at one position
-  if(indexForId(msglist.first().msgId()) == indexForId(msglist.last().msgId())) {
-    if(inOrder) {
-      insertMessageGroup(msglist);
-    } else {
-      QList<Message> messages = msglist;
-      qSort(messages);
-      insertMessageGroup(messages);
-    }
-    return;
-  }
-
   // depending on the order we have to traverse from the front to the back or vice versa
   // for the sake of performance we have a little code duplication here
   // if you need to do some changes here you'll probably need to change them at all
@@ -119,6 +106,7 @@ void MessageModel::insertMessages(const QList<Message> &msglist) {
   // and give back controll to the eventloop (similar to what the QtUiMessageProcessor used to do)
   QList<Message> grouplist;
   MsgId id;
+  MsgId dupeId;
   bool fastForward = false;
   QList<Message>::const_iterator iter;
   if(inOrder) {
@@ -130,13 +118,16 @@ void MessageModel::insertMessages(const QList<Message> &msglist) {
 
   // DUPE (1 / 3)
   int idx = indexForId((*iter).msgId());
+  if(idx >= 0)
+    dupeId = _messageList[idx]->msgId();
   // we always compare to the previous entry...
   // if there isn't, we can fastforward to the top
   if(idx - 1 >= 0) // also safe as we've passed another empty check
     id = _messageList[idx - 1]->msgId();
   else
     fastForward = true;
-  grouplist << *iter;
+  if((*iter).msgId() != dupeId)
+    grouplist << *iter;
 
   if(!inOrder)
     iter++;
@@ -151,12 +142,15 @@ void MessageModel::insertMessages(const QList<Message> &msglist) {
        
        // build new group
        int idx = indexForId((*iter).msgId());
+       if(idx >= 0)
+         dupeId = _messageList[idx]->msgId();
        if(idx - 1 >= 0)
          id = _messageList[idx - 1]->msgId();
        else
          fastForward = true;
       }
-      grouplist.prepend(*iter);
+      if((*iter).msgId() != dupeId)
+       grouplist.prepend(*iter);
     }
   } else {
     while(iter != msglist.constEnd()) {
@@ -167,12 +161,15 @@ void MessageModel::insertMessages(const QList<Message> &msglist) {
        
        // build new group
        int idx = indexForId((*iter).msgId());
+       if(idx >= 0)
+         dupeId = _messageList[idx]->msgId();
        if(idx - 1 >= 0)
          id = _messageList[idx - 1]->msgId();
        else
          fastForward = true;
       }
-      grouplist.prepend(*iter);
+      if((*iter).msgId() != dupeId)
+       grouplist.prepend(*iter);
       iter++;
     }
   }