Add a 'days with events' preference (default 3, range 1-7) that drives the upcoming events widget, and extend the fetch window to 8 days so the largest window can populate. Add a Calendar settings pane (moved under Integrations) that lists the connected CalDAV/ICS sources in a two-column grid with add/edit/remove, and remove calendars from Manage Integrations. Turn the modal service into a stack so add/edit forms open on top of the settings dialog, with one dialog per level, per-entry title ids, and a softened stacked backdrop. Move CALENDAR_ACTOR into its own config module to break the calendar/caldav/ics import cycle.
73 lines
1.9 KiB
JavaScript
73 lines
1.9 KiB
JavaScript
import { CALENDAR_ACTOR } from './calendar-actor';
|
|
|
|
export const CALDAV_TYPE = 'calendar-caldav';
|
|
|
|
// A CalDAV URL keeps its path (servers live under paths like `/remote.php/dav/`),
|
|
// so only the scheme is added when missing.
|
|
export function normalizeCaldavUrl(input) {
|
|
let value = (input ?? '').trim();
|
|
|
|
if (!value || /\s/.test(value)) {
|
|
return null;
|
|
}
|
|
|
|
if (!/^https?:\/\//i.test(value)) {
|
|
value = `https://${value}`;
|
|
}
|
|
|
|
try {
|
|
return new URL(value).href;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// Keys a connected account by host and username so several accounts on the
|
|
// same CalDAV server can coexist.
|
|
export function caldavInstanceKey(url, username) {
|
|
const normalized = normalizeCaldavUrl(url);
|
|
if (!normalized) {
|
|
return null;
|
|
}
|
|
|
|
const host = new URL(normalized).host;
|
|
const user = (username ?? '').trim().toLowerCase().replace(/\s+/g, '-');
|
|
return user ? `${CALDAV_TYPE}-${host}-${user}` : `${CALDAV_TYPE}-${host}`;
|
|
}
|
|
|
|
export function credentialsMessage(context, { url, username, password }) {
|
|
return {
|
|
'@context': context,
|
|
type: 'credentials',
|
|
actor: CALENDAR_ACTOR,
|
|
object: { type: 'credentials', url, username, password },
|
|
};
|
|
}
|
|
|
|
export function fetchMessage(context) {
|
|
return { '@context': context, type: 'fetch', actor: CALENDAR_ACTOR };
|
|
}
|
|
|
|
export function queryMessage(context, calendarId, { startTime, endTime }) {
|
|
return {
|
|
'@context': context,
|
|
type: 'query',
|
|
actor: CALENDAR_ACTOR,
|
|
target: { id: calendarId, type: 'calendar' },
|
|
object: { type: 'event', startTime, endTime },
|
|
};
|
|
}
|
|
|
|
// Keeps only the fields the UI needs from a discovered calendar.
|
|
export function normalizeCalendar(item) {
|
|
if (!item || item.type !== 'calendar' || !item.id) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
id: item.id,
|
|
name: item.name ?? item.id,
|
|
components: Array.isArray(item.components) ? item.components : [],
|
|
};
|
|
}
|