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