Skip to content

Commit 90f2c37

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 9a00604 commit 90f2c37

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
@@ -97,13 +97,17 @@ protected function dropMailSharesWhereRemoteShareIsPossible(ISearchResult $searc
9797
$emailType = new SearchResultType('emails');
9898
$remoteType = new SearchResultType('remotes');
9999

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

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

0 commit comments

Comments
 (0)