summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandr Akulich <akulichalexander@gmail.com>2016-09-14 18:08:33 (GMT)
committerAlexandr Akulich <akulichalexander@gmail.com>2016-09-20 12:46:39 (GMT)
commitcbd7bb27f5caa776c3a41bcb5d35bcf4cb2376b2 (patch)
tree2efc2965199e914f9e11f364db504aa7c60accfe
parent33af28091656d4b39412c1a0064b83f28e3064ac (diff)
[Declarative/MessagesModel] Implemented message sort by sent timestamp
REVIEW: 128954
-rw-r--r--KTp/Declarative/messages-model.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/KTp/Declarative/messages-model.cpp b/KTp/Declarative/messages-model.cpp
index dc1088c..6823574 100644
--- a/KTp/Declarative/messages-model.cpp
+++ b/KTp/Declarative/messages-model.cpp
@@ -214,10 +214,21 @@ void MessagesModel::onMessageReceived(const Tp::ReceivedMessage &message)
}
Q_EMIT dataChanged(originalMessageIndex, originalMessageIndex);
} else {
- int length = rowCount();
- beginInsertRows(QModelIndex(), length, length);
+ int newMessageIndex = 0;
+ const QDateTime sentTimestamp = message.sent();
+ if (sentTimestamp.isValid()) {
+ for (int i = d->messages.count() - 1; i >= 0; --i) {
+ if (sentTimestamp > d->messages.at(i).message.time()) {
+ newMessageIndex = i;
+ break;
+ }
+ }
+ } else {
+ newMessageIndex = rowCount();
+ }
+ beginInsertRows(QModelIndex(), newMessageIndex, newMessageIndex);
- d->messages.append(KTp::MessageProcessor::instance()->processIncomingMessage(
+ d->messages.insert(newMessageIndex, KTp::MessageProcessor::instance()->processIncomingMessage(
message, d->account, d->textChannel));
endInsertRows();