blob: 88d0a5d85fc1fff76761a17feea1e9fc5cac9cf8 (
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
46
47
|
import * as persisted from '#/state/persisted'
import {toHashCode} from 'lib/strings/helpers'
import {isOnboardingActive} from './onboarding'
import {SessionAccount} from '../session'
import {listenSessionLoaded} from '../events'
import {unstable__openModal} from '../modals'
export function init() {
listenSessionLoaded(account => {
if (shouldRequestEmailConfirmation(account)) {
unstable__openModal({name: 'verify-email', showReminder: true})
setEmailConfirmationRequested()
}
})
}
export function shouldRequestEmailConfirmation(account: SessionAccount) {
if (!account) {
return false
}
if (account.emailConfirmed) {
return false
}
if (isOnboardingActive()) {
return false
}
// only prompt once
if (persisted.get('reminders').lastEmailConfirm) {
return false
}
const today = new Date()
// shard the users into 2 day of the week buckets
// (this is to avoid a sudden influx of email updates when
// this feature rolls out)
const code = toHashCode(account.did) % 7
if (code !== today.getDay() && code !== (today.getDay() + 1) % 7) {
return false
}
return true
}
export function setEmailConfirmationRequested() {
persisted.write('reminders', {
...persisted.get('reminders'),
lastEmailConfirm: new Date().toISOString(),
})
}
|