- int idx = indexForId(msglist.first().msgId());
- if(idx > 0) {
- int prevIdx = idx - 1;
- if(_messageList[prevIdx]->msgType() == Message::DayChange
- && _messageList[prevIdx]->timeStamp() > msglist.value(0).timestamp()) {
+ Q_ASSERT(!msglist.isEmpty()); // the msglist can be assumed to be non empty
+ 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
+ int prevIdx = start - 1;
+ if(_messageList.at(prevIdx)->msgType() == Message::DayChange
+ && _messageList.at(prevIdx)->timeStamp() > msglist.at(0).timestamp()) {