Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move reminders to new persisted state layer #1834

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/state/models/root-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {PreferencesModel} from './ui/preferences'
import {resetToTab} from '../../Navigation'
import {ImageSizesCache} from './cache/image-sizes'
import {MutedThreads} from './muted-threads'
import {Reminders} from './ui/reminders'
import {reset as resetNavigation} from '../../Navigation'
import {logger} from '#/logger'

Expand Down Expand Up @@ -53,7 +52,6 @@ export class RootStoreModel {
linkMetas = new LinkMetasCache(this)
imageSizes = new ImageSizesCache()
mutedThreads = new MutedThreads()
reminders = new Reminders(this)

constructor(agent: BskyAgent) {
this.agent = agent
Expand All @@ -77,7 +75,6 @@ export class RootStoreModel {
preferences: this.preferences.serialize(),
invitedUsers: this.invitedUsers.serialize(),
mutedThreads: this.mutedThreads.serialize(),
reminders: this.reminders.serialize(),
}
}

Expand Down Expand Up @@ -107,9 +104,6 @@ export class RootStoreModel {
if (hasProp(v, 'mutedThreads')) {
this.mutedThreads.hydrate(v.mutedThreads)
}
if (hasProp(v, 'reminders')) {
this.reminders.hydrate(v.reminders)
}
}
}

Expand Down
24 changes: 0 additions & 24 deletions src/state/models/ui/reminders.e2e.ts

This file was deleted.

64 changes: 0 additions & 64 deletions src/state/models/ui/reminders.ts

This file was deleted.

13 changes: 11 additions & 2 deletions src/state/models/ui/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/state/persisted/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export function transform(legacy: LegacySchema): Schema {
defaults.session.currentAccount,
},
reminders: {
lastEmailConfirmReminder:
lastEmailConfirm:
legacy.reminders.lastEmailConfirm ||
defaults.reminders.lastEmailConfirmReminder,
defaults.reminders.lastEmailConfirm,
},
languagePrefs: {
primaryLanguage:
Expand Down
4 changes: 2 additions & 2 deletions src/state/persisted/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const schema = z.object({
currentAccount: accountSchema.optional(),
}),
reminders: z.object({
lastEmailConfirmReminder: z.string().optional(),
lastEmailConfirm: z.string().optional(),
}),
languagePrefs: z.object({
primaryLanguage: z.string(), // should move to server
Expand All @@ -46,7 +46,7 @@ export const defaults: Schema = {
currentAccount: undefined,
},
reminders: {
lastEmailConfirmReminder: undefined,
lastEmailConfirm: undefined,
},
languagePrefs: {
primaryLanguage: deviceLocales[0] || 'en',
Expand Down
11 changes: 11 additions & 0 deletions src/state/shell/reminders.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {OnboardingModel} from '../models/discovery/onboarding'
import {SessionModel} from '../models/session'

export function shouldRequestEmailConfirmation(
_session: SessionModel,
_onboarding: OnboardingModel,
) {
return false
}

export function setEmailConfirmationRequested() {}
40 changes: 40 additions & 0 deletions src/state/shell/reminders.ts
Original file line number Diff line number Diff line change
@@ -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(),
})
}