+ 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);
+ endInsertRows();
+
+ Q_ASSERT(start == end || messageItemAt(start)->msgId() != messageItemAt(end)->msgId() || messageItemAt(end)->msgType() == Message::DayChange);
+ Q_ASSERT(start == 0 || messageItemAt(start - 1)->msgId() < messageItemAt(start)->msgId());
+ Q_ASSERT(end + 1 == messageCount() || messageItemAt(end)->msgId() < messageItemAt(end + 1)->msgId());
+}
+
+int MessageModel::insertMessagesGracefully(const QList<Message> &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