Skip to content
Snippets Groups Projects
Commit 6183d116 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

messagelistmodel: rework moveMessages()

1. sourceParent and destinationParent were incorrect.
2. Moving always all the message can be incorrect if parentIdx >
msgIdx after a merge

Change-Id: I0ab8eeabb61926d5c0c22d8fed68c60d54178bf6
GitLab: #939
parent cd5bdbb2
No related branches found
No related tags found
No related merge requests found
......@@ -288,17 +288,26 @@ MessageListModel::moveMessage(const QString& msgId, const QString& parentId)
}
}
auto endIdx = currentIndex;
auto pId = msgId;
// move a message
int newIndex = indexOfMessage(parentId) + 1;
if (newIndex >= interactions_.size()) {
newIndex = interactions_.size() - 1;
// If we can move all the messages after the current one, we can do it directly
childMessageIdToMove.clear();
endIdx = std::max(endIdx, newIndex - 1);
}
if (currentIndex == newIndex || newIndex == -1)
return;
// Pretty every messages is moved
moveMessages(currentIndex, interactions_.size() - 1, newIndex);
moveMessages(currentIndex, endIdx, newIndex);
// move a child message
if (!childMessageIdToMove.isEmpty())
moveMessage(childMessageIdToMove, msgId);
}
void
......@@ -349,21 +358,14 @@ MessageListModel::removeMessage(int index, iterator it)
void
MessageListModel::moveMessages(int from, int last, int to)
{
auto resetModel = (from <= 2 && last == interactions_.size() - 1);
if (last < from)
return;
if (resetModel) {
Q_EMIT beginResetModel();
} else {
Q_EMIT beginMoveRows(QModelIndex(), from, last, QModelIndex(), to);
}
QModelIndex sourceIndex = QAbstractListModel::index(from, 0);
QModelIndex destinationIndex = QAbstractListModel::index(to, 0);
Q_EMIT beginMoveRows(sourceIndex, from, last, destinationIndex, to);
for (int i = 0; i < (last - from); ++i)
interactions_.move(last, to);
if (resetModel) {
Q_EMIT endResetModel();
} else {
Q_EMIT endMoveRows();
}
Q_EMIT endMoveRows();
}
bool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment