diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index e8dd50c345..41a60f24ad 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -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'), ``); + }); + } + // Add custom fields into user hash const customFields = actor.attachment && Array.isArray(actor.attachment) && actor.attachment.length ? actor.attachment