diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-05-25 15:28:09 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-06-09 12:36:39 +0300 |
commit | 738b8e238a30e450d87662c049105281b085a9d0 (patch) | |
tree | 6970133ee37c06a7473f1f7d2c4fc678b5fa1628 /lib | |
parent | 67c6924902b88b5ece48a8b74d481f61a43fc52b (diff) |
Set guest name color also with empty names
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Service/SessionService.php | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index 516045d20..5781b3f47 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -94,9 +94,7 @@ class SessionService { $userName = $this->userId ? $this->userId : $guestName; $session->setUserId($this->userId); $session->setToken($this->secureRandom->generate(64)); - $color = $this->avatarManager->getGuestAvatar($userName)->avatarBackgroundColor($userName); - $color = sprintf("#%02x%02x%02x", $color->r, $color->g, $color->b); - $session->setColor($color); + $session->setColor($this->getColorForGuestName($guestName)); if ($this->userId === null) { $session->setGuestName($guestName); } @@ -222,9 +220,14 @@ class SessionService { } $session = $this->sessionMapper->find($documentId, $sessionId, $sessionToken); $session->setGuestName($guestName); - $color = $this->avatarManager->getGuestAvatar($guestName)->avatarBackgroundColor($guestName); - $color = sprintf("#%02x%02x%02x", $color->r, $color->g, $color->b); - $session->setColor($color); + $session->setColor($this->getColorForGuestName($guestName)); return $this->sessionMapper->update($session); } + + private function getColorForGuestName(string $guestName = null): string { + $guestName = $this->userId ?? $guestName; + $uniqueGuestId = !empty($guestName) ? $guestName : $this->secureRandom->generate(12); + $color = $this->avatarManager->getGuestAvatar($uniqueGuestId)->avatarBackgroundColor($uniqueGuestId); + return sprintf("#%02x%02x%02x", $color->r, $color->g, $color->b); + } } |