aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-10-29 07:31:39 +0100
committerGitHub <noreply@github.com>2024-10-29 07:31:39 +0100
commitbd4c5e19c952cdec95b727a56def055ea7c546b5 (patch)
tree3bd5c6eccc478303042b1c3b259f410671b53992 /apps/files_sharing
parent6fa18c9a8aa7b9f21754a1db66278eeccde1f0eb (diff)
parentcdd62ec85a97a28b16d25287f1b2b7723be4e357 (diff)
downloadnextcloud-server-bd4c5e19c952cdec95b727a56def055ea7c546b5.tar.gz
nextcloud-server-bd4c5e19c952cdec95b727a56def055ea7c546b5.zip
Merge pull request #48887 from nextcloud/fix/federated-users
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/src/utils/AccountIcon.spec.ts40
-rw-r--r--apps/files_sharing/src/utils/AccountIcon.ts18
2 files changed, 54 insertions, 4 deletions
diff --git a/apps/files_sharing/src/utils/AccountIcon.spec.ts b/apps/files_sharing/src/utils/AccountIcon.spec.ts
new file mode 100644
index 00000000000..bbc7f031774
--- /dev/null
+++ b/apps/files_sharing/src/utils/AccountIcon.spec.ts
@@ -0,0 +1,40 @@
+/*!
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import { describe, expect, it, afterEach } from 'vitest'
+import { generateAvatarSvg } from './AccountIcon'
+describe('AccountIcon', () => {
+
+ afterEach(() => {
+ delete document.body.dataset.themes
+ })
+
+ it('should generate regular account avatar svg', () => {
+ const svg = generateAvatarSvg('admin')
+ expect(svg).toContain('/avatar/admin/32')
+ expect(svg).not.toContain('dark')
+ expect(svg).toContain('?guestFallback=true')
+ })
+
+ it('should generate guest account avatar svg', () => {
+ const svg = generateAvatarSvg('admin', true)
+ expect(svg).toContain('/avatar/guest/admin/32')
+ expect(svg).not.toContain('dark')
+ expect(svg).not.toContain('?guestFallback=true')
+ })
+
+ it('should generate dark mode account avatar svg', () => {
+ document.body.dataset.themes = 'dark'
+ const svg = generateAvatarSvg('admin')
+ expect(svg).toContain('/avatar/admin/32/dark')
+ expect(svg).toContain('?guestFallback=true')
+ })
+
+ it('should generate dark mode guest account avatar svg', () => {
+ document.body.dataset.themes = 'dark'
+ const svg = generateAvatarSvg('admin', true)
+ expect(svg).toContain('/avatar/guest/admin/32/dark')
+ expect(svg).not.toContain('?guestFallback=true')
+ })
+})
diff --git a/apps/files_sharing/src/utils/AccountIcon.ts b/apps/files_sharing/src/utils/AccountIcon.ts
index ac126fb1b35..504bb43540e 100644
--- a/apps/files_sharing/src/utils/AccountIcon.ts
+++ b/apps/files_sharing/src/utils/AccountIcon.ts
@@ -4,12 +4,22 @@
*/
import { generateUrl } from '@nextcloud/router'
-const isDarkMode = window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches === true
- || document.querySelector('[data-themes*=dark]') !== null
+const isDarkMode = () => {
+ return window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches === true
+ || document.querySelector('[data-themes*=dark]') !== null
+}
export const generateAvatarSvg = (userId: string, isGuest = false) => {
- const url = isDarkMode ? '/avatar/{userId}/32/dark' : '/avatar/{userId}/32'
- const avatarUrl = generateUrl(isGuest ? url : url + '?guestFallback=true', { userId })
+ // normal avatar url: /avatar/{userId}/32?guestFallback=true
+ // dark avatar url: /avatar/{userId}/32/dark?guestFallback=true
+ // guest avatar url: /avatar/guest/{userId}/32
+ // guest dark avatar url: /avatar/guest/{userId}/32/dark
+ const basePath = isGuest ? `/avatar/guest/${userId}` : `/avatar/${userId}`
+ const darkModePath = isDarkMode() ? '/dark' : ''
+ const guestFallback = isGuest ? '' : '?guestFallback=true'
+
+ const url = `${basePath}/32${darkModePath}${guestFallback}`
+ const avatarUrl = generateUrl(url, { userId })
return `<svg width="32" height="32" viewBox="0 0 32 32"
xmlns="http://www.w3.org/2000/svg" class="sharing-status__avatar">
<image href="${avatarUrl}" height="32" width="32" />