Check for and store indices of shares with duplicate display names

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-10-17 14:00:15 +08:00 коммит произвёл Matthieu Gallien
Родитель 56fbc43e0e
Коммит 5d0924c5ab
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -486,6 +486,38 @@ void ShareModel::slotSharesFetched(const QList<SharePtr> &shares)
slotAddShare(share);
}
// Perform forward pass on shares and check for duplicate display names; store these indeces so
// we can check for these and display the specific user identifier in the display string later
_duplicateDisplayNameShareIndices.clear();
const auto shareCount = _shares.count();
for (auto i = 0; i < shareCount; ++i) {
if (_duplicateDisplayNameShareIndices.contains(i)) {
continue;
}
const auto sharee = _shares.at(i)->getShareWith();
if (sharee == nullptr) {
continue;
}
auto hasDuplicates = false;
for (auto j = i + 1; j < shareCount; ++j) {
const auto otherSharee = _shares.at(j)->getShareWith();
if (otherSharee == nullptr) {
continue;
}
if (sharee->format() == otherSharee->format()) {
hasDuplicates = true; // Reassign is faster
_duplicateDisplayNameShareIndices.insert(j);
}
}
if (hasDuplicates) {
_duplicateDisplayNameShareIndices.insert(i);
}
}
handleLinkShare();
}

Просмотреть файл

@ -253,6 +253,7 @@ private:
QHash<QString, QPersistentModelIndex> _shareIdIndexHash;
QHash<QString, QString> _shareIdRecentlySetPasswords;
QVector<ShareePtr> _sharees;
QSet<unsigned int> _duplicateDisplayNameShareIndices;
};
} // namespace OCC