X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fmessagemodel.cpp;h=818c254e8d7dba52ebfcb5d6f8778acf2d71c173;hb=c80ab2e825ff9125c1c7e8e829487a4b1c118579;hp=2678dd8fe48076f7b8fe27d420a37e68373cada0;hpb=dbd9d7878bcdb592e2355f1219ce6109bea60be2;p=quassel.git diff --git a/src/client/messagemodel.cpp b/src/client/messagemodel.cpp index 2678dd8f..818c254e 100644 --- a/src/client/messagemodel.cpp +++ b/src/client/messagemodel.cpp @@ -88,7 +88,7 @@ void MessageModel::insertMessages(const QList &msglist) { int remainingMsgs = msglist.count() - processedMsgs; if(remainingMsgs > 0) { if(msglist.first().msgId() < msglist.last().msgId()) { - // in Order + // in Order - we have just successfully processed "processedMsg" messages from the end of the list _messageBuffer << msglist.mid(0, remainingMsgs); } else { _messageBuffer << msglist.mid(processedMsgs); @@ -103,7 +103,7 @@ void MessageModel::insertMessageGroup(const QList &msglist) { int start = indexForId(msglist.first().msgId()); int end = start + msglist.count() - 1; MessageModelItem *dayChangeItem = 0; - + bool relocatedMsg = false; if(start > 0) { // check if the preceeding msg is a daychange message and if so if // we have to drop or relocate it at the end of this chunk @@ -122,6 +122,7 @@ void MessageModel::insertMessageGroup(const QList &msglist) { endRemoveRows(); start--; end--; + relocatedMsg = true; } } @@ -150,13 +151,7 @@ void MessageModel::insertMessageGroup(const QList &msglist) { end++; Q_ASSERT(start == 0 || _messageList[start - 1]->msgId() < msglist.first().msgId()); - - if(start < _messageList.count() && _messageList[start]->msgId() <= msglist.last().msgId()) { - qDebug() << _messageList[start] << ">" << msglist.last(); - } Q_ASSERT(start == _messageList.count() || _messageList[start]->msgId() > msglist.last().msgId()); - - beginInsertRows(QModelIndex(), start, end); int pos = start; foreach(Message msg, msglist) { @@ -174,13 +169,21 @@ void MessageModel::insertMessageGroup(const QList &msglist) { } int MessageModel::insertMessagesGracefully(const QList &msglist) { + /* short description: + * 1) first we check where the message with the highest msgId from msglist would be inserted + * 2) check that position for dupe + * 3) determine the messageId of the preceeding msg + * 4) insert as many msgs from msglist with with msgId larger then the just determined id + * those messages are automatically less then the msg of the position we just determined in 1) + */ bool inOrder = (msglist.first().msgId() < msglist.last().msgId()); // depending on the order we have to traverse from the front to the back or vice versa QList grouplist; MsgId id; MsgId dupeId; - int dupeCount = 0; + int processedMsgs = 1; // we know the list isn't empty, so we at least process one message + int idx; bool fastForward = false; QList::const_iterator iter; if(inOrder) { @@ -190,7 +193,7 @@ int MessageModel::insertMessagesGracefully(const QList &msglist) { iter = msglist.constBegin(); } - int idx = indexForId((*iter).msgId()); + idx = indexForId((*iter).msgId()); if(idx >= 0 && !_messageList.isEmpty()) dupeId = _messageList[idx]->msgId(); @@ -203,8 +206,6 @@ int MessageModel::insertMessagesGracefully(const QList &msglist) { if((*iter).msgId() != dupeId) grouplist << *iter; - else - dupeCount++; if(!inOrder) iter++; @@ -215,7 +216,13 @@ int MessageModel::insertMessagesGracefully(const QList &msglist) { if(!fastForward && (*iter).msgId() < id) break; + processedMsgs++; + if(grouplist.isEmpty()) { // as long as we don't have a starting point, we have to update the dupeId + idx = indexForId((*iter).msgId()); + if(idx >= 0 && !_messageList.isEmpty()) + dupeId = _messageList[idx]->msgId(); + } if((*iter).msgId() != dupeId) { if(!grouplist.isEmpty()) { QDateTime nextTs = grouplist.value(0).timestamp(); @@ -230,19 +237,23 @@ int MessageModel::insertMessagesGracefully(const QList &msglist) { Message dayChangeMsg = Message::ChangeOfDay(nextTs); dayChangeMsg.setMsgId((*iter).msgId()); grouplist.prepend(dayChangeMsg); - dupeCount--; } } + dupeId = (*iter).msgId(); grouplist.prepend(*iter); - } else { - dupeCount++; } } } else { while(iter != msglist.constEnd()) { if(!fastForward && (*iter).msgId() < id) break; + processedMsgs++; + if(grouplist.isEmpty()) { // as long as we don't have a starting point, we have to update the dupeId + idx = indexForId((*iter).msgId()); + if(idx >= 0 && !_messageList.isEmpty()) + dupeId = _messageList[idx]->msgId(); + } if((*iter).msgId() != dupeId) { if(!grouplist.isEmpty()) { QDateTime nextTs = grouplist.value(0).timestamp(); @@ -257,20 +268,18 @@ int MessageModel::insertMessagesGracefully(const QList &msglist) { Message dayChangeMsg = Message::ChangeOfDay(nextTs); dayChangeMsg.setMsgId((*iter).msgId()); grouplist.prepend(dayChangeMsg); - dupeCount--; } } + dupeId = (*iter).msgId(); grouplist.prepend(*iter); - } else { - dupeCount++; } - iter++; } } - insertMessageGroup(grouplist); - return grouplist.count() + dupeCount; + if(!grouplist.isEmpty()) + insertMessageGroup(grouplist); + return processedMsgs; } void MessageModel::customEvent(QEvent *event) {