From 6f2670d5d8015ebf899c947458dbf3851d735d8b Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 22 Jul 2026 10:22:12 +0200 Subject: [PATCH] feat(Sharing): Fallback to guest avatar if recipient provides no icon Signed-off-by: provokateurin --- lib/public/Sharing/Recipient/ShareRecipient.php | 11 ++++++++++- tests/lib/Sharing/AbstractSharingManagerTests.php | 10 ++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/public/Sharing/Recipient/ShareRecipient.php b/lib/public/Sharing/Recipient/ShareRecipient.php index c76bf8bee5209..0baf1dac40640 100644 --- a/lib/public/Sharing/Recipient/ShareRecipient.php +++ b/lib/public/Sharing/Recipient/ShareRecipient.php @@ -13,6 +13,7 @@ use OCP\IURLGenerator; use OCP\IUserManager; use OCP\L10N\IFactory; +use OCP\Sharing\Icon\ShareIconURL; use OCP\Sharing\ISharingRegistry; use OCP\Sharing\Share; use OCP\Sharing\ShareUser; @@ -77,12 +78,20 @@ public function format(ISharingRegistry $registry, IFactory $l10nFactory, IURLGe ); } + $icon = $recipientType->getRecipientIcon($this->value); + if ($icon === null) { + $icon = new ShareIconURL( + $urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $displayName, 'size' => 64]), + $urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $displayName, 'size' => 64, 'darkTheme' => true]), + ); + } + return [ 'class' => $this->class, 'value' => $this->value, 'instance' => $this->instance, 'display_name' => $displayName, - 'icon' => $recipientType->getRecipientIcon($this->value)?->format(), + 'icon' => $icon->format(), 'secret' => $secret, 'initiator' => $this->initiator?->format($userManager), ]; diff --git a/tests/lib/Sharing/AbstractSharingManagerTests.php b/tests/lib/Sharing/AbstractSharingManagerTests.php index f88270a2ba521..093ac0948a1eb 100644 --- a/tests/lib/Sharing/AbstractSharingManagerTests.php +++ b/tests/lib/Sharing/AbstractSharingManagerTests.php @@ -2263,7 +2263,10 @@ public function testGetShareAsRecipientWithArguments(): void { 'value' => 'secret', 'instance' => null, 'display_name' => 'secret', - 'icon' => null, + 'icon' => [ + 'light' => 'http://localhost/index.php/avatar/guest/secret/64', + 'dark' => 'http://localhost/index.php/avatar/guest/secret/64?darkTheme=1', + ], 'secret' => [ 'updatable' => false, ], @@ -2388,7 +2391,10 @@ public function testGetShareWithSecretActive(): void { 'value' => 'secret', 'instance' => null, 'display_name' => 'secret', - 'icon' => null, + 'icon' => [ + 'light' => 'http://localhost/index.php/avatar/guest/secret/64', + 'dark' => 'http://localhost/index.php/avatar/guest/secret/64?darkTheme=1', + ], 'secret' => [ 'updatable' => false, ],