Skip to content

Commit

Permalink
feat(attendee): expose member parameter
Browse files Browse the repository at this point in the history
Idea and original code by Jonas Heinrich (@onny).

Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
onny authored and st3iny committed Oct 27, 2023
1 parent 8ee49fb commit 47261c0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/properties/attendeeProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand Down Expand Up @@ -207,6 +208,25 @@ export default class AttendeeProperty extends Property {
this.value = startStringWith(email, 'mailto:')
}

/**
* Gets the email addresses of groups the attendee is a part of
*
* @return {string[]|null} The email addresses of the groups
*/
get member() {
return this.getParameter('MEMBER')?.value ?? null
}

/**
* Sets the email addresses of groups the attendee is a part of
*
* @param {string[]} members The email addresses of the groups
*/
set member(members) {
members = members.map(member => startStringWith(member, 'mailto:'))
this.updateParameterIfExist('MEMBER', members)
}

/**
* Is this attendee the organizer?
*
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/properties/attendeeProperty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @copyright Copyright (c) 2019 Georg Ehrke
*
* @author Georg Ehrke <[email protected]>
* @author Richard Steinmetz <[email protected]>
*
* @license AGPL-3.0-or-later
*
Expand Down Expand Up @@ -265,6 +266,38 @@ it('AttendeeProperty should provide easy getter/setter for email', () => {
expect(property.email).toEqual('mailto:[email protected]')
})

it('AttendeeProperty should provide easy getter/setter for member', () => {
const icalValue = ICAL.Property.fromString('ATTENDEE;MEMBER="mailto:[email protected]","mailto:[email protected]":mailto:[email protected]')
const property = AttendeeProperty.fromICALJs(icalValue)

expect(property.member).toEqual(['mailto:[email protected]', 'mailto:[email protected]'])

property.member = ['[email protected]']
expect(property.member).toEqual(['mailto:[email protected]'])

property.lock()
expect(property.isLocked()).toEqual(true)

expect(() => {
property.member = ['mailto:[email protected]']
}).toThrow(ModificationNotAllowedError)
expect(property.member).toEqual(['mailto:[email protected]'])

property.unlock()

property.member = ['[email protected]', 'mailto:[email protected]']
expect(property.member).toEqual(['mailto:[email protected]', 'mailto:[email protected]'])

expect(property.toICALJs().toICALString()).toEqual('ATTENDEE;MEMBER="mailto:[email protected]","mailto:[email protected]":mailto:[email protected]')
})

it('AttendeeProperty should handle missing member gracefully', () => {
const icalValue = ICAL.Property.fromString('ATTENDEE;CN=Foo;PARTSTAT=DECLINED123;LANGUAGE=EN:mailto:[email protected]')
const property = AttendeeProperty.fromICALJs(icalValue)

expect(property.member).toEqual(null)
})

it('AttendeeProperty should provide easy getter/setter for commonName', () => {
const icalValue = ICAL.Property.fromString('ATTENDEE;CN=Foo;PARTSTAT=DECLINED123;LANGUAGE=EN:mailto:[email protected]')
const property = AttendeeProperty.fromICALJs(icalValue)
Expand Down

0 comments on commit 47261c0

Please sign in to comment.