mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {simpleAreDatesEqual} from '#/lib/strings/time'
2import {logger} from '#/logger'
3import * as persisted from '#/state/persisted'
4import {SessionAccount} from '../session'
5import {isOnboardingActive} from './onboarding'
6
7export function shouldRequestEmailConfirmation(account: SessionAccount) {
8 // ignore logged out
9 if (!account) return false
10 // ignore confirmed accounts, this is the success state of this reminder
11 if (account.emailConfirmed) return false
12 // wait for onboarding to complete
13 if (isOnboardingActive()) return false
14
15 const snoozedAt = persisted.get('reminders').lastEmailConfirm
16 const today = new Date()
17
18 logger.debug('Checking email confirmation reminder', {
19 today,
20 snoozedAt,
21 })
22
23 // never been snoozed, new account
24 if (!snoozedAt) {
25 return true
26 }
27
28 // already snoozed today
29 if (simpleAreDatesEqual(new Date(Date.parse(snoozedAt)), new Date())) {
30 return false
31 }
32
33 return true
34}
35
36export function snoozeEmailConfirmationPrompt() {
37 const lastEmailConfirm = new Date().toISOString()
38 logger.debug('Snoozing email confirmation reminder', {
39 snoozedAt: lastEmailConfirm,
40 })
41 persisted.write('reminders', {
42 ...persisted.get('reminders'),
43 lastEmailConfirm,
44 })
45}