Use the displayname for federated notifications

Since we have the showing this is a lot nicer.
Especially on alrge isntances where the uid can be totally random.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2019-11-18 15:00:33 +01:00
parent bb77c1447b
commit 17fae47bdb
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 24 additions and 12 deletions

View File

@ -102,8 +102,14 @@ class Notifier implements INotifier {
$params = $notification->getSubjectParameters(); $params = $notification->getSubjectParameters();
if ($params[0] !== $params[1] && $params[1] !== null) { if ($params[0] !== $params[1] && $params[1] !== null) {
$notification->setParsedSubject( $notification->setParsedSubject(
$l->t('You received "%3$s" as a remote share from %1$s (on behalf of %2$s)', $params) $l->t('You received "%3$s" as a remote share from %4$s (%1$s) (on behalf of %5$s (%2$s))', $params)
); );
$initiator = $params[0];
$initiatorDisplay = isset($params[3]) ? $params[3] : null;
$owner = $params[1];
$ownerDisplay = isset($params[4]) ? $params[4] : null;
$notification->setRichSubject( $notification->setRichSubject(
$l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'), $l->t('You received {share} as a remote share from {user} (on behalf of {behalf})'),
[ [
@ -112,14 +118,18 @@ class Notifier implements INotifier {
'id' => $notification->getObjectId(), 'id' => $notification->getObjectId(),
'name' => $params[2], 'name' => $params[2],
], ],
'user' => $this->createRemoteUser($params[0]), 'user' => $this->createRemoteUser($initiator, $initiatorDisplay),
'behalf' => $this->createRemoteUser($params[1]), 'behalf' => $this->createRemoteUser($owner, $ownerDisplay),
] ]
); );
} else { } else {
$notification->setParsedSubject( $notification->setParsedSubject(
$l->t('You received "%3$s" as a remote share from %1$s', $params) $l->t('You received "%3$s" as a remote share from %4$s (%1$s)', $params)
); );
$owner = $params[0];
$ownerDisplay = isset($params[3]) ? $params[3] : null;
$notification->setRichSubject( $notification->setRichSubject(
$l->t('You received {share} as a remote share from {user}'), $l->t('You received {share} as a remote share from {user}'),
[ [
@ -128,7 +138,7 @@ class Notifier implements INotifier {
'id' => $notification->getObjectId(), 'id' => $notification->getObjectId(),
'name' => $params[2], 'name' => $params[2],
], ],
'user' => $this->createRemoteUser($params[0]), 'user' => $this->createRemoteUser($owner, $ownerDisplay),
] ]
); );
} }
@ -164,15 +174,17 @@ class Notifier implements INotifier {
* @param string $cloudId * @param string $cloudId
* @return array * @return array
*/ */
protected function createRemoteUser($cloudId) { protected function createRemoteUser($cloudId, $displayName = null) {
$displayName = $cloudId;
try { try {
$resolvedId = $this->cloudIdManager->resolveCloudId($cloudId); $resolvedId = $this->cloudIdManager->resolveCloudId($cloudId);
$displayName = $this->getDisplayName($resolvedId); if ($displayName === null) {
$displayName = $this->getDisplayName($resolvedId);
}
$user = $resolvedId->getUser(); $user = $resolvedId->getUser();
$server = $resolvedId->getRemote(); $server = $resolvedId->getRemote();
} catch (HintException $e) { } catch (HintException $e) {
$user = $cloudId; $user = $cloudId;
$displayName = $cloudId;
$server = ''; $server = '';
} }

View File

@ -245,7 +245,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
->setAffectedUser($shareWith) ->setAffectedUser($shareWith)
->setObject('remote_share', (int)$shareId, $name); ->setObject('remote_share', (int)$shareId, $name);
\OC::$server->getActivityManager()->publish($event); \OC::$server->getActivityManager()->publish($event);
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name); $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner);
} else { } else {
$groupMembers = $this->groupManager->get($shareWith)->getUsers(); $groupMembers = $this->groupManager->get($shareWith)->getUsers();
foreach ($groupMembers as $user) { foreach ($groupMembers as $user) {
@ -256,7 +256,7 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
->setAffectedUser($user->getUID()) ->setAffectedUser($user->getUID())
->setObject('remote_share', (int)$shareId, $name); ->setObject('remote_share', (int)$shareId, $name);
\OC::$server->getActivityManager()->publish($event); \OC::$server->getActivityManager()->publish($event);
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name); $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner);
} }
} }
return $shareId; return $shareId;
@ -333,13 +333,13 @@ class CloudFederationProviderFiles implements ICloudFederationProvider {
* @param $sharedByFederatedId * @param $sharedByFederatedId
* @param $name * @param $name
*/ */
private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name) { private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $sharedBy, $owner) {
$notification = $this->notificationManager->createNotification(); $notification = $this->notificationManager->createNotification();
$notification->setApp('files_sharing') $notification->setApp('files_sharing')
->setUser($shareWith) ->setUser($shareWith)
->setDateTime(new \DateTime()) ->setDateTime(new \DateTime())
->setObject('remote_share', $shareId) ->setObject('remote_share', $shareId)
->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/'), $sharedBy, $owner]);
$declineAction = $notification->createAction(); $declineAction = $notification->createAction();
$declineAction->setLabel('decline') $declineAction->setLabel('decline')