mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #12939 convert custom emoji in actor summary into images
This commit is contained in:
@@ -19,6 +19,8 @@ const utils = require('../utils');
|
||||
|
||||
const accountHelpers = require('../controllers/accounts/helpers');
|
||||
|
||||
const isEmojiShortcode = /^:[\w]+:$/;
|
||||
|
||||
const activitypub = module.parent.exports;
|
||||
const Mocks = module.exports;
|
||||
|
||||
@@ -47,7 +49,7 @@ Mocks.profile = async (actors, hostMap) => {
|
||||
let hostname = hostMap.get(uid);
|
||||
let {
|
||||
url, preferredUsername, published, icon, image,
|
||||
name, summary, followers, inbox, endpoints,
|
||||
name, summary, followers, inbox, endpoints, tag,
|
||||
} = actor;
|
||||
preferredUsername = slugify(preferredUsername || name);
|
||||
const { followers: followerCount, following: followingCount } = await activitypub.actors.getLocalFollowCounts(uid);
|
||||
@@ -68,6 +70,17 @@ Mocks.profile = async (actors, hostMap) => {
|
||||
let bgColor = Array.prototype.reduce.call(preferredUsername, (cur, next) => cur + next.charCodeAt(), 0);
|
||||
bgColor = iconBackgrounds[bgColor % iconBackgrounds.length];
|
||||
|
||||
// Replace emoji in summary
|
||||
if (tag && Array.isArray(tag)) {
|
||||
tag
|
||||
.filter(tag => tag.type === 'Emoji' &&
|
||||
isEmojiShortcode.test(tag.name) &&
|
||||
tag.icon && tag.icon.mediaType && tag.icon.mediaType.startsWith('image/'))
|
||||
.forEach((tag) => {
|
||||
summary = summary.replace(new RegExp(tag.name, 'g'), `<img class="not-responsive emoji" src="${tag.icon.url}" title="${tag.name}" />`);
|
||||
});
|
||||
}
|
||||
|
||||
// Add custom fields into user hash
|
||||
const customFields = actor.attachment && Array.isArray(actor.attachment) && actor.attachment.length ?
|
||||
actor.attachment
|
||||
|
||||
Reference in New Issue
Block a user