Skip to content

Commit 88642c6

Browse files
Merge pull request #23549 from nextcloud/backport/22062/stable18
[stable18] fix display of remote users in incoming share notifications
2 parents f41d8dc + 5d2537e commit 88642c6

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

apps/federatedfilesharing/lib/Notifier.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ public function prepare(INotification $notification, string $languageCode): INot
102102

103103
$params = $notification->getSubjectParameters();
104104
if ($params[0] !== $params[1] && $params[1] !== null) {
105+
$remoteInitiator = $this->createRemoteUser($params[0]);
106+
$remoteOwner = $this->createRemoteUser($params[1]);
107+
$params[3] = $remoteInitiator['name'] . '@' . $remoteInitiator['server'];
108+
$params[4] = $remoteOwner['name'] . '@' . $remoteOwner['server'];
109+
105110
$notification->setParsedSubject(
106111
$l->t('You received "%3$s" as a remote share from %4$s (%1$s) (on behalf of %5$s (%2$s))', $params)
107112
);
108113

109-
$initiator = $params[0];
110-
$initiatorDisplay = isset($params[3]) ? $params[3] : null;
111-
$owner = $params[1];
112-
$ownerDisplay = isset($params[4]) ? $params[4] : null;
113-
114114
$notification->setRichSubject(
115115
$l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'),
116116
[
@@ -119,17 +119,18 @@ public function prepare(INotification $notification, string $languageCode): INot
119119
'id' => $notification->getObjectId(),
120120
'name' => $params[2],
121121
],
122-
'user' => $this->createRemoteUser($initiator, $initiatorDisplay),
123-
'behalf' => $this->createRemoteUser($owner, $ownerDisplay),
122+
'user' => $remoteInitiator,
123+
'behalf' => $remoteOwner,
124124
]
125125
);
126126
} else {
127+
$remoteOwner = $this->createRemoteUser($params[0]);
128+
$params[3] = $remoteOwner['name'] . '@' . $remoteOwner['server'];
129+
127130
$notification->setParsedSubject(
128131
$l->t('You received "%3$s" as a remote share from %4$s (%1$s)', $params)
129132
);
130133

131-
$owner = $params[0];
132-
$ownerDisplay = isset($params[3]) ? $params[3] : null;
133134

134135
$notification->setRichSubject(
135136
$l->t('You received {share} as a remote share from {user}'),
@@ -139,7 +140,7 @@ public function prepare(INotification $notification, string $languageCode): INot
139140
'id' => $notification->getObjectId(),
140141
'name' => $params[2],
141142
],
142-
'user' => $this->createRemoteUser($owner, $ownerDisplay),
143+
'user' => $remoteOwner,
143144
]
144145
);
145146
}
@@ -213,17 +214,24 @@ protected function getDisplayName(ICloudId $cloudId) {
213214
}
214215

215216
try {
217+
// contains protocol in the ID
216218
return $this->getDisplayNameFromContact($cloudId->getId());
217219
} catch (\OutOfBoundsException $e) {
218220
}
219221

220222
try {
221-
$this->getDisplayNameFromContact($user . '@http://' . $server);
223+
// does not include protocol, as stored in addressbooks
224+
return $this->getDisplayNameFromContact($cloudId->getDisplayId());
225+
} catch (\OutOfBoundsException $e) {
226+
}
227+
228+
try {
229+
return $this->getDisplayNameFromContact($user . '@http://' . $server);
222230
} catch (\OutOfBoundsException $e) {
223231
}
224232

225233
try {
226-
$this->getDisplayNameFromContact($user . '@https://' . $server);
234+
return $this->getDisplayNameFromContact($user . '@https://' . $server);
227235
} catch (\OutOfBoundsException $e) {
228236
}
229237

apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function shareReceived(ICloudFederationShare $share) {
256256
->setAffectedUser($shareWith)
257257
->setObject('remote_share', (int)$shareId, $name);
258258
\OC::$server->getActivityManager()->publish($event);
259-
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner);
259+
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name);
260260
} else {
261261
$groupMembers = $this->groupManager->get($shareWith)->getUsers();
262262
foreach ($groupMembers as $user) {
@@ -267,7 +267,7 @@ public function shareReceived(ICloudFederationShare $share) {
267267
->setAffectedUser($user->getUID())
268268
->setObject('remote_share', (int)$shareId, $name);
269269
\OC::$server->getActivityManager()->publish($event);
270-
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner);
270+
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name);
271271
}
272272
}
273273
return $shareId;
@@ -335,22 +335,13 @@ private function mapShareTypeToNextcloud($shareType) {
335335
return $result;
336336
}
337337

338-
/**
339-
* notify user about new federated share
340-
*
341-
* @param $shareWith
342-
* @param $shareId
343-
* @param $ownerFederatedId
344-
* @param $sharedByFederatedId
345-
* @param $name
346-
*/
347-
private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner) {
338+
private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name): void {
348339
$notification = $this->notificationManager->createNotification();
349340
$notification->setApp('files_sharing')
350341
->setUser($shareWith)
351342
->setDateTime(new \DateTime())
352343
->setObject('remote_share', $shareId)
353-
->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/'), $sharedBy, $owner]);
344+
->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]);
354345

355346
$declineAction = $notification->createAction();
356347
$declineAction->setLabel('decline')

0 commit comments

Comments
 (0)