Skip to content

Commit

Permalink
fix(Federation): Show some icon for federated users on shares
Browse files Browse the repository at this point in the history
Signed-off-by: fenn-cs <[email protected]>
  • Loading branch information
nfebe committed Sep 15, 2024
1 parent 124b565 commit 7a4e088
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
28 changes: 9 additions & 19 deletions apps/files_sharing/src/actions/sharingStatusAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,19 @@
*/
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'
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 `<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>`
}

const isExternal = (node: Node) => {
return node.attributes.remote_id !== undefined
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
17 changes: 17 additions & 0 deletions apps/files_sharing/src/utils/AccountIcon.ts
Original file line number Diff line number Diff line change
@@ -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 `<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>`
}

0 comments on commit 7a4e088

Please sign in to comment.