1 import { canonicalizeEmailByGuess } from '@proton/shared/lib/helpers/email';
3 import type { EventReadResult } from '../../containers/calendar/eventStore/interface';
6 eventReadResult: EventReadResult | undefined;
10 [uniqueId: string]: Event;
13 export const getEventReadResult = (uniqueId?: string): EventReadResult | undefined => {
14 return uniqueId ? eventsCache[uniqueId]?.eventReadResult : undefined;
17 export const setEventReadResult = (uniqueId?: string, eventReadResult?: EventReadResult): void => {
22 eventsCache[uniqueId] = {
23 ...eventsCache[uniqueId], // Ensure existing data is not overwritten
28 export const getCurrentPartstat = (uniqueId: string, selfEmail: string) => {
29 const eventReadResult = getEventReadResult(uniqueId);
30 const [decryptedVeventResult] = eventReadResult?.result || [];
32 if (decryptedVeventResult) {
33 const attendee = decryptedVeventResult.veventComponent.attendee?.find((attendee) =>
34 attendee.value.includes(canonicalizeEmailByGuess(selfEmail))
37 if (attendee && attendee.parameters) {
38 return attendee.parameters.partstat;
43 export const setPartstat = (uniqueId: string, selfEmail: string, partstat: string): boolean => {
44 const eventReadResult = getEventReadResult(uniqueId);
45 const [decryptedVeventResult] = eventReadResult?.result || [];
47 if (decryptedVeventResult) {
48 const attendee = decryptedVeventResult.veventComponent.attendee?.find((attendee) =>
49 attendee.value.includes(canonicalizeEmailByGuess(selfEmail))
52 if (attendee && attendee.parameters) {
53 attendee.parameters.partstat = partstat;
54 setEventReadResult(uniqueId, eventReadResult);