Emoji: Remove final flag (#36409)

This commit is contained in:
Echo 2025-10-28 12:33:27 +01:00 committed by GitHub
commit 85d0cdb5f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 112 additions and 1103 deletions

View file

@ -8,11 +8,10 @@ import type {
ApiAccountRoleJSON,
ApiAccountJSON,
} from 'mastodon/api_types/accounts';
import emojify from 'mastodon/features/emoji/emoji';
import { unescapeHTML } from 'mastodon/utils/html';
import { CustomEmojiFactory, makeEmojiMap } from './custom_emoji';
import type { CustomEmoji, EmojiMap } from './custom_emoji';
import { CustomEmojiFactory } from './custom_emoji';
import type { CustomEmoji } from './custom_emoji';
// AccountField
interface AccountFieldShape extends Required<ApiAccountFieldJSON> {
@ -102,17 +101,11 @@ export const accountDefaultValues: AccountShape = {
const AccountFactory = ImmutableRecord<AccountShape>(accountDefaultValues);
function createAccountField(
jsonField: ApiAccountFieldJSON,
emojiMap: EmojiMap,
) {
function createAccountField(jsonField: ApiAccountFieldJSON) {
return AccountFieldFactory({
...jsonField,
name_emojified: emojify(
escapeTextContentForBrowser(jsonField.name),
emojiMap,
),
value_emojified: emojify(jsonField.value, emojiMap),
name_emojified: escapeTextContentForBrowser(jsonField.name),
value_emojified: jsonField.value,
value_plain: unescapeHTML(jsonField.value),
});
}
@ -120,8 +113,6 @@ function createAccountField(
export function createAccountFromServerJSON(serverJSON: ApiAccountJSON) {
const { moved, ...accountJSON } = serverJSON;
const emojiMap = makeEmojiMap(accountJSON.emojis);
const displayName =
accountJSON.display_name.trim().length === 0
? accountJSON.username
@ -134,7 +125,7 @@ export function createAccountFromServerJSON(serverJSON: ApiAccountJSON) {
...accountJSON,
moved: moved?.id,
fields: ImmutableList(
serverJSON.fields.map((field) => createAccountField(field, emojiMap)),
serverJSON.fields.map((field) => createAccountField(field)),
),
emojis: ImmutableList(
serverJSON.emojis.map((emoji) => CustomEmojiFactory(emoji)),
@ -142,11 +133,8 @@ export function createAccountFromServerJSON(serverJSON: ApiAccountJSON) {
roles: ImmutableList(
serverJSON.roles?.map((role) => AccountRoleFactory(role)),
),
display_name_html: emojify(
escapeTextContentForBrowser(displayName),
emojiMap,
),
note_emojified: emojify(accountNote, emojiMap),
display_name_html: escapeTextContentForBrowser(displayName),
note_emojified: accountNote,
note_plain: unescapeHTML(accountNote),
url:
accountJSON.url?.startsWith('http://') ||

View file

@ -1,10 +1,9 @@
import escapeTextContentForBrowser from 'escape-html';
import type { ApiPollJSON, ApiPollOptionJSON } from 'mastodon/api_types/polls';
import emojify from 'mastodon/features/emoji/emoji';
import { CustomEmojiFactory, makeEmojiMap } from './custom_emoji';
import type { CustomEmoji, EmojiMap } from './custom_emoji';
import { CustomEmojiFactory } from './custom_emoji';
import type { CustomEmoji } from './custom_emoji';
interface PollOptionTranslation {
title: string;
@ -17,16 +16,12 @@ export interface PollOption extends ApiPollOptionJSON {
translation: PollOptionTranslation | null;
}
export function createPollOptionTranslationFromServerJSON(
translation: { title: string },
emojiMap: EmojiMap,
) {
export function createPollOptionTranslationFromServerJSON(translation: {
title: string;
}) {
return {
...translation,
titleHtml: emojify(
escapeTextContentForBrowser(translation.title),
emojiMap,
),
titleHtml: escapeTextContentForBrowser(translation.title),
} as PollOptionTranslation;
}
@ -50,8 +45,6 @@ export function createPollFromServerJSON(
serverJSON: ApiPollJSON,
previousPoll?: Poll,
) {
const emojiMap = makeEmojiMap(serverJSON.emojis);
return {
...pollDefaultValues,
...serverJSON,
@ -60,20 +53,15 @@ export function createPollFromServerJSON(
const option = {
...optionJSON,
voted: serverJSON.own_votes?.includes(index) || false,
titleHtml: emojify(
escapeTextContentForBrowser(optionJSON.title),
emojiMap,
),
titleHtml: escapeTextContentForBrowser(optionJSON.title),
} as PollOption;
const prevOption = previousPoll?.options[index];
if (prevOption?.translation && prevOption.title === option.title) {
const { translation } = prevOption;
option.translation = createPollOptionTranslationFromServerJSON(
translation,
emojiMap,
);
option.translation =
createPollOptionTranslationFromServerJSON(translation);
}
return option;