Skip to content

Node.js based forum software built for the modern web

feat(activitypub): render remote emoji in actor names

Julian Lamd0cbe18da978
diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js
index aba5ce2791..29f0eb47d2 100644
--- a/public/src/modules/helpers.common.js
+++ b/public/src/modules/helpers.common.js
@@ -30,7 +30,7 @@ module.exports = function (utils, Benchpress, tx, relative_path) {
renderDigestAvatar,
userAgentIcons,
buildAvatar,
- renderTitleEmoji,
+ renderShortcodeEmoji,
increment,
lessthan,
greaterthan,
@@ -550,11 +550,11 @@ module.exports = function (utils, Benchpress, tx, relative_path) {
return html.join('');
}
- function renderTitleEmoji(title, emojiMeta) {
- if (!title || !emojiMeta || !emojiMeta.length) {
- return String(title || '');
+ function renderShortcodeEmoji(text, emojiMeta) {
+ if (!text || !emojiMeta || !emojiMeta.length) {
+ return String(text || '');
}
- let result = String(title);
+ let result = String(text);
for (const { clean, hostname } of emojiMeta) {
const code = `:${clean}:`;
const proxyUrl = `/emoji/ap/${encodeURIComponent(clean)}/${encodeURIComponent(hostname)}`;
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index ac5f9fe021..a16e0e1f9f 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -251,6 +251,26 @@ Mocks.profile = async (actors) => {
bgColor = iconBackgrounds[bgColor % iconBackgrounds.length];
summary = await activitypub.helpers.renderEmoji(summary || '', tag);
+ // Extract emoji metadata for fullname rendering (titleEmoji pattern)
+ const nameEmoji = [];
+ const emojiTags = (tag || []).filter(tag => tag.type === 'Emoji');
+ for (const emojiTag of emojiTags) {
+ const { name: emojiName, icon } = emojiTag;
+ if (!emojiName || !icon?.url) continue;
+ let code = emojiName;
+ if (!code.startsWith(':')) code = `:${code}`;
+ if (!code.endsWith(':')) code = `${code}:`;
+ if (name && name.includes(code)) {
+ try {
+ const { hostname } = new URL(icon.url);
+ const clean = code.replace(/^:+|:+$/g, '');
+ nameEmoji.push({ code, hostname, clean });
+ } catch {
+ // skip invalid icon URLs
+ }
+ }
+ }
+
// Add custom fields into user hash
const customFields = actor.attachment && Array.isArray(actor.attachment) && actor.attachment.length ?
actor.attachment
@@ -289,6 +309,7 @@ Mocks.profile = async (actors) => {
userslug: `${preferredUsername}@${canonicalHostname}`.toLowerCase(),
displayname: name,
fullname: name,
+ fullnameEmoji: nameEmoji.length ? JSON.stringify(nameEmoji) : undefined,
joindate: new Date(published).getTime() || Date.now(),
picture,
status: 'offline',
diff --git a/src/user/data.js b/src/user/data.js
index d7857bb0a9..11d81e56de 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -28,7 +28,7 @@ const intFields = [
module.exports = function (User) {
const fieldWhitelist = [
'uid', 'username', 'userslug', 'url', 'email', 'email:confirmed', 'joindate',
- 'lastonline', 'picture', 'icon:bgColor', 'fullname', 'birthday',
+ 'lastonline', 'picture', 'icon:bgColor', 'fullname', 'fullnameEmoji', 'birthday',
'aboutme', 'signature', 'uploadedpicture', 'profileviews', 'reputation',
'postcount', 'topiccount', 'lastposttime', 'banned', 'banned:expire',
'status', 'flags', 'followerCount', 'followingCount', 'cover:url',
@@ -272,6 +272,11 @@ module.exports = function (User) {
db.parseIntFields(user, intFields, requestedFields);
+ // Parse fullnameEmoji from JSON (titleEmoji pattern)
+ if (user.hasOwnProperty('fullnameEmoji')) {
+ user.fullnameEmoji = user.fullnameEmoji ? JSON.parse(String(user.fullnameEmoji)) : [];
+ }
+
if (user.hasOwnProperty('username')) {
user.username = String(user.username || '');
}
diff --git a/src/views/partials/feed/item.tpl b/src/views/partials/feed/item.tpl
index 92c15933a8..b0800a99c7 100644
--- a/src/views/partials/feed/item.tpl
+++ b/src/views/partials/feed/item.tpl
@@ -48,7 +48,7 @@
<div>
{{{ if !./topic.generatedTitle }}}
<a class="lh-1 topic-title fw-semibold fs-5 text-reset line-clamp-2" href="{config.relative_path}/topic/{./topic.slug}">
- {{renderTitleEmoji(./topic.title, ./topic.titleEmoji)}}
+ {{renderShortcodeEmoji(./topic.title, ./topic.titleEmoji)}}
</a>
{{{ end }}}
</div>
diff --git a/src/views/partials/search/results.tpl b/src/views/partials/search/results.tpl
index 0f4a4efcd1..ee12085c54 100644
--- a/src/views/partials/search/results.tpl
+++ b/src/views/partials/search/results.tpl
@@ -18,7 +18,7 @@
<hr/>
<div class="topic-row mb-3">
<a class="topic-title fw-semibold fs-5 text-reset text-break" href="{config.relative_path}/post/{encodeURIComponent(./pid)}">
- {{{ if !./isMainPost }}}RE: {{{ end }}}{{renderTitleEmoji(./topic.title, ./topic.titleEmoji)}}
+ {{{ if !./isMainPost }}}RE: {{{ end }}}{{renderShortcodeEmoji(./topic.title, ./topic.titleEmoji)}}
</a>
<div class="post-body d-flex flex-column gap-1">
<div class="d-flex gap-3 post-info">
diff --git a/src/views/post-queue.tpl b/src/views/post-queue.tpl
index 880af0d0dc..cf09ca0125 100644
--- a/src/views/post-queue.tpl
+++ b/src/views/post-queue.tpl
@@ -147,14 +147,14 @@
<span class="small topic-title text-break">
{{{ if posts.data.tid }}}
<div class="d-flex flex-column align-items-start gap-1">
- <a href="{config.relative_path}/topic/{posts.data.tid}">{{renderTitleEmoji(posts.topic.title, posts.topic.titleEmoji)}}</a>
+ <a href="{config.relative_path}/topic/{posts.data.tid}">{{renderShortcodeEmoji(posts.topic.title, posts.topic.titleEmoji)}}</a>
<span class="badge text-body border border-gray-300 stats text-xs">
<span class="text-lowercase fw-normal">{{tx("global:lastpost")}}</span>
<span title="{posts.topic.lastposttimeISO}" class="timeago fw-bold"></span>
</span>
</div>
{{{ end }}}
- <span class="title-text">{{renderTitleEmoji(posts.data.title, posts.data.titleEmoji)}}</span>
+ <span class="title-text">{{renderShortcodeEmoji(posts.data.title, posts.data.titleEmoji)}}</span>
</span>
{{{if !posts.data.tid}}}
<div class="topic-title-editable hidden">