diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2021-09-15 15:39:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-15 15:39:08 +0300 |
commit | 46a6bf0693b8d192632e1e2b5845ff3f63f249c0 (patch) | |
tree | 686f3f759d7bd3670f9318c75f774da97e087787 /lib | |
parent | 3307603fe1583fd0242bf677b0b45808445f9192 (diff) | |
parent | a95bf0820d4d34f9eaa749ec3ca020acc635355f (diff) |
Merge pull request #6205 from nextcloud/bugfix/3598/inconsistent-handling-of-deleted-users
Unify handling of deleted users
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Chat/Parser/SystemMessage.php | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index ad63f4f7e..8c69a2140 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -68,7 +68,9 @@ class SystemMessage { /** @var IL10N */ protected $l; - /** @var string[] */ + /** + * @psalm-var array<array-key, null|string> + */ protected $displayNames = []; /** @var string[] */ protected $groupNames = []; @@ -584,7 +586,19 @@ class SystemMessage { protected function getUser(string $uid): array { if (!isset($this->displayNames[$uid])) { - $this->displayNames[$uid] = $this->getDisplayName($uid); + try { + $this->displayNames[$uid] = $this->getDisplayName($uid); + } catch (ParticipantNotFoundException $e) { + $this->displayNames[$uid] = null; + } + } + + if ($this->displayNames[$uid] === null) { + return [ + 'type' => 'highlight', + 'id' => 'deleted_user', + 'name' => $this->l->t('Deleted user'), + ]; } return [ @@ -594,6 +608,15 @@ class SystemMessage { ]; } + protected function getDisplayName(string $uid): string { + $user = $this->userManager->get($uid); + if ($user instanceof IUser) { + return $user->getDisplayName(); + } + + throw new ParticipantNotFoundException(); + } + protected function getGroup(string $gid): array { if (!isset($this->groupNames[$gid])) { $this->groupNames[$gid] = $this->getDisplayNameGroup($gid); @@ -627,14 +650,6 @@ class SystemMessage { ]; } - protected function getDisplayName(string $uid): string { - $user = $this->userManager->get($uid); - if ($user instanceof IUser) { - return $user->getDisplayName(); - } - return $uid; - } - protected function getDisplayNameGroup(string $gid): string { $group = $this->groupManager->get($gid); if ($group instanceof IGroup) { |