2020 *
2121 */
2222import { Node , View , registerFileAction , FileAction , Permission } from '@nextcloud/files'
23- import { translate as t } from '@nextcloud/l10n'
24- import { Type } from '@nextcloud/sharing'
23+ import { t } from '@nextcloud/l10n'
24+ import { ShareType } from '@nextcloud/sharing'
2525
2626import AccountGroupSvg from '@mdi/svg/svg/account-group.svg?raw'
2727import AccountPlusSvg from '@mdi/svg/svg/account-plus.svg?raw'
@@ -55,17 +55,31 @@ export const action = new FileAction({
5555 title ( nodes : Node [ ] ) {
5656 const node = nodes [ 0 ]
5757
58- // Mixed share types
59- if ( Array . isArray ( node . attributes ?. [ 'share-types' ] ) && node . attributes ?. [ 'share-types' ] . length > 1 ) {
60- return t ( 'files_sharing' , 'Shared multiple times with different people' )
61- }
62-
6358 if ( node . owner && ( node . owner !== getCurrentUser ( ) ?. uid || isExternal ( node ) ) ) {
6459 const ownerDisplayName = node ?. attributes ?. [ 'owner-display-name' ]
6560 return t ( 'files_sharing' , 'Shared by {ownerDisplayName}' , { ownerDisplayName } )
6661 }
6762
68- return t ( 'files_sharing' , 'Show sharing options' )
63+ const shareTypes = Object . values ( node ?. attributes ?. [ 'share-types' ] || { } ) . flat ( ) as number [ ]
64+ if ( shareTypes . length > 1 ) {
65+ return t ( 'files_sharing' , 'Shared multiple times with different people' )
66+ }
67+
68+ const sharees = node . attributes . sharees ?. sharee as { id : string , 'display-name' : string , type : ShareType } [ ] | undefined
69+ if ( ! sharees ) {
70+ // No sharees so just show the default message to create a new share
71+ return t ( 'files_sharing' , 'Show sharing options' )
72+ }
73+
74+ const sharee = [ sharees ] . flat ( ) [ 0 ] // the property is sometimes weirdly normalized, so we need to compensate
75+ switch ( sharee . type ) {
76+ case ShareType . User :
77+ return t ( 'files_sharing' , 'Shared with {user}' , { user : sharee [ 'display-name' ] } )
78+ case ShareType . Group :
79+ return t ( 'files_sharing' , 'Shared with group {group}' , { group : sharee [ 'display-name' ] ?? sharee . id } )
80+ default :
81+ return t ( 'files_sharing' , 'Shared with others' )
82+ }
6983 } ,
7084
7185 iconSvgInline ( nodes : Node [ ] ) {
@@ -78,25 +92,24 @@ export const action = new FileAction({
7892 }
7993
8094 // Link shares
81- if ( shareTypes . includes ( Type . SHARE_TYPE_LINK )
82- || shareTypes . includes ( Type . SHARE_TYPE_EMAIL ) ) {
95+ if ( shareTypes . includes ( ShareType . Link )
96+ || shareTypes . includes ( ShareType . Email ) ) {
8397 return LinkSvg
8498 }
8599
86100 // Group shares
87- if ( shareTypes . includes ( Type . SHARE_TYPE_GROUP )
88- || shareTypes . includes ( Type . SHARE_TYPE_REMOTE_GROUP ) ) {
101+ if ( shareTypes . includes ( ShareType . Group )
102+ || shareTypes . includes ( ShareType . RemoteGroup ) ) {
89103 return AccountGroupSvg
90104 }
91105
92106 // Circle shares
93- if ( shareTypes . includes ( Type . SHARE_TYPE_CIRCLE ) ) {
107+ if ( shareTypes . includes ( ShareType . Team ) ) {
94108 return CircleSvg
95109 }
96110
97111 if ( node . owner && ( node . owner !== getCurrentUser ( ) ?. uid || isExternal ( node ) ) ) {
98- const sanitizeId = ( id : string ) => id . replace ( / [ ^ a - z A - Z 0 - 9 . _ % + @ - ] + / g, '' ) . replace ( / \/ / g, '' )
99- return generateAvatarSvg ( sanitizeId ( node . owner ) , isExternal ( node ) )
112+ return generateAvatarSvg ( node . owner , isExternal ( node ) )
100113 }
101114
102115 return AccountPlusSvg
@@ -118,7 +131,7 @@ export const action = new FileAction({
118131 }
119132
120133 // If the node is shared by someone else
121- if ( node . owner && ( node . owner !== getCurrentUser ( ) ?. uid || isExternal ( node ) ) ) {
134+ if ( node . owner !== getCurrentUser ( ) ?. uid || isExternal ( node ) ) {
122135 return true
123136 }
124137
0 commit comments