@@ -32,6 +32,10 @@ import { getContents } from './services/trashbin'
3232import './actions/restoreAction'
3333import { Column , Node , View , getNavigation } from '@nextcloud/files'
3434import { dirname , joinPaths } from '@nextcloud/paths'
35+ import { getCurrentUser } from '@nextcloud/auth'
36+
37+ import Vue from 'vue'
38+ import NcUserBubble from '@nextcloud/vue/dist/Components/NcUserBubble.js'
3539
3640const parseOriginalLocation = ( node : Node ) : string => {
3741 const path = node . attributes ?. [ 'trashbin-original-location' ] !== undefined ? String ( node . attributes ?. [ 'trashbin-original-location' ] ) : null
@@ -45,6 +49,34 @@ const parseOriginalLocation = (node: Node): string => {
4549 return joinPaths ( t ( 'files_trashbin' , 'All files' ) , dir )
4650}
4751
52+ interface DeletedBy {
53+ userId : null | string
54+ displayName : null | string
55+ label : null | string
56+ }
57+
58+ const generateLabel = ( userId : null | string , displayName : null | string ) => {
59+ const currentUserId = getCurrentUser ( ) ?. uid
60+ if ( userId === currentUserId ) {
61+ return t ( 'files_trashbin' , 'You' )
62+ }
63+ if ( ! userId && ! displayName ) {
64+ return t ( 'files_trashbin' , 'Unknown' )
65+ }
66+ return null
67+ }
68+
69+ const parseDeletedBy = ( node : Node ) : DeletedBy => {
70+ const userId = node . attributes ?. [ 'trashbin-deleted-by-id' ] !== undefined ? String ( node . attributes ?. [ 'trashbin-deleted-by-id' ] ) : null
71+ const displayName = node . attributes ?. [ 'trashbin-deleted-by-display-name' ] !== undefined ? String ( node . attributes ?. [ 'trashbin-deleted-by-display-name' ] ) : null
72+ const label = generateLabel ( userId , displayName )
73+ return {
74+ userId,
75+ displayName,
76+ label,
77+ }
78+ }
79+
4880const Navigation = getNavigation ( )
4981Navigation . register ( new View ( {
5082 id : 'trashbin' ,
@@ -78,6 +110,33 @@ Navigation.register(new View({
78110 } ,
79111 } ) ,
80112
113+ new Column ( {
114+ id : 'deleted-by' ,
115+ title : t ( 'files_trashbin' , 'Deleted by' ) ,
116+ render ( node ) {
117+ const { userId, displayName, label } = parseDeletedBy ( node )
118+ if ( label ) {
119+ const span = document . createElement ( 'span' )
120+ span . textContent = label
121+ return span
122+ }
123+
124+ const UserBubble = Vue . extend ( NcUserBubble )
125+ const propsData = {
126+ size : 32 ,
127+ user : userId ?? undefined ,
128+ displayName : displayName ?? t ( 'files_trashbin' , 'Unknown' ) ,
129+ }
130+ const userBubble = new UserBubble ( { propsData } ) . $mount ( ) . $el
131+ return userBubble as HTMLElement
132+ } ,
133+ sort ( nodeA , nodeB ) {
134+ const deletedByA = parseDeletedBy ( nodeA ) . label ?? parseDeletedBy ( nodeA ) . displayName ?? t ( 'files_trashbin' , 'Unknown' )
135+ const deletedByB = parseDeletedBy ( nodeB ) . label ?? parseDeletedBy ( nodeB ) . displayName ?? t ( 'files_trashbin' , 'Unknown' )
136+ return deletedByA . localeCompare ( deletedByB )
137+ } ,
138+ } ) ,
139+
81140 new Column ( {
82141 id : 'deleted' ,
83142 title : t ( 'files_trashbin' , 'Deleted' ) ,
0 commit comments