]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Check for and store indices of shares with duplicate display names
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 17 Oct 2024 06:00:15 +0000 (14:00 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 18 Oct 2024 09:05:16 +0000 (11:05 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filedetails/sharemodel.cpp
src/gui/filedetails/sharemodel.h

index f184d1c146624ed7b089038bf6b68c5b34102df8..b1e60f84f53cd621fd70995e9be526e58b7542ac 100644 (file)
@@ -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();
 }
 
index e3b8dffe7fff150157eb6b7eb24204807024e79f..7fe2187170159b935c6970c5f3613c3fb6018071 100644 (file)
@@ -253,6 +253,7 @@ private:
     QHash<QString, QPersistentModelIndex> _shareIdIndexHash;
     QHash<QString, QString> _shareIdRecentlySetPasswords;
     QVector<ShareePtr> _sharees;
+    QSet<unsigned int> _duplicateDisplayNameShareIndices;
 };
 
 } // namespace OCC