aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/utils/AccountIcon.ts
blob: ac126fb1b35ad3101a46852a46061b69c984e279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*!
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
import { generateUrl } from '@nextcloud/router'

const isDarkMode = 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 })
	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" />
	</svg>`
}