]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(files): sidebar favorite event sync
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Wed, 16 Aug 2023 09:05:02 +0000 (11:05 +0200)
committerJohn Molakvoæ <skjnldsv@protonmail.com>
Thu, 17 Aug 2023 16:56:38 +0000 (18:56 +0200)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
apps/files/src/services/FileInfo.js
apps/files/src/views/Sidebar.vue

index c09af45f495d42f62e2507dae9a8796884bc781b..0b3b0040c26b546c363ad5b65c246ab3fa938c83 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 import axios from '@nextcloud/axios'
+import { davGetDefaultPropfind } from '@nextcloud/files'
 
 /**
  * @param {any} url -
@@ -29,33 +30,7 @@ export default async function(url) {
        const response = await axios({
                method: 'PROPFIND',
                url,
-               data: `<?xml version="1.0"?>
-                       <d:propfind  xmlns:d="DAV:"
-                               xmlns:oc="http://owncloud.org/ns"
-                               xmlns:nc="http://nextcloud.org/ns"
-                               xmlns:ocs="http://open-collaboration-services.org/ns">
-                       <d:prop>
-                               <d:getlastmodified />
-                               <d:getetag />
-                               <d:getcontenttype />
-                               <d:resourcetype />
-                               <oc:fileid />
-                               <oc:permissions />
-                               <oc:size />
-                               <d:getcontentlength />
-                               <nc:has-preview />
-                               <nc:mount-type />
-                               <nc:is-encrypted />
-                               <ocs:share-permissions />
-                               <nc:share-attributes />
-                               <oc:tags />
-                               <oc:favorite />
-                               <oc:comments-unread />
-                               <oc:owner-id />
-                               <oc:owner-display-name />
-                               <oc:share-types />
-                       </d:prop>
-                       </d:propfind>`,
+               data: davGetDefaultPropfind(),
        })
 
        // TODO: create new parser or use cdav-lib when available
index b17aa93e63ed00c307fdfc39641963633e35251a..a2da72ce792f41a47853c801f6ad81c3bc571982 100644 (file)
        </NcAppSidebar>
 </template>
 <script>
+import { emit } from '@nextcloud/event-bus'
 import { encodePath } from '@nextcloud/paths'
+import { File, Folder } from '@nextcloud/files'
+import { getCurrentUser } from '@nextcloud/auth'
+import { Type as ShareTypes } from '@nextcloud/sharing'
 import $ from 'jquery'
 import axios from '@nextcloud/axios'
-import { emit } from '@nextcloud/event-bus'
 import moment from '@nextcloud/moment'
-import { Type as ShareTypes } from '@nextcloud/sharing'
 
 import NcAppSidebar from '@nextcloud/vue/dist/Components/NcAppSidebar.js'
 import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
 import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
 
 import FileInfo from '../services/FileInfo.js'
-import SidebarTab from '../components/SidebarTab.vue'
 import LegacyView from '../components/LegacyView.vue'
+import SidebarTab from '../components/SidebarTab.vue'
 import SystemTags from '../../../systemtags/src/components/SystemTags.vue'
 
 export default {
@@ -253,7 +255,7 @@ export default {
                                return {
                                        key: 'error', // force key to re-render
                                        subname: '',
-                                       title: '',
+                                       name: '',
                                        class: {
                                                'app-sidebar--full': this.isFullScreen,
                                        },
@@ -263,7 +265,7 @@ export default {
                        return {
                                loading: this.loading,
                                subname: '',
-                               title: '',
+                               name: '',
                                class: {
                                        'app-sidebar--full': this.isFullScreen,
                                },
@@ -396,6 +398,19 @@ export default {
                                                ${state ? '</d:set>' : '</d:remove>'}
                                                </d:propertyupdate>`,
                                })
+
+                               /**
+                                * TODO: adjust this when the Sidebar is finally using File/Folder classes
+                                * @see https://github.com/nextcloud/server/blob/8a75cb6e72acd42712ab9fea22296aa1af863ef5/apps/files/src/views/favorites.ts#L83-L115
+                                */
+                               const isDir = this.fileInfo.type === 'dir'
+                               const Node = isDir ? Folder : File
+                               emit(state ? 'files:favorites:added' : 'files:favorites:removed', new Node({
+                                       fileid: this.fileInfo.id,
+                                       source: this.davPath,
+                                       root: `/files/${getCurrentUser().uid}`,
+                                       mime: isDir ? undefined : this.fileInfo.mimetype,
+                               }))
                        } catch (error) {
                                OC.Notification.showTemporary(t('files', 'Unable to change the favourite state of the file'))
                                console.error('Unable to change favourite state', error)