Emoji: Refresh custom emoji on new (#37271)
This commit is contained in:
7 files changed
+123
-32
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import type { ApiCustomEmojiJSON } from '@/mastodon/api_types/custom_emoji';
|
||||
import { loadCustomEmoji } from '@/mastodon/features/emoji';
|
||||
|
||||
export async function importCustomEmoji(emojis: ApiCustomEmojiJSON[]) {
|
||||
if (emojis.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// First, check if we already have them all.
|
||||
const { searchCustomEmojisByShortcodes, clearEtag } =
|
||||
await import('@/mastodon/features/emoji/database');
|
||||
|
||||
const existingEmojis = await searchCustomEmojisByShortcodes(
|
||||
emojis.map((emoji) => emoji.shortcode),
|
||||
);
|
||||
|
||||
// If there's a mismatch, re-import all custom emojis.
|
||||
if (existingEmojis.length < emojis.length) {
|
||||
await clearEtag('custom');
|
||||
await loadCustomEmoji();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createPollFromServerJSON } from 'mastodon/models/poll';
|
||||
|
||||
import { importAccounts } from './accounts';
|
||||
import { importCustomEmoji } from './emoji';
|
||||
import { normalizeStatus } from './normalizer';
|
||||
import { importPolls } from './polls';
|
||||
|
||||
@@ -39,6 +40,10 @@ export function importFetchedAccounts(accounts) {
|
||||
if (account.moved) {
|
||||
processAccount(account.moved);
|
||||
}
|
||||
|
||||
if (account.emojis && account.username === account.acct) {
|
||||
importCustomEmoji(account.emojis);
|
||||
}
|
||||
}
|
||||
|
||||
accounts.forEach(processAccount);
|
||||
@@ -80,6 +85,10 @@ export function importFetchedStatuses(statuses, options = {}) {
|
||||
if (status.card) {
|
||||
status.card.authors.forEach(author => author.account && pushUnique(accounts, author.account));
|
||||
}
|
||||
|
||||
if (status.emojis && status.account.username === status.account.acct) {
|
||||
importCustomEmoji(status.emojis);
|
||||
}
|
||||
}
|
||||
|
||||
statuses.forEach(processStatus);
|
||||
|
||||
@@ -2,6 +2,8 @@ import escapeTextContentForBrowser from 'escape-html';
|
||||
|
||||
import { expandSpoilers } from '../../initial_state';
|
||||
|
||||
import { importCustomEmoji } from './emoji';
|
||||
|
||||
const domParser = new DOMParser();
|
||||
|
||||
export function searchTextFromRawStatus (status) {
|
||||
@@ -151,5 +153,9 @@ export function normalizeAnnouncement(announcement) {
|
||||
|
||||
normalAnnouncement.contentHtml = normalAnnouncement.content;
|
||||
|
||||
if (normalAnnouncement.emojis) {
|
||||
importCustomEmoji(normalAnnouncement.emojis);
|
||||
}
|
||||
|
||||
return normalAnnouncement;
|
||||
}
|
||||
Reference in new issue
Block a user