kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'fix-1602' into 'main'
Fix parsing custom emoji reactions Closes #1602 See merge request soapbox-pub/soapbox!2854environments/review-main-yi2y9f/deployments/4263
commit
1616cc50e8
|
@ -14,6 +14,7 @@ import { normalizeAttachment } from 'soapbox/normalizers/attachment';
|
||||||
import { normalizeEmoji } from 'soapbox/normalizers/emoji';
|
import { normalizeEmoji } from 'soapbox/normalizers/emoji';
|
||||||
import { normalizeMention } from 'soapbox/normalizers/mention';
|
import { normalizeMention } from 'soapbox/normalizers/mention';
|
||||||
import { accountSchema, cardSchema, emojiReactionSchema, groupSchema, pollSchema, tombstoneSchema } from 'soapbox/schemas';
|
import { accountSchema, cardSchema, emojiReactionSchema, groupSchema, pollSchema, tombstoneSchema } from 'soapbox/schemas';
|
||||||
|
import { filteredArray } from 'soapbox/schemas/utils';
|
||||||
import { maybeFromJS } from 'soapbox/utils/normalizers';
|
import { maybeFromJS } from 'soapbox/utils/normalizers';
|
||||||
|
|
||||||
import type { Account, Attachment, Card, Emoji, Group, Mention, Poll, EmbeddedEntity, EmojiReaction } from 'soapbox/types/entities';
|
import type { Account, Attachment, Card, Emoji, Group, Mention, Poll, EmbeddedEntity, EmojiReaction } from 'soapbox/types/entities';
|
||||||
|
@ -219,11 +220,13 @@ const normalizeEvent = (status: ImmutableMap<string, any>) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normalize emojis
|
/** Normalize emojis. */
|
||||||
const normalizeEmojis = (status: ImmutableMap<string, any>) => {
|
const normalizeEmojis = (status: ImmutableMap<string, any>) => {
|
||||||
const reactions = status.getIn(['pleroma', 'emoji_reactions'], status.get('reactions')) as ImmutableList<ImmutableMap<string, any>>;
|
const data = ImmutableList<ImmutableMap<string, any>>(status.getIn(['pleroma', 'emoji_reactions']) || status.get('reactions'));
|
||||||
|
const reactions = filteredArray(emojiReactionSchema).parse(data.toJS());
|
||||||
|
|
||||||
if (reactions) {
|
if (reactions) {
|
||||||
status.set('reactions', ImmutableList(reactions.map(((reaction: ImmutableMap<string, any>) => emojiReactionSchema.parse(reaction.toJS())))));
|
status.set('reactions', ImmutableList(reactions));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,22 @@ import { z } from 'zod';
|
||||||
|
|
||||||
import { emojiSchema } from './utils';
|
import { emojiSchema } from './utils';
|
||||||
|
|
||||||
/** Pleroma emoji reaction. */
|
const baseEmojiReactionSchema = z.object({
|
||||||
const emojiReactionSchema = z.object({
|
|
||||||
name: emojiSchema,
|
|
||||||
count: z.number().nullable().catch(null),
|
count: z.number().nullable().catch(null),
|
||||||
me: z.boolean().catch(false),
|
me: z.boolean().catch(false),
|
||||||
/** Akkoma custom emoji reaction. */
|
name: emojiSchema,
|
||||||
url: z.string().url().optional().catch(undefined),
|
url: z.literal(undefined).catch(undefined),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const customEmojiReactionSchema = baseEmojiReactionSchema.extend({
|
||||||
|
name: z.string(),
|
||||||
|
/** Akkoma custom emoji reaction. */
|
||||||
|
url: z.string().url(),
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Pleroma emoji reaction. */
|
||||||
|
const emojiReactionSchema = baseEmojiReactionSchema.or(customEmojiReactionSchema);
|
||||||
|
|
||||||
type EmojiReaction = z.infer<typeof emojiReactionSchema>;
|
type EmojiReaction = z.infer<typeof emojiReactionSchema>;
|
||||||
|
|
||||||
export { emojiReactionSchema, type EmojiReaction };
|
export { emojiReactionSchema, type EmojiReaction };
|
Ładowanie…
Reference in New Issue