5555use OCP\IURLGenerator;
5656use OCP\IUserManager;
5757use OCP\Notification\IManager as INotificationManager;
58+ use OCP\Server;
5859use OCP\Share\Exceptions\ShareNotFound;
5960use OCP\Share\IManager;
6061use OCP\Share\IShare;
6162use OCP\Util;
63+ use Psr\Container\ContainerExceptionInterface;
64+ use Psr\Log\LoggerInterface;
6265
6366class CloudFederationProviderFiles implements ICloudFederationProvider {
6467
@@ -250,26 +253,29 @@ public function shareReceived(ICloudFederationShare $share) {
250253 $this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType,false, $shareWith, $remoteId);
251254 $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
252255
256+ // get DisplayName about the owner of the share
257+ $ownerDisplayName = $this->getUserDisplayName($ownerFederatedId);
258+
253259 if ($shareType === IShare::TYPE_USER) {
254260 $event = $this->activityManager->generateEvent();
255261 $event->setApp('files_sharing')
256262 ->setType('remote_share')
257- ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
263+ ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName ])
258264 ->setAffectedUser($shareWith)
259265 ->setObject('remote_share', $shareId, $name);
260266 \OC::$server->getActivityManager()->publish($event);
261- $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name);
267+ $this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName );
262268 } else {
263269 $groupMembers = $this->groupManager->get($shareWith)->getUsers();
264270 foreach ($groupMembers as $user) {
265271 $event = $this->activityManager->generateEvent();
266272 $event->setApp('files_sharing')
267273 ->setType('remote_share')
268- ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
274+ ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/'), $ownerDisplayName ])
269275 ->setAffectedUser($user->getUID())
270276 ->setObject('remote_share', $shareId, $name);
271277 \OC::$server->getActivityManager()->publish($event);
272- $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name);
278+ $this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName );
273279 }
274280 }
275281 return $shareId;
@@ -335,13 +341,13 @@ private function mapShareTypeToNextcloud($shareType) {
335341 return $result;
336342 }
337343
338- private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name): void {
344+ private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $displayName ): void {
339345 $notification = $this->notificationManager->createNotification();
340346 $notification->setApp('files_sharing')
341347 ->setUser($shareWith)
342348 ->setDateTime(new \DateTime())
343349 ->setObject('remote_share', $shareId)
344- ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]);
350+ ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/'), $displayName ]);
345351
346352 $declineAction = $notification->createAction();
347353 $declineAction->setLabel('decline')
@@ -579,6 +585,8 @@ private function unshare($id, array $notification) {
579585 ->where($qb->expr()->eq('parent', $qb->createNamedParameter((int)$share['id'])));
580586 $qb->execute();
581587
588+ $ownerDisplayName = $this->getUserDisplayName($owner->getId());
589+
582590 if ((int)$share['share_type'] === IShare::TYPE_USER) {
583591 if ($share['accepted']) {
584592 $path = trim($mountpoint, '/');
@@ -594,7 +602,7 @@ private function unshare($id, array $notification) {
594602 $event = $this->activityManager->generateEvent();
595603 $event->setApp('files_sharing')
596604 ->setType('remote_share')
597- ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])
605+ ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path, $ownerDisplayName ])
598606 ->setAffectedUser($user)
599607 ->setObject('remote_share', (int)$share['id'], $path);
600608 \OC::$server->getActivityManager()->publish($event);
@@ -824,4 +832,25 @@ private function isS2SEnabled($incoming = false) {
824832 public function getSupportedShareTypes() {
825833 return ['user', 'group'];
826834 }
835+
836+
837+ public function getUserDisplayName(string $userId): string {
838+ // check if gss is enabled and available
839+ if (!$this->appManager->isInstalled('globalsiteselector')
840+ || !class_exists('\OCA\GlobalSiteSelector\Service\SlaveService')) {
841+ return '';
842+ }
843+
844+ try {
845+ $slaveService = Server::get(\OCA\GlobalSiteSelector\Service\SlaveService::class);
846+ } catch (\Throwable $e) {
847+ Server::get(LoggerInterface::class)->error(
848+ $e->getMessage(),
849+ ['exception' => $e]
850+ );
851+ return '';
852+ }
853+
854+ return $slaveService->getUserDisplayName($this->cloudIdManager->removeProtocolFromUrl($userId), false);
855+ }
827856}
0 commit comments