emoji dms
This commit is contained in:
@@ -359,16 +359,25 @@ if (window.__dmLoaded) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pre-fetch emojis so :name: syntax renders correctly even on first /messages load.
|
// Pre-fetch emojis so :name: syntax renders correctly even on first /messages load.
|
||||||
// This mirrors CommentSystem.loadEmojis() but works without a comment system instance.
|
// Must be awaited before loadThread() so the cache is populated when renderDmEmojis runs.
|
||||||
(async () => {
|
await (async () => {
|
||||||
if ((typeof CommentSystem !== 'undefined' && CommentSystem.emojiCache)
|
const cachedInstance = window.commentSystem?.customEmojis;
|
||||||
|| window.commentSystem?.customEmojis) {
|
const cachedStatic = (typeof CommentSystem !== 'undefined') ? CommentSystem.emojiCache : null;
|
||||||
// Already loaded — dispatch so the re-render handler can fire if needed
|
const activeCache = cachedStatic || cachedInstance;
|
||||||
const cached = (typeof CommentSystem !== 'undefined' && CommentSystem.emojiCache)
|
|
||||||
|| window.commentSystem.customEmojis;
|
// Only skip if the cache is non-empty (an empty {} means "no patterns scanned",
|
||||||
window.dispatchEvent(new CustomEvent('f0ck:emojis_ready', { detail: cached }));
|
// not "no emojis exist" — we must still fetch for the DM thread).
|
||||||
|
if (activeCache && Object.keys(activeCache).length > 0) return;
|
||||||
|
|
||||||
|
// If a fetch is already in flight, wait for it to resolve instead of firing a second one.
|
||||||
|
if (typeof CommentSystem !== 'undefined' && CommentSystem.loadingEmojis) {
|
||||||
|
await new Promise(resolve => {
|
||||||
|
const h = () => { window.removeEventListener('f0ck:emojis_ready', h); resolve(); };
|
||||||
|
window.addEventListener('f0ck:emojis_ready', h);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v2/emojis');
|
const res = await fetch('/api/v2/emojis');
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -376,7 +385,7 @@ if (window.__dmLoaded) {
|
|||||||
const map = {};
|
const map = {};
|
||||||
data.emojis.forEach(e => { map[e.name] = e.url; });
|
data.emojis.forEach(e => { map[e.name] = e.url; });
|
||||||
if (typeof CommentSystem !== 'undefined') CommentSystem.emojiCache = map;
|
if (typeof CommentSystem !== 'undefined') CommentSystem.emojiCache = map;
|
||||||
window.dispatchEvent(new CustomEvent('f0ck:emojis_ready', { detail: map }));
|
if (window.commentSystem) window.commentSystem.customEmojis = map;
|
||||||
}
|
}
|
||||||
} catch { /* non-critical — emojis can fall back to :name: text */ }
|
} catch { /* non-critical — emojis can fall back to :name: text */ }
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user