diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 67b89e2627..9dba416d09 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -53,10 +53,7 @@ import {MessagesSettingsScreen} from './screens/Messages/Settings' import {useModalControls} from './state/modals' import {useUnreadNotifications} from './state/queries/notifications/unread' import {useSession} from './state/session' -import { - setEmailConfirmationRequested, - shouldRequestEmailConfirmation, -} from './state/shell/reminders' +import {shouldRequestEmailConfirmation} from './state/shell/reminders' import {AccessibilitySettingsScreen} from './view/screens/AccessibilitySettings' import {CommunityGuidelinesScreen} from './view/screens/CommunityGuidelines' import {CopyrightPolicyScreen} from './view/screens/CopyrightPolicy' @@ -585,7 +582,6 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { if (currentAccount && shouldRequestEmailConfirmation(currentAccount)) { openModal({name: 'verify-email', showReminder: true}) - setEmailConfirmationRequested() } } diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index 8de4b52aed..9176354a83 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -61,3 +61,10 @@ export function getAge(birthDate: Date): number { } return age } + +export function toSimpleDateString(date: Date) { + const mm = date.getMonth() + 1 // 0-indexed + const dd = date.getDate() + const yyyy = date.getFullYear() + return `${yyyy}-${mm}-${dd}` +} diff --git a/src/state/shell/reminders.ts b/src/state/shell/reminders.ts index c722bbf48e..f509d962e8 100644 --- a/src/state/shell/reminders.ts +++ b/src/state/shell/reminders.ts @@ -1,38 +1,53 @@ +import {toSimpleDateString} from '#/lib/strings/time' +import {logger} from '#/logger' import * as persisted from '#/state/persisted' -import {toHashCode} from 'lib/strings/helpers' import {SessionAccount} from '../session' import {isOnboardingActive} from './onboarding' export function shouldRequestEmailConfirmation(account: SessionAccount) { - if (!account) { + // 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 stored = persisted.get('reminders').lastEmailConfirm + const today = toSimpleDateString(new Date()) + const snoozedAt = stored ? toSimpleDateString(new Date(stored)) : undefined + + logger.debug('Checking email confirmation reminder', { + today, + snoozedAt, + }) + + // never been snoozed, new account + if (!snoozedAt) { + snooze() + return true + } + + // already snoozed today + if (snoozedAt === today) { return false } - if (account.emailConfirmed) { - return false - } - if (isOnboardingActive()) { - return false - } - // only prompt once - if (persisted.get('reminders').lastEmailConfirm) { - return false - } - const now = new Date() - const today = now.getDay() - const tomorrow = (today + 1) % 7 - // 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 day = toHashCode(account.did) % 7 - if (day !== today && day !== tomorrow) { - return false + + // snoozed recently + if (snoozedAt !== today) { + snooze() + return true } + return true } -export function setEmailConfirmationRequested() { +export function snooze() { + const lastEmailConfirm = new Date().toISOString() + logger.debug('Snoozing email confirmation reminder', { + snoozedAt: lastEmailConfirm, + }) persisted.write('reminders', { ...persisted.get('reminders'), - lastEmailConfirm: new Date().toISOString(), + lastEmailConfirm, }) }