mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 02:25:55 +01:00
feat: ability to load remote post data in a topic
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const activitypub = require('../activitypub');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
|
||||||
const intFields = [
|
const intFields = [
|
||||||
@@ -57,6 +58,10 @@ module.exports = function (Posts) {
|
|||||||
|
|
||||||
function modifyPost(post, fields) {
|
function modifyPost(post, fields) {
|
||||||
if (post) {
|
if (post) {
|
||||||
|
if (activitypub.helpers.isUri(post.pid)) {
|
||||||
|
intFields.splice(intFields.indexOf('pid'), 1);
|
||||||
|
intFields.splice(intFields.indexOf('uid'), 1);
|
||||||
|
}
|
||||||
db.parseIntFields(post, intFields, fields);
|
db.parseIntFields(post, intFields, fields);
|
||||||
if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) {
|
if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) {
|
||||||
post.votes = post.upvotes - post.downvotes;
|
post.votes = post.upvotes - post.downvotes;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const utils = require('../utils');
|
|||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const activitypub = require('../activitypub');
|
||||||
|
|
||||||
const Posts = module.exports;
|
const Posts = module.exports;
|
||||||
|
|
||||||
@@ -44,6 +45,9 @@ Posts.getPostsByPids = async function (pids, uid) {
|
|||||||
if (!Array.isArray(pids) || !pids.length) {
|
if (!Array.isArray(pids) || !pids.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const remotePids = pids.filter(pid => !utils.isNumber(pid));
|
||||||
|
await activitypub.assertNotes(uid, remotePids);
|
||||||
let posts = await Posts.getPostsData(pids);
|
let posts = await Posts.getPostsData(pids);
|
||||||
posts = await Promise.all(posts.map(Posts.parsePost));
|
posts = await Promise.all(posts.map(Posts.parsePost));
|
||||||
const data = await plugins.hooks.fire('filter:post.getPosts', { posts: posts, uid: uid });
|
const data = await plugins.hooks.fire('filter:post.getPosts', { posts: posts, uid: uid });
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const activitypub = require('../activitypub');
|
||||||
const translator = require('../translator');
|
const translator = require('../translator');
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ module.exports = function (Posts) {
|
|||||||
if (!postData) {
|
if (!postData) {
|
||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
postData.content = String(postData.content || '');
|
postData.content = String(postData.sourceContent || postData.content || '');
|
||||||
const cache = require('./cache');
|
const cache = require('./cache');
|
||||||
const pid = String(postData.pid);
|
const pid = String(postData.pid);
|
||||||
const cachedContent = cache.get(pid);
|
const cachedContent = cache.get(pid);
|
||||||
@@ -60,12 +61,14 @@ module.exports = function (Posts) {
|
|||||||
return postData;
|
return postData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await plugins.hooks.fire('filter:parse.post', { postData: postData });
|
if (!activitypub.helpers.isUri(postData.pid) || postData.hasOwnProperty('sourceContent')) {
|
||||||
data.postData.content = translator.escape(data.postData.content);
|
({ postData } = await plugins.hooks.fire('filter:parse.post', { postData }));
|
||||||
if (data.postData.pid) {
|
|
||||||
cache.set(pid, data.postData.content);
|
|
||||||
}
|
}
|
||||||
return data.postData;
|
postData.content = translator.escape(postData.content);
|
||||||
|
if (postData.pid) {
|
||||||
|
cache.set(pid, postData.content);
|
||||||
|
}
|
||||||
|
return postData;
|
||||||
};
|
};
|
||||||
|
|
||||||
Posts.parseSignature = async function (userData, uid) {
|
Posts.parseSignature = async function (userData, uid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user