Skip to content

Commit dd5bb23

Browse files
n-ivAntreesy
authored andcommitted
fix: trim duplicate search results for external share
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 3279c40 commit dd5bb23

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

lib/private/Collaboration/Collaborators/Search.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ protected function dropMailSharesWhereRemoteShareIsPossible(ISearchResult $searc
9898
$emailType = new SearchResultType('emails');
9999
$remoteType = new SearchResultType('remotes');
100100

101-
if (!isset($allResults[$remoteType->getLabel()])
102-
|| !isset($allResults[$emailType->getLabel()])) {
101+
$emailLabel = $emailType->getLabel();
102+
$emailEntries = array_merge(
103+
$allResults['exact'][$emailLabel] ?? [],
104+
$allResults[$emailLabel] ?? []
105+
);
106+
if ($emailEntries === []) {
103107
return;
104108
}
105109

106110
$mailIdMap = [];
107-
foreach ($allResults[$emailType->getLabel()] as $mailRow) {
111+
foreach ($emailEntries as $mailRow) {
108112
// sure, array_reduce looks nicer, but foreach needs less resources and is faster
109113
if (!isset($mailRow['uuid'])) {
110114
continue;
@@ -120,5 +124,17 @@ protected function dropMailSharesWhereRemoteShareIsPossible(ISearchResult $searc
120124
$searchResult->removeCollaboratorResult($emailType, $mailIdMap[$resultRow['uuid']]);
121125
}
122126
}
127+
$lookupType = new SearchResultType('lookup');
128+
if (isset($allResults[$lookupType->getLabel()])) {
129+
foreach ($allResults[$lookupType->getLabel()] as $resultRow) {
130+
$userid = $resultRow['extra']['userid']['value'] ?? null;
131+
if ($userid === null) {
132+
continue;
133+
}
134+
if (isset($mailIdMap[$userid])) {
135+
$searchResult->removeCollaboratorResult($emailType, $mailIdMap[$userid]);
136+
}
137+
}
138+
}
123139
}
124140
}

0 commit comments

Comments
 (0)