+ if(!dayChangeMsg.isValid() && start < messageCount()) {
+ // if(!dayChangeItem && start < _messageList.count()) {
+ // check if we need to insert a daychange message at the end of the this group
+
+ // if this assert triggers then indexForId() would have found a spot right before a DayChangeMsg
+ // this should never happen as daychange messages share the msgId with the preceeding message
+ Q_ASSERT(messageItemAt(start)->msgType() != Message::DayChange);
+ QDateTime nextTs = messageItemAt(start)->timestamp();
+ QDateTime prevTs = msglist.last().timestamp();
+ nextTs.setTimeSpec(Qt::UTC);
+ prevTs.setTimeSpec(Qt::UTC);
+ uint nextDay = nextTs.toTime_t() / 86400;
+ uint prevDay = prevTs.toTime_t() / 86400;
+ if(nextDay != prevDay) {
+ nextTs.setTime_t(nextDay * 86400);
+ nextTs.setTimeSpec(Qt::LocalTime);
+ dayChangeMsg = Message::ChangeOfDay(nextTs);
+ dayChangeMsg.setMsgId(msglist.last().msgId());
+ }
+ }
+
+ if(dayChangeMsg.isValid())
+ end++;
+
+ Q_ASSERT(start == 0 || messageItemAt(start - 1)->msgId() < msglist.first().msgId());
+ Q_ASSERT(start == messageCount() || messageItemAt(start)->msgId() > msglist.last().msgId());
+ beginInsertRows(QModelIndex(), start, end);
+ insertMessages__(start, msglist);
+ if(dayChangeMsg.isValid())
+ insertMessage__(start + msglist.count(), dayChangeMsg);