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

+10 -1
View File
@@ -3,7 +3,11 @@ import { Record as ImmutableRecord, List as ImmutableList } from 'immutable';
import { me } from 'mastodon/initial_state';
import { accountDefaultValues } from 'mastodon/models/account';
import type { Account, AccountShape } from 'mastodon/models/account';
import type {
Account,
AccountShape,
AccountShapeFull,
} from 'mastodon/models/account';
import type { Relationship } from 'mastodon/models/relationship';
import { createAppSelector } from 'mastodon/store';
import type { RootState } from 'mastodon/store';
@@ -50,6 +54,11 @@ export function makeGetAccount() {
);
}
export const selectPlainAccount = createAppSelector(
[(state, accountId: string) => state.accounts.get(accountId)],
(account) => (account ? (account.toJS() as AccountShapeFull) : null),
);
export const getAccountHidden = createAppSelector(
[
(state, id: string) => state.accounts.get(id)?.hidden,
+9 -1
View File
@@ -3,6 +3,14 @@ import { createSelector } from '@reduxjs/toolkit';
import type { RootState } from 'mastodon/store';
import { toServerSideType } from 'mastodon/utils/filters';
export interface FilterShape {
id: string;
title: string;
context: string[];
expires_at: string | null;
filter_action: 'hide' | 'blur' | 'warn';
}
// TODO: move to `app/javascript/mastodon/models` and use more globally
type Filter = Immutable.Map<string, unknown>;
@@ -12,7 +20,7 @@ type FilterResult = Immutable.Map<string, unknown>;
export const getFilters = createSelector(
[
(state: RootState) => state.filters as Immutable.Map<string, Filter>,
(_, { contextType }: { contextType: string }) => contextType,
(_, { contextType }: { contextType?: string }) => contextType,
],
(filters, contextType) => {
if (!contextType) {
+86 -1
View File
@@ -2,7 +2,11 @@ import type { OrderedSet as ImmutableOrderedSet } from 'immutable';
import { createAppSelector } from 'mastodon/store';
import type { StatusShape } from '../models/status';
import type { ExpandedStatusShape, StatusShape } from '../models/status';
import { selectPlainAccount } from './accounts';
import type { FilterShape } from './filters';
import { getFilters } from './filters';
export const getStatusList = createAppSelector(
[
@@ -21,3 +25,84 @@ export const selectPlainStatus = createAppSelector(
return status.toJS() as unknown as StatusShape;
},
);
export const selectAccountStatus = createAppSelector(
[
selectPlainStatus,
(state, statusId: string) => {
const accountId = state.statuses.getIn(statusId, 'account');
if (typeof accountId !== 'string') {
return null;
}
return selectPlainAccount(state, accountId);
},
],
(status, account) => {
if (!status || !account) {
return null;
}
return {
...status,
account,
};
},
);
export const selectExpandedStatus = createAppSelector(
[
selectAccountStatus,
(state, statusId: string) => {
const reblogId = state.statuses.getIn(statusId, 'reblog');
if (typeof reblogId !== 'string') {
return null;
}
return selectAccountStatus(state, reblogId);
},
],
(status, reblog): ExpandedStatusShape | null => {
if (!status) {
return null;
}
return {
...status,
reblog: reblog ?? undefined,
};
},
);
export const selectPictureInPicture = createAppSelector(
[
(state, statusId: string) =>
state.picture_in_picture.type !== null &&
state.picture_in_picture.statusId === statusId,
(state) => state.meta.get('layout') !== 'mobile',
],
(inUse, available) => ({
inUse: inUse && available,
available,
}),
);
export const selectMediaMatchFilters = createAppSelector(
[
(state, { statusId }: { statusId: string }) =>
selectPlainStatus(state, statusId),
getFilters,
],
(status, immutableFilters) => {
const filters = immutableFilters
? (immutableFilters.toJS() as unknown as Record<string, FilterShape>)
: null;
const mediaFilters: string[] = [];
if (status?.filtered && filters) {
for (const { filter } of status.filtered) {
if (filters[filter]?.filter_action === 'blur') {
mediaFilters.push(filters[filter].title);
}
}
}
return mediaFilters;
},
);