Skip to content

Commit

Permalink
Merge pull request #29334 from nextcloud/fix/dav-availability-setting…
Browse files Browse the repository at this point in the history
…s-duplicate-slots
  • Loading branch information
skjnldsv authored Oct 20, 2021
2 parents 1021c89 + e23a38e commit 49e727f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/apps/comments/js/*.js.map binary
/apps/dashboard/js/*.js binary
/apps/dashboard/js/*.js.map binary
/apps/dav/js/*.js binary
/apps/dav/js/*.js.map binary
/apps/files/js/dist/*.js binary
/apps/files/js/dist/*.js.map binary
/apps/files_sharing/js/dist/*.js binary
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/js/settings-personal-availability.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/dav/js/settings-personal-availability.js.map

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions apps/dav/src/service/CalendarService.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,37 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
})))]

const vavailabilityComp = new ICAL.Component('vavailability')
// TODO: deduplicate slots that occur on more than one day
all.map(slot => {

// Deduplicate by start and end time
const deduplicated = all.reduce((acc, slot) => {
const key = [
slot.start.getHours(),
slot.start.getMinutes(),
slot.end.getHours(),
slot.end.getMinutes(),
].join('-')

return {
...acc,
[key]: [...(acc[key] ?? []), slot],
}
}, {})

// Create an AVAILABILITY component for every recurring slot
Object.keys(deduplicated).map(key => {
const slots = deduplicated[key]
const start = slots[0].start
const end = slots[0].end
// Combine days but make them also unique
const days = slots.map(slot => slot.day).filter((day, index, self) => self.indexOf(day) === index)

const availableComp = new ICAL.Component('available')

// Define DTSTART and DTEND
// TODO: tz? moment.tz(dateTime, timezone).toDate()
const startTimeProp = availableComp.addPropertyWithValue('dtstart', ICAL.Time.fromJSDate(slot.start, false))
const startTimeProp = availableComp.addPropertyWithValue('dtstart', ICAL.Time.fromJSDate(start, false))
startTimeProp.setParameter('tzid', timezoneId)
const endTimeProp = availableComp.addPropertyWithValue('dtend', ICAL.Time.fromJSDate(slot.end, false))
const endTimeProp = availableComp.addPropertyWithValue('dtend', ICAL.Time.fromJSDate(end, false))
endTimeProp.setParameter('tzid', timezoneId)

// Add mandatory UID
Expand All @@ -119,7 +141,7 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
// Define RRULE
availableComp.addPropertyWithValue('rrule', {
freq: 'WEEKLY',
byday: slot.day,
byday: days,
})

return availableComp
Expand Down

0 comments on commit 49e727f

Please sign in to comment.