From 7a4e0883ba201640a150a392e216ac908a7886c6 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Thu, 22 Aug 2024 23:25:42 +0100 Subject: [PATCH] fix(Federation): Show some icon for federated users on shares Signed-off-by: fenn-cs --- .../src/actions/sharingStatusAction.ts | 28 ++++++------------- apps/files_sharing/src/utils/AccountIcon.ts | 17 +++++++++++ 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 apps/files_sharing/src/utils/AccountIcon.ts diff --git a/apps/files_sharing/src/actions/sharingStatusAction.ts b/apps/files_sharing/src/actions/sharingStatusAction.ts index 4f9648fa27f80..e8d643595c9b2 100644 --- a/apps/files_sharing/src/actions/sharingStatusAction.ts +++ b/apps/files_sharing/src/actions/sharingStatusAction.ts @@ -21,7 +21,7 @@ */ import { Node, View, registerFileAction, FileAction, Permission } from '@nextcloud/files' import { translate as t } from '@nextcloud/l10n' -import { Type } from '@nextcloud/sharing' +import { ShareType } from '@nextcloud/sharing' import AccountGroupSvg from '@mdi/svg/svg/account-group.svg?raw' import AccountPlusSvg from '@mdi/svg/svg/account-plus.svg?raw' @@ -29,23 +29,11 @@ import LinkSvg from '@mdi/svg/svg/link.svg?raw' import CircleSvg from '../../../../core/img/apps/circles.svg?raw' import { action as sidebarAction } from '../../../files/src/actions/sidebarAction' -import { generateUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' +import { generateAvatarSvg } from '../utils/AccountIcon.ts' import './sharingStatusAction.scss' -const isDarkMode = window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches === true - || document.querySelector('[data-themes*=dark]') !== null - -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 `` -} - const isExternal = (node: Node) => { return node.attributes.remote_id !== undefined } @@ -84,6 +72,7 @@ export const action = new FileAction({ iconSvgInline(nodes: Node[]) { const node = nodes[0] + console.debug("Node check", node) const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[] // Mixed share types @@ -92,19 +81,20 @@ export const action = new FileAction({ } // Link shares - if (shareTypes.includes(Type.SHARE_TYPE_LINK) - || shareTypes.includes(Type.SHARE_TYPE_EMAIL)) { + if (shareTypes.includes(ShareType.Link) + || shareTypes.includes(ShareType.Email)) { return LinkSvg } // Group shares - if (shareTypes.includes(Type.SHARE_TYPE_GROUP) - || shareTypes.includes(Type.SHARE_TYPE_REMOTE_GROUP)) { + if (shareTypes.includes(ShareType.Grup) + || shareTypes.includes(ShareType.RemoteGroup)) { return AccountGroupSvg } // Circle shares - if (shareTypes.includes(Type.SHARE_TYPE_CIRCLE)) { + if (shareTypes.includes(ShareType.Team)) { + // Circles was renamed to Teams return CircleSvg } diff --git a/apps/files_sharing/src/utils/AccountIcon.ts b/apps/files_sharing/src/utils/AccountIcon.ts new file mode 100644 index 0000000000000..ac126fb1b35ad --- /dev/null +++ b/apps/files_sharing/src/utils/AccountIcon.ts @@ -0,0 +1,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 `` +}