diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-07 16:39:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 16:39:13 -0800 |
commit | 2acc88e78df1c1f4c21bf9a333f3432781a64135 (patch) | |
tree | e331e9c7f79441f2643f1b7f13b00563baea2899 /src/state/shell/reminders.ts | |
parent | 96d8faf4b052060b8774ac38c3400ab7d75451ad (diff) | |
download | voidsky-2acc88e78df1c1f4c21bf9a333f3432781a64135.tar.zst |
Move reminders to new persisted state layer (#1834)
Diffstat (limited to 'src/state/shell/reminders.ts')
-rw-r--r-- | src/state/shell/reminders.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/state/shell/reminders.ts b/src/state/shell/reminders.ts new file mode 100644 index 000000000..d68a272ac --- /dev/null +++ b/src/state/shell/reminders.ts @@ -0,0 +1,40 @@ +import * as persisted from '#/state/persisted' +import {OnboardingModel} from '../models/discovery/onboarding' +import {SessionModel} from '../models/session' +import {toHashCode} from 'lib/strings/helpers' + +export function shouldRequestEmailConfirmation( + session: SessionModel, + onboarding: OnboardingModel, +) { + const sess = session.currentSession + if (!sess) { + return false + } + if (sess.emailConfirmed) { + return false + } + if (onboarding.isActive) { + 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(sess.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(), + }) +} |