Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/components/Imip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,20 @@ const DECLINED = 'DECLINED'
* Search a vEvent for an attendee by mail.
*
* @param {EventComponent|undefined|null} vEvent The event providing the attendee haystack.
* @param {string} email The email address (with or without a mailto prefix) to use as the needle.
* @param {Array<string>} addresses The email address (with or without a mailto prefix) to use as the needle.
* @return {AttendeeProperty|undefined} The attendee property or undefined if the given email is not matching an attendee.
*/
function findAttendee(vEvent, email) {
if (!vEvent) {
function findAttendee(vEvent, addresses) {
if (!vEvent || !addresses || addresses.length === 0) {
return undefined
}

email = removeMailtoPrefix(email)
addresses = addresses
.map(addr => addr.toLowerCase())
.filter(addr => addr.startsWith('mailto:'))
.map(removeMailtoPrefix)
for (const attendee of [...vEvent.getPropertyIterator('ORGANIZER'), ...vEvent.getAttendeeIterator()]) {
if (removeMailtoPrefix(attendee.email) === email) {
if (addresses.includes(removeMailtoPrefix(attendee.email.toLowerCase()))) {
return attendee
}
}
Expand Down Expand Up @@ -305,7 +308,10 @@ export default {
* @return {boolean}
*/
userIsAttendee() {
return !!findAttendee(this.attachedVEvent, this.currentUserPrincipalEmail)
return !!findAttendee(
this.attachedVEvent,
this.currentUserPrincipal.calendarUserAddressSet?.length ? this.currentUserPrincipal.calendarUserAddressSet : [this.currentUserPrincipalEmail],
)
},

/**
Expand All @@ -314,7 +320,10 @@ export default {
* @return {string|undefined}
*/
existingParticipationStatus() {
const attendee = findAttendee(this.existingVEvent, this.currentUserPrincipalEmail)
const attendee = findAttendee(
this.existingVEvent,
this.currentUserPrincipal.calendarUserAddressSet?.length ? this.currentUserPrincipal.calendarUserAddressSet : [this.currentUserPrincipalEmail],
)
return attendee?.participationStatus ?? undefined
},

Expand Down Expand Up @@ -428,7 +437,10 @@ export default {
vCalendar = this.attachedVCalendar
}
const vEvent = vCalendar.getFirstComponent('VEVENT')
const attendee = findAttendee(vEvent, this.currentUserPrincipalEmail)
const attendee = findAttendee(
vEvent,
this.currentUserPrincipal.calendarUserAddressSet?.length ? this.currentUserPrincipal.calendarUserAddressSet : [this.currentUserPrincipalEmail],
)
if (!attendee) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/eventAttendee.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @return {string} URI without a mailto prefix
*/
export function removeMailtoPrefix(uri) {
if (uri.startsWith('mailto:') || uri.startsWith('MAILTO:')) {
if (uri.toLowerCase().startsWith('mailto:')) {
return uri.substring(7)
}

Expand Down
Loading