mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
Merge pull request #58335 from nextcloud/lazy-share-recipient-displayname
feat: delay fetching the display name of a share recipient untill we need it
This commit is contained in:
commit
0ea5449683
2 changed files with 21 additions and 12 deletions
|
|
@ -1118,16 +1118,10 @@ class DefaultShareProvider implements
|
|||
|
||||
if ($share->getShareType() === IShare::TYPE_USER) {
|
||||
$share->setSharedWith($data['share_with']);
|
||||
$displayName = $this->userManager->getDisplayName($data['share_with']);
|
||||
if ($displayName !== null) {
|
||||
$share->setSharedWithDisplayName($displayName);
|
||||
}
|
||||
$share->setSharedWithDisplayNameCallback(fn (IShare $share) => $this->userManager->getDisplayName($share->getSharedWith()));
|
||||
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
||||
$share->setSharedWith($data['share_with']);
|
||||
$group = $this->groupManager->get($data['share_with']);
|
||||
if ($group !== null) {
|
||||
$share->setSharedWithDisplayName($group->getDisplayName());
|
||||
}
|
||||
$share->setSharedWithDisplayNameCallback(fn (IShare $share) => $this->groupManager->getDisplayName($share->getSharedWith()));
|
||||
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
|
||||
$share->setPassword($data['password']);
|
||||
$share->setSendPasswordByTalk((bool)$data['password_by_talk']);
|
||||
|
|
@ -1488,6 +1482,7 @@ class DefaultShareProvider implements
|
|||
|
||||
/**
|
||||
* For each user the path with the fewest slashes is returned
|
||||
*
|
||||
* @param array $shares
|
||||
* @return array
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -35,8 +35,9 @@ class Share implements IShare {
|
|||
private $shareType;
|
||||
/** @var string */
|
||||
private $sharedWith;
|
||||
/** @var string */
|
||||
private $sharedWithDisplayName;
|
||||
private ?string $sharedWithDisplayName = null;
|
||||
/** @var ?callable */
|
||||
private $sharedWithDisplayNameCallback = null;
|
||||
/** @var string */
|
||||
private $sharedWithAvatar;
|
||||
/** @var string */
|
||||
|
|
@ -260,11 +261,24 @@ class Share implements IShare {
|
|||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @param callable(IShare):?string $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function setSharedWithDisplayNameCallback(callable $callback) {
|
||||
$this->sharedWithDisplayNameCallback = $callback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getSharedWithDisplayName() {
|
||||
return $this->sharedWithDisplayName;
|
||||
if ($this->sharedWithDisplayNameCallback !== null) {
|
||||
$displayName = ($this->sharedWithDisplayNameCallback)($this);
|
||||
if ($displayName !== null) {
|
||||
$this->sharedWithDisplayName = $displayName;
|
||||
}
|
||||
$this->sharedWithDisplayNameCallback = null;
|
||||
}
|
||||
return $this->sharedWithDisplayName ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue