Increase email reminder period to once per day
This commit is contained in:
+1
-5
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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}`
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user