fix newskie joined time copy
This commit is contained in:
@@ -7,7 +7,6 @@ import {Trans} from '@lingui/react/macro'
|
|||||||
import {differenceInSeconds} from 'date-fns'
|
import {differenceInSeconds} from 'date-fns'
|
||||||
|
|
||||||
import {HITSLOP_10} from '#/lib/constants'
|
import {HITSLOP_10} from '#/lib/constants'
|
||||||
import {useGetTimeAgo} from '#/lib/hooks/useTimeAgo'
|
|
||||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
@@ -20,6 +19,7 @@ import * as StarterPackCard from '#/components/StarterPack/StarterPackCard'
|
|||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {IS_NATIVE} from '#/env'
|
import {IS_NATIVE} from '#/env'
|
||||||
import {type app} from '#/lexicons'
|
import {type app} from '#/lexicons'
|
||||||
|
import {getJoinMessage} from './utils'
|
||||||
|
|
||||||
export function NewskieDialog({
|
export function NewskieDialog({
|
||||||
profile,
|
profile,
|
||||||
@@ -80,11 +80,10 @@ function DialogInner({
|
|||||||
now: number
|
now: number
|
||||||
}) {
|
}) {
|
||||||
const control = Dialog.useDialogContext()
|
const control = Dialog.useDialogContext()
|
||||||
const {_} = useLingui()
|
const {_, i18n} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const timeAgo = useGetTimeAgo()
|
|
||||||
const isMe = profile.did === currentAccount?.did
|
const isMe = profile.did === currentAccount?.did
|
||||||
|
|
||||||
const profileName = useMemo(() => {
|
const profileName = useMemo(() => {
|
||||||
@@ -96,28 +95,6 @@ function DialogInner({
|
|||||||
)
|
)
|
||||||
}, [moderationOpts, profile])
|
}, [moderationOpts, profile])
|
||||||
|
|
||||||
const getJoinMessage = () => {
|
|
||||||
const timeAgoString = timeAgo(createdAt, now, {format: 'long'})
|
|
||||||
|
|
||||||
if (isMe) {
|
|
||||||
if (profile.joinedViaStarterPack) {
|
|
||||||
return _(
|
|
||||||
msg`You joined Bluesky using a starter pack ${timeAgoString} ago`,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return _(msg`You joined Bluesky ${timeAgoString} ago`)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (profile.joinedViaStarterPack) {
|
|
||||||
return _(
|
|
||||||
msg`${profileName} joined Bluesky using a starter pack ${timeAgoString} ago`,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return _(msg`${profileName} joined Bluesky ${timeAgoString} ago`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.ScrollableInner
|
<Dialog.ScrollableInner
|
||||||
label={_(msg`New user info dialog`)}
|
label={_(msg`New user info dialog`)}
|
||||||
@@ -143,7 +120,14 @@ function DialogInner({
|
|||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text style={[a.text_md, a.text_center, a.leading_snug]}>
|
<Text style={[a.text_md, a.text_center, a.leading_snug]}>
|
||||||
{getJoinMessage()}
|
{getJoinMessage({
|
||||||
|
i18n,
|
||||||
|
profileName,
|
||||||
|
isMe,
|
||||||
|
joinedViaStarterPack: Boolean(profile.joinedViaStarterPack),
|
||||||
|
createdAt,
|
||||||
|
now,
|
||||||
|
})}
|
||||||
</Text>
|
</Text>
|
||||||
{profile.joinedViaStarterPack ? (
|
{profile.joinedViaStarterPack ? (
|
||||||
<StarterPackCard.Link
|
<StarterPackCard.Link
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import {beforeAll, describe, expect, it} from '@jest/globals'
|
||||||
|
import {i18n} from '@lingui/core'
|
||||||
|
|
||||||
|
import {getJoinMessage} from './utils'
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
i18n.loadAndActivate({locale: 'en', messages: {}})
|
||||||
|
})
|
||||||
|
|
||||||
|
const now = Date.parse('2026-09-01T12:00:00.000Z')
|
||||||
|
|
||||||
|
describe('NewskieDialog getJoinMessage', () => {
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
isMe: true,
|
||||||
|
joinedViaStarterPack: false,
|
||||||
|
expected: 'You joined Bluesky just now',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isMe: true,
|
||||||
|
joinedViaStarterPack: true,
|
||||||
|
expected: 'You joined Bluesky using a starter pack just now',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isMe: false,
|
||||||
|
joinedViaStarterPack: false,
|
||||||
|
expected: 'Alice joined Bluesky just now',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isMe: false,
|
||||||
|
joinedViaStarterPack: true,
|
||||||
|
expected: 'Alice joined Bluesky using a starter pack just now',
|
||||||
|
},
|
||||||
|
])('$expected', ({isMe, joinedViaStarterPack, expected}) => {
|
||||||
|
expect(
|
||||||
|
getJoinMessage({
|
||||||
|
i18n,
|
||||||
|
profileName: 'Alice',
|
||||||
|
isMe,
|
||||||
|
joinedViaStarterPack,
|
||||||
|
createdAt: new Date(now - 4_000).toISOString(),
|
||||||
|
now,
|
||||||
|
}),
|
||||||
|
).toBe(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('keeps the ago suffix for elapsed time', () => {
|
||||||
|
expect(
|
||||||
|
getJoinMessage({
|
||||||
|
i18n,
|
||||||
|
profileName: 'Alice',
|
||||||
|
isMe: true,
|
||||||
|
joinedViaStarterPack: false,
|
||||||
|
createdAt: new Date(now - 5_000).toISOString(),
|
||||||
|
now,
|
||||||
|
}),
|
||||||
|
).toBe('You joined Bluesky 5 seconds ago')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('treats a future timestamp as just now', () => {
|
||||||
|
expect(
|
||||||
|
getJoinMessage({
|
||||||
|
i18n,
|
||||||
|
profileName: 'Alice',
|
||||||
|
isMe: true,
|
||||||
|
joinedViaStarterPack: false,
|
||||||
|
createdAt: new Date(now + 60_000).toISOString(),
|
||||||
|
now,
|
||||||
|
}),
|
||||||
|
).toBe('You joined Bluesky just now')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import {type I18n} from '@lingui/core'
|
||||||
|
import {msg} from '@lingui/core/macro'
|
||||||
|
|
||||||
|
import {dateDiff, formatDateDiff} from '#/lib/hooks/useTimeAgo'
|
||||||
|
|
||||||
|
export function getJoinMessage({
|
||||||
|
i18n,
|
||||||
|
profileName,
|
||||||
|
isMe,
|
||||||
|
joinedViaStarterPack,
|
||||||
|
createdAt,
|
||||||
|
now,
|
||||||
|
}: {
|
||||||
|
i18n: I18n
|
||||||
|
profileName: string
|
||||||
|
isMe: boolean
|
||||||
|
joinedViaStarterPack: boolean
|
||||||
|
createdAt: string
|
||||||
|
now: number
|
||||||
|
}): string {
|
||||||
|
const diff = dateDiff(createdAt, now)
|
||||||
|
|
||||||
|
if (diff.unit === 'now') {
|
||||||
|
if (isMe) {
|
||||||
|
return joinedViaStarterPack
|
||||||
|
? i18n._(msg`You joined Bluesky using a starter pack just now`)
|
||||||
|
: i18n._(msg`You joined Bluesky just now`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return joinedViaStarterPack
|
||||||
|
? i18n._(msg`${profileName} joined Bluesky using a starter pack just now`)
|
||||||
|
: i18n._(msg`${profileName} joined Bluesky just now`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeAgoString = formatDateDiff({diff, i18n, format: 'long'})
|
||||||
|
|
||||||
|
if (isMe) {
|
||||||
|
return joinedViaStarterPack
|
||||||
|
? i18n._(
|
||||||
|
msg`You joined Bluesky using a starter pack ${timeAgoString} ago`,
|
||||||
|
)
|
||||||
|
: i18n._(msg`You joined Bluesky ${timeAgoString} ago`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return joinedViaStarterPack
|
||||||
|
? i18n._(
|
||||||
|
msg`${profileName} joined Bluesky using a starter pack ${timeAgoString} ago`,
|
||||||
|
)
|
||||||
|
: i18n._(msg`${profileName} joined Bluesky ${timeAgoString} ago`)
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import {Trans} from '@lingui/react/macro'
|
|||||||
import {isInvalidHandle, sanitizeHandle} from '#/lib/strings/handles'
|
import {isInvalidHandle, sanitizeHandle} from '#/lib/strings/handles'
|
||||||
import {type Shadow} from '#/state/cache/types'
|
import {type Shadow} from '#/state/cache/types'
|
||||||
import {atoms as a, useTheme, web} from '#/alf'
|
import {atoms as a, useTheme, web} from '#/alf'
|
||||||
import {NewskieDialog} from '#/components/NewskieDialog'
|
import {NewskieDialog} from '#/components/dialogs/NewskieDialog'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {IS_IOS, IS_NATIVE} from '#/env'
|
import {IS_IOS, IS_NATIVE} from '#/env'
|
||||||
import {type app} from '#/lexicons'
|
import {type app} from '#/lexicons'
|
||||||
|
|||||||
Reference in New Issue
Block a user