Skip to content

Commit

Permalink
feat: add organizer selection
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Aug 11, 2024
1 parent 05715c9 commit 7dc7c5b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 150 deletions.
4 changes: 2 additions & 2 deletions src/components/Editor/Invitees/InviteesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default {
return organizerDisplayName(this.calendarObjectInstance.organizer)
},
organizerSelection() {
const organizers = [];
const organizers = []
const owner = this.principalsStore.getPrincipalByUrl(this.calendarInstance.owner)
const principal = this.principalsStore.getCurrentUserPrincipal
if (owner) {
Expand All @@ -244,7 +244,7 @@ export default {
address: owner.emailAddress
})
}
if (principal && owner != principal) {
if (principal && owner.id !== principal.id) {
organizers.push({
id: principal.id,
label: principal.displayname,
Expand Down
149 changes: 1 addition & 148 deletions src/components/Editor/Invitees/OrganizerList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,12 @@ import {
NcAvatar as Avatar,
NcSelect,
} from '@nextcloud/vue'
import { principalPropertySearchByDisplaynameOrEmail } from '../../../services/caldavService.js'
import HttpClient from '@nextcloud/axios'
import debounce from 'debounce'
import { linkTo } from '@nextcloud/router'
import { randomId } from '../../../utils/randomId.js'
import GoogleCirclesCommunitiesIcon from 'vue-material-design-icons/GoogleCirclesCommunities.vue'
import { showInfo } from '@nextcloud/dialogs'
export default {
name: 'OrganizerListSearch',
name: 'OrganizerList',
components: {
Avatar,
NcSelect,
GoogleCirclesCommunitiesIcon,
},
props: {
organizerSelection: {
Expand Down Expand Up @@ -82,148 +74,9 @@ export default {
},
},
methods: {
findAttendees: debounce(async function(query) {
this.isLoading = true
const matches = []
if (query.length > 0) {
const promises = [
this.findAttendeesFromContactsAPI(query),
this.findAttendeesFromDAV(query),
]
const [contactsResults, davResults, circleResults] = await Promise.all(promises)
matches.push(...contactsResults)
matches.push(...davResults)
if (isCirclesEnabled) {
matches.push(...circleResults)
}
// Source of the Regex: https://stackoverflow.com/a/46181
// eslint-disable-next-line
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if (emailRegex.test(query)) {
const alreadyInList = matches.find((attendee) => attendee.email.toLowerCase() === query.toLowerCase())
if (!alreadyInList) {
matches.unshift({
calendarUserType: 'INDIVIDUAL',
commonName: query,
email: query,
isUser: false,
avatar: null,
language: null,
timezoneId: null,
hasMultipleEMails: false,
dropdownName: query,
})
}
}
// Generate a unique id for every result to make the avatar components reactive
for (const match of matches) {
match.uid = randomId()
}
this.isLoading = false
this.inputGiven = true
} else {
this.inputGiven = false
this.isLoading = false
}
this.matches = matches
}, 500),
changeOrganizer(selectedValue) {
this.$emit('change-organizer', selectedValue)
},
async findAttendeesFromContactsAPI(query) {
let response
try {
response = await HttpClient.post(linkTo('calendar', 'index.php') + '/v1/autocompletion/attendee', {
search: query,
})
} catch (error) {
console.debug(error)
return []
}
const data = response.data
return data.reduce((arr, result) => {
const hasMultipleEMails = result.emails.length > 1
result.emails.forEach((email) => {
let name
if (result.name && !hasMultipleEMails) {
name = result.name
} else if (result.name && hasMultipleEMails) {
name = `${result.name} (${email})`
} else {
name = email
}
if (email && this.alreadyInvitedEmails.includes(email)) {
return
}
arr.push({
calendarUserType: 'INDIVIDUAL',
commonName: result.name,
email,
isUser: false,
avatar: result.photo,
language: result.lang,
timezoneId: result.tzid,
hasMultipleEMails,
dropdownName: name,
})
})
return arr
}, [])
},
async findAttendeesFromDAV(query) {
let results
try {
results = await principalPropertySearchByDisplaynameOrEmail(query)
} catch (error) {
console.debug(error)
return []
}
return results.filter((principal) => {
if (!principal.email) {
return false
}
if (this.alreadyInvitedEmails.includes(principal.email)) {
return false
}
// We do not support GROUPS for now
if (principal.calendarUserType === 'GROUP') {
return false
}
// Do not include resources and rooms
if (['ROOM', 'RESOURCE'].includes(principal.calendarUserType)) {
return false
}
return true
}).map((principal) => {
return {
commonName: principal.displayname,
calendarUserType: principal.calendarUserType,
email: principal.email,
language: principal.language,
isUser: principal.calendarUserType === 'INDIVIDUAL',
avatar: decodeURIComponent(principal.userId),
hasMultipleEMails: false,
dropdownName: principal.displayname ? [principal.displayname, principal.email].join(' ') : principal.email,
}
})
},
},
}
</script>

0 comments on commit 7dc7c5b

Please sign in to comment.