forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useMemo} from 'react'
2
3import {BSKY_SERVICE} from '#/lib/constants'
4import {type SessionAccount} from '#/state/session'
5import {
6 type MergeableMetadata,
7 type SessionMetadata,
8} from '#/analytics/metadata'
9
10/**
11 * Thin `useMemo` wrapper that marks the metadata as memoized and provides a
12 * type guard.
13 */
14export function useMeta(metadata?: MergeableMetadata) {
15 const m = useMemo(() => metadata, [metadata])
16 if (!m) return
17 // @ts-ignore
18 m.__meta = true
19 return m
20}
21
22export function accountToSessionMetadata(
23 account: SessionAccount | undefined,
24): SessionMetadata | undefined {
25 if (!account) {
26 return
27 } else {
28 return {
29 did: account.did,
30 isBskyPds: account.service.startsWith(BSKY_SERVICE),
31 }
32 }
33}