1 import { useCallback } from 'react';
3 import { useGetAddressKeys } from '@proton/account/addressKeys/hooks';
4 import { useGetAddresses } from '@proton/account/addresses/hooks';
5 import { useGetCalendarBootstrap } from '@proton/calendar/calendarBootstrap/hooks';
6 import { useGetCalendarKeys } from '@proton/calendar/calendarBootstrap/keys';
7 import { getIsAutoAddedInvite } from '@proton/shared/lib/calendar/apiModels';
8 import { getAuthorPublicKeysMap, withNormalizedAuthors } from '@proton/shared/lib/calendar/author';
9 import { getCalendarEventDecryptionKeys } from '@proton/shared/lib/calendar/crypto/keys/helpers';
10 import { readCalendarEvent, readSessionKeys } from '@proton/shared/lib/calendar/deserialize';
11 import type { SimpleMap } from '@proton/shared/lib/interfaces';
12 import type { CalendarEvent } from '@proton/shared/lib/interfaces/calendar';
13 import type { ContactEmail } from '@proton/shared/lib/interfaces/contacts';
14 import type { GetCalendarEventRaw } from '@proton/shared/lib/interfaces/hooks/GetCalendarEventRaw';
16 import useGetVerificationPreferences from './useGetVerificationPreferences';
18 const useGetCalendarEventRaw = (contactEmailsMap: SimpleMap<ContactEmail>): GetCalendarEventRaw => {
19 const getCalendarKeys = useGetCalendarKeys();
20 const getCalendarBootstrap = useGetCalendarBootstrap();
21 const getAddresses = useGetAddresses();
22 const getAddressKeys = useGetAddressKeys();
23 const getVerificationPreferences = useGetVerificationPreferences();
26 async (Event: CalendarEvent) => {
38 const encryptingAddressID = getIsAutoAddedInvite(Event) ? Event.AddressID : undefined;
39 const addresses = await getAddresses();
41 const [privateKeys, publicKeysMap, { CalendarSettings: calendarSettings }] = await Promise.all([
42 getCalendarEventDecryptionKeys({ calendarEvent: Event, getAddressKeys, getCalendarKeys }),
43 getAuthorPublicKeysMap({
45 getVerificationPreferences,
48 getCalendarBootstrap(CalendarID),
50 const [sharedSessionKey, calendarSessionKey] = await readSessionKeys({
54 return readCalendarEvent({
56 SharedEvents: withNormalizedAuthors(SharedEvents),
57 CalendarEvents: withNormalizedAuthors(CalendarEvents),
58 AttendeesEvents: withNormalizedAuthors(AttendeesEvents),
74 [getAddresses, getAddressKeys, getCalendarKeys, contactEmailsMap]
78 export default useGetCalendarEventRaw;