[#90] added freebusy (#618)

This commit is contained in:
Camille Moussu
2026-03-12 18:07:25 +01:00
committed by GitHub
parent 047cbeef62
commit fd7581a8db
18 changed files with 917 additions and 29 deletions
+1
View File
@@ -1092,6 +1092,7 @@ function EventUpdateModal({
setEventClass={setEventClass}
timezone={timezone}
setTimezone={setTimezone}
eventId={event.uid}
calendarid={calendarid}
setCalendarid={setCalendarid}
hasVideoConference={hasVideoConference}
@@ -0,0 +1,37 @@
import { getCalendars } from "@/features/Calendars/CalendarApi";
import { api } from "@/utils/apiUtils";
import { extractCalendarHrefs } from "@/utils/extractCalendarHrefs";
import { hasFreeBusyConflict } from "../../../components/Attendees/useFreeBusy";
export async function getFreeBusyForAddedAttendeesREPORT(
userId: string,
start: string,
end: string
): Promise<boolean> {
const calendars = await getCalendars(
userId,
"withFreeBusy=true&withRights=true"
);
const hrefs = extractCalendarHrefs(calendars);
if (hrefs.length === 0) return false;
const freeBusyBody = JSON.stringify({
type: "free-busy-query",
match: { start, end },
});
const results = await Promise.all(
hrefs.map((href) =>
api(`dav${href}`, {
method: "REPORT",
headers: { Accept: "application/json, text/plain, */*" },
body: freeBusyBody,
})
.then((r) => (r.ok ? r.json() : null))
.then((data) => (data ? hasFreeBusyConflict(data) : false))
.catch(() => false)
)
);
return results.some(Boolean);
}
@@ -0,0 +1,22 @@
import { api } from "@/utils/apiUtils";
export async function getFreeBusyForEventAttendeesPOST(
userIds: string[],
start: string,
end: string,
eventUid: string
): Promise<Record<string, boolean>> {
const r = await api("dav/calendars/freebusy", {
method: "POST",
headers: { Accept: "application/json, text/plain, */*" },
body: JSON.stringify({ start, end, users: userIds, uids: [eventUid] }),
});
if (!r.ok) throw new Error(`HTTP ${r.status}`);
const { users } = (await r.json()) as {
users: { id: string; calendars: { busy: unknown[] }[] }[];
};
return Object.fromEntries(
users.map((u) => [u.id, u.calendars.some((cal) => cal.busy.length > 0)])
);
}
@@ -0,0 +1,7 @@
import { api } from "@/utils/apiUtils";
export async function getUserDataFromEmail(email: string) {
const r = await api(`api/users?email=${encodeURIComponent(email)}`);
const result: Array<Record<string, string>> = await r.json();
return result;
}