Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read and write time zone ID when updating CalDAV availability #29318

Merged
merged 2 commits into from
Oct 25, 2021
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
4 changes: 2 additions & 2 deletions apps/dav/js/settings-admin-caldav.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/dav/js/settings-admin-caldav.js.map

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions 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.

29 changes: 26 additions & 3 deletions apps/dav/src/service/CalendarService.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getClient } from '../dav/client'
import ICAL from 'ical.js'
import logger from './logger'
import { parseXML } from 'webdav/dist/node/tools/dav'
import { getZoneString } from 'icalzone'
import { v4 as uuidv4 } from 'uuid'

export function getEmptySlots() {
Expand Down Expand Up @@ -64,8 +65,14 @@ export async function findScheduleInboxAvailability() {

const vcalendarComp = new ICAL.Component(parsedIcal)
const vavailabilityComp = vcalendarComp.getFirstSubcomponent('vavailability')
const availableComps = vavailabilityComp.getAllSubcomponents('available')

let timezoneId
const timezoneComp = vcalendarComp.getFirstSubcomponent('vtimezone')
if (timezoneComp) {
timezoneId = timezoneComp.getFirstProperty('tzid').getFirstValue()
}

const availableComps = vavailabilityComp.getAllSubcomponents('available')
// Combine all AVAILABLE blocks into a week of slots
const slots = getEmptySlots()
availableComps.forEach((availableComp) => {
Expand All @@ -90,6 +97,7 @@ export async function findScheduleInboxAvailability() {

return {
slots,
timezoneId,
}
}

Expand All @@ -99,6 +107,23 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
day: dayId,
})))]

const vcalendarComp = new ICAL.Component('vcalendar')
vcalendarComp.addPropertyWithValue('prodid', 'Nextcloud DAV app')

// Store time zone info
// If possible we use the info from a time zone database
const predefinedTimezoneIcal = getZoneString(timezoneId)
if (predefinedTimezoneIcal) {
const timezoneComp = new ICAL.Component(ICAL.parse(predefinedTimezoneIcal))
vcalendarComp.addSubcomponent(timezoneComp)
} else {
// Fall back to a simple markup
const timezoneComp = new ICAL.Component('vtimezone')
timezoneComp.addPropertyWithValue('tzid', timezoneId)
vcalendarComp.addSubcomponent(timezoneComp)
}

// Store availability info
const vavailabilityComp = new ICAL.Component('vavailability')

// Deduplicate by start and end time
Expand Down Expand Up @@ -127,7 +152,6 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
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(start, false))
startTimeProp.setParameter('tzid', timezoneId)
const endTimeProp = availableComp.addPropertyWithValue('dtend', ICAL.Time.fromJSDate(end, false))
Expand All @@ -147,7 +171,6 @@ export async function saveScheduleInboxAvailability(slots, timezoneId) {
return availableComp
}).map(vavailabilityComp.addSubcomponent.bind(vavailabilityComp))

const vcalendarComp = new ICAL.Component('vcalendar')
vcalendarComp.addSubcomponent(vavailabilityComp)
logger.debug('New availability ical created', {
asObject: vcalendarComp,
Expand Down
5 changes: 4 additions & 1 deletion apps/dav/src/views/Availability.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,15 @@ export default {
},
async mounted() {
try {
const { slots } = await findScheduleInboxAvailability()
const { slots, timezoneId } = await findScheduleInboxAvailability()
if (slots) {
this.daysOfTheWeek.forEach(day => {
day.slots.push(...slots[day.id])
})
}
if (timezoneId) {
this.timezone = timezoneId
}
console.info('availability loaded', this.daysOfTheWeek)
} catch (e) {
console.error('could not load existing availability', e)
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"escape-html": "^1.0.3",
"handlebars": "^4.7.7",
"ical.js": "^1.4.0",
"icalzone": "^0.0.1",
"jquery": "~3.3",
"jquery-migrate": "~3.3",
"jquery-ui": "^1.13.0",
Expand Down