Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions apps/files_sharing/src/actions/sharingStatusAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ import { generateAvatarSvg } from '../utils/AccountIcon.ts'
import './sharingStatusAction.scss'

const isExternal = (node: Node) => {
return node.attributes?.['is-federated'] ?? false
return node.attributes.remote_id !== undefined
}

export const action = new FileAction({
id: 'sharing-status',
displayName(nodes: Node[]) {
const node = nodes[0]
const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[]
const ownerId = node?.attributes?.['owner-id']

if (shareTypes.length > 0
|| (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
|| (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
return t('files_sharing', 'Shared')
}

Expand All @@ -55,15 +54,14 @@ export const action = new FileAction({

title(nodes: Node[]) {
const node = nodes[0]
const ownerId = node?.attributes?.['owner-id']
const ownerDisplayName = node?.attributes?.['owner-display-name']

// Mixed share types
if (Array.isArray(node.attributes?.['share-types']) && node.attributes?.['share-types'].length > 1) {
return t('files_sharing', 'Shared multiple times with different people')
}

if (ownerId && (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
const ownerDisplayName = node?.attributes?.['owner-display-name']
return t('files_sharing', 'Shared by {ownerDisplayName}', { ownerDisplayName })
}

Expand Down Expand Up @@ -96,10 +94,9 @@ export const action = new FileAction({
return CircleSvg
}

const ownerId = node?.attributes?.['owner-id']
if (ownerId && (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
const sanitizeId = (id: string) => id.replace(/[^a-zA-Z0-9._%+@-]+/g, '').replace(/\//g, '')
return generateAvatarSvg(sanitizeId(ownerId), isExternal(node))
return generateAvatarSvg(sanitizeId(node.owner), isExternal(node))
}

return AccountPlusSvg
Expand All @@ -111,8 +108,8 @@ export const action = new FileAction({
}

const node = nodes[0]
const ownerId = node?.attributes?.['owner-id']
const isMixed = Array.isArray(node.attributes?.['share-types'])
const shareTypes = node.attributes?.['share-types']
const isMixed = Array.isArray(shareTypes) && shareTypes.length > 0

// If the node is shared multiple times with
// different share types to the current user
Expand All @@ -121,7 +118,7 @@ export const action = new FileAction({
}

// If the node is shared by someone else
if (ownerId && (ownerId !== getCurrentUser()?.uid || isExternal(node))) {
if (node.owner && (node.owner !== getCurrentUser()?.uid || isExternal(node))) {
return true
}

Expand Down
Loading