Fix lint issues
And disable eslint when building in prod mode Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -27,9 +27,13 @@ function mapToJson(map: Map<any, any>): string {
|
||||
/**
|
||||
* Fetch existing anonymous participations saved inside this browser
|
||||
*/
|
||||
function getLocalAnonymousParticipations(): Map<string, IAnonymousParticipation> {
|
||||
function getLocalAnonymousParticipations(): Map<
|
||||
string,
|
||||
IAnonymousParticipation
|
||||
> {
|
||||
return jsonToMap(
|
||||
localStorage.getItem(ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY) || mapToJson(new Map())
|
||||
localStorage.getItem(ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY) ||
|
||||
mapToJson(new Map())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,9 +62,14 @@ function insertLocalAnonymousParticipation(
|
||||
hashedUUID: string,
|
||||
participation: IAnonymousParticipation
|
||||
) {
|
||||
const participations = purgeOldParticipations(getLocalAnonymousParticipations());
|
||||
const participations = purgeOldParticipations(
|
||||
getLocalAnonymousParticipations()
|
||||
);
|
||||
participations.set(hashedUUID, participation);
|
||||
localStorage.setItem(ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY, mapToJson(participations));
|
||||
localStorage.setItem(
|
||||
ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY,
|
||||
mapToJson(participations)
|
||||
);
|
||||
}
|
||||
|
||||
function buildExpiration(event: IEvent): Date {
|
||||
@@ -82,12 +91,14 @@ async function addLocalUnconfirmedAnonymousParticipation(
|
||||
cancellationToken: string
|
||||
): Promise<void> {
|
||||
/**
|
||||
* We hash the event UUID so that we can't know which events an anonymous user goes by looking up it's localstorage
|
||||
* We hash the event UUID so that we can't know which events
|
||||
* an anonymous user goes by looking up it's localstorage
|
||||
*/
|
||||
const hashedUUID = await digestMessage(event.uuid);
|
||||
|
||||
/**
|
||||
* We round expiration to first day of next 3 months so that it's difficult to find event from date
|
||||
* We round expiration to first day of next 3 months so that
|
||||
* it's difficult to find event from date
|
||||
*/
|
||||
const expiration = buildExpiration(event);
|
||||
insertLocalAnonymousParticipation(hashedUUID, {
|
||||
@@ -98,19 +109,28 @@ async function addLocalUnconfirmedAnonymousParticipation(
|
||||
}
|
||||
|
||||
async function confirmLocalAnonymousParticipation(uuid: string): Promise<void> {
|
||||
const participations = purgeOldParticipations(getLocalAnonymousParticipations());
|
||||
const participations = purgeOldParticipations(
|
||||
getLocalAnonymousParticipations()
|
||||
);
|
||||
const hashedUUID = await digestMessage(uuid);
|
||||
const participation = participations.get(hashedUUID);
|
||||
if (participation) {
|
||||
participation.confirmed = true;
|
||||
participations.set(hashedUUID, participation);
|
||||
localStorage.setItem(ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY, mapToJson(participations));
|
||||
localStorage.setItem(
|
||||
ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY,
|
||||
mapToJson(participations)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function getParticipation(eventUUID: string): Promise<IAnonymousParticipation> {
|
||||
async function getParticipation(
|
||||
eventUUID: string
|
||||
): Promise<IAnonymousParticipation> {
|
||||
const hashedUUID = await digestMessage(eventUUID);
|
||||
const participation = purgeOldParticipations(getLocalAnonymousParticipations()).get(hashedUUID);
|
||||
const participation = purgeOldParticipations(
|
||||
getLocalAnonymousParticipations()
|
||||
).get(hashedUUID);
|
||||
if (participation) {
|
||||
return participation;
|
||||
}
|
||||
@@ -122,15 +142,22 @@ async function isParticipatingInThisEvent(eventUUID: string): Promise<boolean> {
|
||||
return participation !== undefined && participation.confirmed;
|
||||
}
|
||||
|
||||
async function getLeaveTokenForParticipation(eventUUID: string): Promise<string> {
|
||||
async function getLeaveTokenForParticipation(
|
||||
eventUUID: string
|
||||
): Promise<string> {
|
||||
return (await getParticipation(eventUUID)).token;
|
||||
}
|
||||
|
||||
async function removeAnonymousParticipation(eventUUID: string): Promise<void> {
|
||||
const hashedUUID = await digestMessage(eventUUID);
|
||||
const participations = purgeOldParticipations(getLocalAnonymousParticipations());
|
||||
const participations = purgeOldParticipations(
|
||||
getLocalAnonymousParticipations()
|
||||
);
|
||||
participations.delete(hashedUUID);
|
||||
localStorage.setItem(ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY, mapToJson(participations));
|
||||
localStorage.setItem(
|
||||
ANONYMOUS_PARTICIPATIONS_LOCALSTORAGE_KEY,
|
||||
mapToJson(participations)
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user