diff --git a/app/soapbox/utils/accounts.ts b/app/soapbox/utils/accounts.ts index ef7c446a5..d8d946f9d 100644 --- a/app/soapbox/utils/accounts.ts +++ b/app/soapbox/utils/accounts.ts @@ -1,7 +1,6 @@ import type { Account } from 'soapbox/schemas'; -import type { Account as AccountEntity } from 'soapbox/types/entities'; -const getDomainFromURL = (account: AccountEntity): string => { +const getDomainFromURL = (account: Pick): string => { try { const url = account.url; return new URL(url).host; @@ -10,12 +9,12 @@ const getDomainFromURL = (account: AccountEntity): string => { } }; -export const getDomain = (account: AccountEntity): string => { +export const getDomain = (account: Pick): string => { const domain = account.acct.split('@')[1]; return domain ? domain : getDomainFromURL(account); }; -export const getBaseURL = (account: AccountEntity): string => { +export const getBaseURL = (account: Pick): string => { try { return new URL(account.url).origin; } catch { @@ -27,12 +26,12 @@ export const getAcct = (account: Pick, displayFqn: bool displayFqn === true ? account.fqn : account.acct ); -export const isLocal = (account: AccountEntity | Account): boolean => { +export const isLocal = (account: Pick): boolean => { const domain: string = account.acct.split('@')[1]; return domain === undefined ? true : false; }; -export const isRemote = (account: AccountEntity): boolean => !isLocal(account); +export const isRemote = (account: Pick): boolean => !isLocal(account); /** Default header filenames from various backends */ const DEFAULT_HEADERS = [ diff --git a/app/soapbox/utils/ads.ts b/app/soapbox/utils/ads.ts index b59cf430b..ed2bf0cad 100644 --- a/app/soapbox/utils/ads.ts +++ b/app/soapbox/utils/ads.ts @@ -4,7 +4,7 @@ import type { Ad } from 'soapbox/schemas'; const AD_EXPIRY_THRESHOLD = 5 * 60 * 1000; /** Whether the ad is expired or about to expire. */ -const isExpired = (ad: Ad, threshold = AD_EXPIRY_THRESHOLD): boolean => { +const isExpired = (ad: Pick, threshold = AD_EXPIRY_THRESHOLD): boolean => { if (ad.expires_at) { const now = new Date(); return now.getTime() > (new Date(ad.expires_at).getTime() - threshold); diff --git a/app/soapbox/utils/status.ts b/app/soapbox/utils/status.ts index 74c43e071..09593facc 100644 --- a/app/soapbox/utils/status.ts +++ b/app/soapbox/utils/status.ts @@ -1,10 +1,13 @@ import { isIntegerId } from 'soapbox/utils/numbers'; import type { IntlShape } from 'react-intl'; -import type { Status as StatusEntity } from 'soapbox/types/entities'; +import type { Status } from 'soapbox/types/entities'; /** Get the initial visibility of media attachments from user settings. */ -export const defaultMediaVisibility = (status: StatusEntity | undefined | null, displayMedia: string): boolean => { +export const defaultMediaVisibility = ( + status: Pick | undefined | null, + displayMedia: string, +): boolean => { if (!status) return false; if (status.reblog && typeof status.reblog === 'object') { @@ -21,7 +24,7 @@ export const defaultMediaVisibility = (status: StatusEntity | undefined | null, }; /** Grab the first external link from a status. */ -export const getFirstExternalLink = (status: StatusEntity): HTMLAnchorElement | null => { +export const getFirstExternalLink = (status: Pick): HTMLAnchorElement | null => { try { // Pulled from Pleroma's media parser const selector = 'a:not(.mention,.hashtag,.attachment,[rel~="tag"])'; @@ -34,18 +37,22 @@ export const getFirstExternalLink = (status: StatusEntity): HTMLAnchorElement | }; /** Whether the status is expected to have a Card after it loads. */ -export const shouldHaveCard = (status: StatusEntity): boolean => { +export const shouldHaveCard = (status: Pick): boolean => { return Boolean(getFirstExternalLink(status)); }; /** Whether the media IDs on this status have integer IDs (opposed to FlakeIds). */ // https://gitlab.com/soapbox-pub/soapbox/-/merge_requests/1087 -export const hasIntegerMediaIds = (status: StatusEntity): boolean => { +export const hasIntegerMediaIds = (status: Pick): boolean => { return status.media_attachments.some(({ id }) => isIntegerId(id)); }; /** Sanitize status text for use with screen readers. */ -export const textForScreenReader = (intl: IntlShape, status: StatusEntity, rebloggedByText?: string): string => { +export const textForScreenReader = ( + intl: IntlShape, + status: Pick, + rebloggedByText?: string, +): string => { const { account } = status; if (!account || typeof account !== 'object') return ''; @@ -55,7 +62,7 @@ export const textForScreenReader = (intl: IntlShape, status: StatusEntity, reblo displayName.length === 0 ? account.acct.split('@')[0] : displayName, status.spoiler_text && status.hidden ? status.spoiler_text : status.search_index.slice(status.spoiler_text.length), intl.formatDate(status.created_at, { hour: '2-digit', minute: '2-digit', month: 'short', day: 'numeric' }), - status.getIn(['account', 'acct']), + account.acct, ]; if (rebloggedByText) { @@ -68,12 +75,12 @@ export const textForScreenReader = (intl: IntlShape, status: StatusEntity, reblo /** Get reblogged status if any, otherwise return the original status. */ // @ts-ignore The type seems right, but TS doesn't like it. export const getActualStatus: { - (status: StatusEntity): StatusEntity + >(status: T): T (status: undefined): undefined (status: null): null -} = (status) => { +} = >(status: T | null | undefined) => { if (status?.reblog && typeof status?.reblog === 'object') { - return status.reblog as StatusEntity; + return status.reblog as Status; } else { return status; }