Skip to content

Commit 03fcf5f

Browse files
committed
Add authenicated user to person list for search filtering
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>
1 parent 5b7a523 commit 03fcf5f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

core/src/services/UnifiedSearchService.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
2424
import axios from '@nextcloud/axios'
25+
import { getCurrentUser } from '@nextcloud/auth'
2526

2627
/**
2728
* Create a cancel token
@@ -103,5 +104,20 @@ export async function getContacts({ searchTerm }) {
103104
const { data: { contacts } } = await axios.post(generateUrl('/contactsmenu/contacts'), {
104105
filter: searchTerm,
105106
})
107+
/*
108+
* Add authenticated user to list of contacts for search filter
109+
* If authtenicated user is searching/filtering, do not add them to the list
110+
*/
111+
if (!searchTerm) {
112+
let authenticatedUser = getCurrentUser()
113+
authenticatedUser = {
114+
id: authenticatedUser.uid,
115+
fullName: 'Me',
116+
emailAddresses: [],
117+
}
118+
contacts.unshift(authenticatedUser)
119+
return contacts
120+
}
121+
106122
return contacts
107123
}

core/src/views/UnifiedSearchModal.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export default {
194194
filteredProviders: [],
195195
searching: false,
196196
searchQuery: '',
197-
placesFilter: '',
197+
placessearchTerm: '',
198198
dateTimeFilter: null,
199199
filters: [],
200200
results: [],
@@ -244,7 +244,7 @@ export default {
244244
this.providers = providers
245245
console.debug('Search providers', this.providers)
246246
})
247-
getContacts({ filter: '' }).then((contacts) => {
247+
getContacts({ searchTerm: '' }).then((contacts) => {
248248
this.contacts = this.mapContacts(contacts)
249249
console.debug('Contacts', this.contacts)
250250
})
@@ -364,7 +364,7 @@ export default {
364364
})
365365
},
366366
filterContacts(query) {
367-
getContacts({ filter: query }).then((contacts) => {
367+
getContacts({ searchTerm: query }).then((contacts) => {
368368
this.contacts = this.mapContacts(contacts)
369369
console.debug(`Contacts filtered by ${query}`, this.contacts)
370370
})

0 commit comments

Comments
 (0)