import {useState} from 'react' import {Image, View} from 'react-native' import { FontAwesomeIcon, type FontAwesomeIconStyle, } from '@fortawesome/react-native-fontawesome' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {isBridgedPdsUrl, isBskyPdsUrl} from '#/state/queries/pds-label' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {Fediverse as FediverseIcon} from '#/components/icons/Fediverse' import {Mark as BskyMark} from '#/components/icons/Logo' import {InlineLinkText} from '#/components/Link' import {Text} from '#/components/Typography' function formatBskyPdsDisplayName(hostname: string): string { const match = hostname.match(/^([^.]+)\.([^.]+)\.host\.bsky\.network$/) if (match) { const name = match[1].charAt(0).toUpperCase() + match[1].slice(1) const rawRegion = match[2] const region = rawRegion .replace(/^us-east$/, 'US East') .replace(/^us-west$/, 'US West') .replace(/^eu-west$/, 'EU West') .replace( /^ap-(.+)$/, (_match: string, r: string) => `AP ${r.charAt(0).toUpperCase()}${r.slice(1)}`, ) return `${name} (${region})` } if (hostname === 'bsky.social') return 'Bluesky Social' return hostname } export function PdsDialog({ control, pdsUrl, faviconUrl, }: { control: Dialog.DialogControlProps pdsUrl: string faviconUrl: string }) { const {_} = useLingui() const {gtMobile} = useBreakpoints() let hostname = pdsUrl try { hostname = new URL(pdsUrl).hostname } catch {} const isBsky = isBskyPdsUrl(pdsUrl) const isBridged = isBridgedPdsUrl(pdsUrl) const displayName = isBsky ? formatBskyPdsDisplayName(hostname) : hostname return ( {displayName} {isBsky && ( Bluesky-hosted PDS )} {isBridged && ( Fediverse bridge )} This account's data is stored on a Personal Data Server (PDS):{' '} {displayName} {'. '}A PDS is where your posts, follows, and other data live on the AT Protocol network. {isBridged && ( This account is bridged from the Fediverse via{' '} Bridgy Fed . Their original account lives on a Fediverse platform such as Mastodon. )} {!isBsky && !isBridged && ( This account is self-hosted or uses a third-party PDS provider. )} ) } export function FaviconOrGlobe({ faviconUrl, isBsky, isBridged, size, borderRadius, }: { faviconUrl: string isBsky: boolean isBridged: boolean size: number borderRadius?: number }) { const t = useTheme() const [imgError, setImgError] = useState(false) const resolvedBorderRadius = borderRadius ?? size / 5 if (isBsky) { return ( ) } if (isBridged) { return ( ) } if (!imgError && faviconUrl) { return ( setImgError(true)} accessibilityIgnoresInvertColors /> ) } return ( ) }