mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-04 14:55:43 +02:00
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
This commit is contained in:
parent
cd5bdbb211
commit
6183d116e4
1 changed files with 14 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue