mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: #12683, parse incoming emoji tags and replace in content prior to storage in database
This commit is contained in:
@@ -152,3 +152,7 @@ blockquote {
|
||||
.pull-right {
|
||||
float: right!important;
|
||||
}
|
||||
|
||||
img.emoji {
|
||||
height: $font-size-lg;
|
||||
}
|
||||
@@ -11,6 +11,8 @@ const privileges = require('../privileges');
|
||||
const activitypub = require('../activitypub');
|
||||
const utils = require('../utils');
|
||||
|
||||
const isEmojiShortcode = /^:[\w]+:$/;
|
||||
|
||||
module.exports = function (Posts) {
|
||||
Posts.create = async function (data) {
|
||||
// This is an internal method, consider using Topics.reply instead
|
||||
@@ -28,13 +30,7 @@ module.exports = function (Posts) {
|
||||
}
|
||||
|
||||
const pid = data.pid || await db.incrObjectField('global', 'nextPid');
|
||||
let postData = {
|
||||
pid: pid,
|
||||
uid: uid,
|
||||
tid: tid,
|
||||
content: content,
|
||||
timestamp: timestamp,
|
||||
};
|
||||
let postData = { pid, uid, tid, content, timestamp };
|
||||
|
||||
if (data.toPid) {
|
||||
postData.toPid = data.toPid;
|
||||
@@ -49,6 +45,17 @@ module.exports = function (Posts) {
|
||||
postData.url = _activitypub.url;
|
||||
}
|
||||
|
||||
// Rewrite emoji references to inline image assets
|
||||
if (_activitypub && _activitypub.tag && Array.isArray(_activitypub.tag)) {
|
||||
_activitypub.tag
|
||||
.filter(tag => tag.type === 'Emoji' &&
|
||||
isEmojiShortcode.test(tag.name) &&
|
||||
tag.icon && tag.icon.mediaType && tag.icon.mediaType.startsWith('image/'))
|
||||
.forEach((tag) => {
|
||||
postData.content = postData.content.replace(new RegExp(tag.name, 'g'), `<img class="not-responsive emoji" src="${tag.icon.url}" />`);
|
||||
});
|
||||
}
|
||||
|
||||
({ post: postData } = await plugins.hooks.fire('filter:post.create', { post: postData, data: data }));
|
||||
await db.setObject(`post:${postData.pid}`, postData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user