diff options
Diffstat (limited to 'src/state/models/ui')
-rw-r--r-- | src/state/models/ui/reminders.e2e.ts | 24 | ||||
-rw-r--r-- | src/state/models/ui/reminders.ts | 64 | ||||
-rw-r--r-- | src/state/models/ui/shell.ts | 13 |
3 files changed, 11 insertions, 90 deletions
diff --git a/src/state/models/ui/reminders.e2e.ts b/src/state/models/ui/reminders.e2e.ts deleted file mode 100644 index ec0eca40d..000000000 --- a/src/state/models/ui/reminders.e2e.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {makeAutoObservable} from 'mobx' -import {RootStoreModel} from '../root-store' - -export class Reminders { - constructor(public rootStore: RootStoreModel) { - makeAutoObservable( - this, - {serialize: false, hydrate: false}, - {autoBind: true}, - ) - } - - serialize() { - return {} - } - - hydrate(_v: unknown) {} - - get shouldRequestEmailConfirmation() { - return false - } - - setEmailConfirmationRequested() {} -} diff --git a/src/state/models/ui/reminders.ts b/src/state/models/ui/reminders.ts deleted file mode 100644 index c650de004..000000000 --- a/src/state/models/ui/reminders.ts +++ /dev/null @@ -1,64 +0,0 @@ -import {makeAutoObservable} from 'mobx' -import {isObj, hasProp} from 'lib/type-guards' -import {RootStoreModel} from '../root-store' -import {toHashCode} from 'lib/strings/helpers' - -export class Reminders { - lastEmailConfirm: Date | null = null - - constructor(public rootStore: RootStoreModel) { - makeAutoObservable( - this, - {serialize: false, hydrate: false}, - {autoBind: true}, - ) - } - - serialize() { - return { - lastEmailConfirm: this.lastEmailConfirm - ? this.lastEmailConfirm.toISOString() - : undefined, - } - } - - hydrate(v: unknown) { - if ( - isObj(v) && - hasProp(v, 'lastEmailConfirm') && - typeof v.lastEmailConfirm === 'string' - ) { - this.lastEmailConfirm = new Date(v.lastEmailConfirm) - } - } - - get shouldRequestEmailConfirmation() { - const sess = this.rootStore.session.currentSession - if (!sess) { - return false - } - if (sess.emailConfirmed) { - return false - } - if (this.rootStore.onboarding.isActive) { - return false - } - // only prompt once - if (this.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 - } - - setEmailConfirmationRequested() { - this.lastEmailConfirm = new Date() - } -} diff --git a/src/state/models/ui/shell.ts b/src/state/models/ui/shell.ts index d39131629..343fff86d 100644 --- a/src/state/models/ui/shell.ts +++ b/src/state/models/ui/shell.ts @@ -7,6 +7,10 @@ import {ImageModel} from '../media/image' import {ListModel} from '../content/list' import {GalleryModel} from '../media/gallery' import {StyleProp, ViewStyle} from 'react-native' +import { + shouldRequestEmailConfirmation, + setEmailConfirmationRequested, +} from '#/state/shell/reminders' export type ColorMode = 'system' | 'light' | 'dark' @@ -358,9 +362,14 @@ export class ShellUiModel { setupLoginModals() { this.rootStore.onSessionReady(() => { - if (this.rootStore.reminders.shouldRequestEmailConfirmation) { + if ( + shouldRequestEmailConfirmation( + this.rootStore.session, + this.rootStore.onboarding, + ) + ) { this.openModal({name: 'verify-email', showReminder: true}) - this.rootStore.reminders.setEmailConfirmationRequested() + setEmailConfirmationRequested() } }) } |