mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
Merge pull request #29318 from nextcloud/fix/dav-availability-settings-timezone-id
Read and write time zone ID when updating CalDAV availability
This commit is contained in:
commit
9177afe8ab
8 changed files with 61 additions and 23 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -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() {
|
||||
|
|
@ -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) => {
|
||||
|
|
@ -90,6 +97,7 @@ export async function findScheduleInboxAvailability() {
|
|||
|
||||
return {
|
||||
slots,
|
||||
timezoneId,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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))
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
11
package-lock.json
generated
11
package-lock.json
generated
|
|
@ -40,6 +40,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",
|
||||
|
|
@ -13629,6 +13630,11 @@
|
|||
"resolved": "https://registry.npmjs.org/ical.js/-/ical.js-1.4.0.tgz",
|
||||
"integrity": "sha512-ltHZuOFNNjcyEYbzDgjemS7LWIFh2vydJeznxQHUh3dnarbxqOYsWONYteBVAq1MEOHnwXFGN2eskZReHclnrA=="
|
||||
},
|
||||
"node_modules/icalzone": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/icalzone/-/icalzone-0.0.1.tgz",
|
||||
"integrity": "sha512-ln0AM3fMSLLuJijuWuRzwrN0Tg+BG8ADi7ha6slmC7ZqOijagif5I6b4Nl4/vPSXWexnxyrHiEof8VxDOllXVQ=="
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
|
|
@ -34560,6 +34566,11 @@
|
|||
"resolved": "https://registry.npmjs.org/ical.js/-/ical.js-1.4.0.tgz",
|
||||
"integrity": "sha512-ltHZuOFNNjcyEYbzDgjemS7LWIFh2vydJeznxQHUh3dnarbxqOYsWONYteBVAq1MEOHnwXFGN2eskZReHclnrA=="
|
||||
},
|
||||
"icalzone": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/icalzone/-/icalzone-0.0.1.tgz",
|
||||
"integrity": "sha512-ln0AM3fMSLLuJijuWuRzwrN0Tg+BG8ADi7ha6slmC7ZqOijagif5I6b4Nl4/vPSXWexnxyrHiEof8VxDOllXVQ=="
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue