]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add authenicated user to person list for search filtering
authorfenn-cs <fenn25.fn@gmail.com>
Tue, 12 Dec 2023 18:46:56 +0000 (19:46 +0100)
committerfenn-cs <fenn25.fn@gmail.com>
Tue, 12 Dec 2023 20:24:52 +0000 (21:24 +0100)
As expected, a user does not see themselves in their contact list,
 however, when using the contact list for filtering search, a user,
 might want to limit the search to things that pertain to them.

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
core/src/services/UnifiedSearchService.js
core/src/views/UnifiedSearchModal.vue

index e477a59eb4cf66f45aacd3fd4a0fa38687985f48..fddbd6b1e1d8372a7d32132bc957f51c4e91f5f1 100644 (file)
@@ -22,6 +22,7 @@
 
 import { generateOcsUrl, generateUrl } from '@nextcloud/router'
 import axios from '@nextcloud/axios'
+import { getCurrentUser } from '@nextcloud/auth'
 
 /**
  * Create a cancel token
@@ -103,5 +104,20 @@ export async function getContacts({ searchTerm }) {
        const { data: { contacts } } = await axios.post(generateUrl('/contactsmenu/contacts'), {
                filter: searchTerm,
        })
+       /*
+        * Add authenticated user to list of contacts for search filter
+        * If authtenicated user is searching/filtering, do not add them to the list
+        */
+       if (!searchTerm) {
+               let authenticatedUser = getCurrentUser()
+               authenticatedUser = {
+                       id: authenticatedUser.uid,
+                       fullName: 'Me',
+                       emailAddresses: [],
+                 }
+               contacts.unshift(authenticatedUser)
+               return contacts
+         }
+
        return contacts
 }
index db13dd29a953997acd78a67005aa35cb17529c0e..49a07136fe830081d3ede0dcc84e2bf463ebc77b 100644 (file)
@@ -194,7 +194,7 @@ export default {
                        filteredProviders: [],
                        searching: false,
                        searchQuery: '',
-                       placesFilter: '',
+                       placessearchTerm: '',
                        dateTimeFilter: null,
                        filters: [],
                        results: [],
@@ -244,7 +244,7 @@ export default {
                        this.providers = providers
                        console.debug('Search providers', this.providers)
                })
-               getContacts({ filter: '' }).then((contacts) => {
+               getContacts({ searchTerm: '' }).then((contacts) => {
                        this.contacts = this.mapContacts(contacts)
                        console.debug('Contacts', this.contacts)
                })
@@ -364,7 +364,7 @@ export default {
                        })
                },
                filterContacts(query) {
-                       getContacts({ filter: query }).then((contacts) => {
+                       getContacts({ searchTerm: query }).then((contacts) => {
                                this.contacts = this.mapContacts(contacts)
                                console.debug(`Contacts filtered by ${query}`, this.contacts)
                        })