Status media attachments refactor (#39601)

This commit is contained in:
Echo authored and GitHub committed 2026-06-25 16:34:11 +00:00
1 parent e4e19ba264
commit 3f98bee57f
11 files changed
+494 -88

No files matched your search

@@ -55,6 +55,14 @@ export interface AccountShape extends Required<
moved: string | null;
url: string;
}
export type AccountShapeFull = Omit<
AccountShape,
'emojis' | 'fields' | 'roles'
> & {
emojis: CustomEmoji[];
fields: AccountFieldShape[];
roles: AccountRoleShape[];
};
export type Account = RecordOf<AccountShape>;
+48 -6
View File
@@ -2,7 +2,15 @@ import type { RecordOf } from 'immutable';
import type { ApiCollectionJSON } from '@/mastodon/api_types/collections';
import type { ApiCustomEmojiJSON } from '@/mastodon/api_types/custom_emoji';
import type { ApiMediaAttachmentJSON } from '@/mastodon/api_types/media_attachments';
import type {
ApiAudioAttachmentJSON,
ApiGifvAttachmentJSON,
ApiImageAttachmentJSON,
ApiMediaAttachmentJSON,
ApiUnknownAttachmentJSON,
ApiVideoAttachmentJSON,
MediaAttachmentType,
} from '@/mastodon/api_types/media_attachments';
import type {
ApiQuoteJSON,
ApiQuotePolicyJSON,
@@ -17,6 +25,8 @@ import type {
StatusVisibility,
} from '@/mastodon/api_types/statuses';
import type { AccountShapeFull } from './account';
export type { StatusVisibility } from '@/mastodon/api_types/statuses';
// Temporary until we type it correctly
@@ -75,6 +85,10 @@ export interface StatusShape {
replies_count: number;
visibility: StatusVisibility;
}
export type ExpandedStatusShape = Omit<StatusShape, 'account' | 'reblog'> & {
account: AccountShapeFull;
reblog?: Omit<ExpandedStatusShape, 'reblog'>;
};
export type CardShape = Omit<ApiPreviewCardJSON, 'authors'> & {
authors: (Omit<ApiPreviewCardAuthorJSON, 'author'> & {
@@ -86,14 +100,42 @@ export type Card = RecordOf<CardShape>;
export type MediaAttachment = Immutable.Map<string, unknown>;
export type MediaAttachmentShape = Omit<
ApiMediaAttachmentJSON,
'remote_url'
> & {
export type MediaAttachmentShape<
TAttachmentJSON extends ApiMediaAttachmentJSON = ApiMediaAttachmentJSON,
> = Omit<TAttachmentJSON, 'remote_url'> & {
remote_url: string | null;
translation?: string;
translation?: {
description: string;
};
};
export function isMediaAttachmentOfType(
attachment: MediaAttachmentShape,
type: 'image',
): attachment is MediaAttachmentShape<ApiImageAttachmentJSON>;
export function isMediaAttachmentOfType(
attachment: MediaAttachmentShape,
type: 'video',
): attachment is MediaAttachmentShape<ApiVideoAttachmentJSON>;
export function isMediaAttachmentOfType(
attachment: MediaAttachmentShape,
type: 'gifv',
): attachment is MediaAttachmentShape<ApiGifvAttachmentJSON>;
export function isMediaAttachmentOfType(
attachment: MediaAttachmentShape,
type: 'audio',
): attachment is MediaAttachmentShape<ApiAudioAttachmentJSON>;
export function isMediaAttachmentOfType(
attachment: MediaAttachmentShape,
type: 'unknown',
): attachment is MediaAttachmentShape<ApiUnknownAttachmentJSON>;
export function isMediaAttachmentOfType(
attachment: MediaAttachmentShape,
type: MediaAttachmentType,
) {
return attachment.type === type;
}
export type CollectionAttachment = RecordOf<ApiCollectionJSON>;
export type FilterResult = Omit<ApiFilterResultJSON, 'filter'> & {