mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +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 plugins = require('../plugins');
|
||||
const activitypub = require('../activitypub');
|
||||
const utils = require('../utils');
|
||||
|
||||
const intFields = [
|
||||
@@ -57,6 +58,10 @@ module.exports = function (Posts) {
|
||||
|
||||
function modifyPost(post, fields) {
|
||||
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);
|
||||
if (post.hasOwnProperty('upvotes') && post.hasOwnProperty('downvotes')) {
|
||||
post.votes = post.upvotes - post.downvotes;
|
||||
|
||||
@@ -7,6 +7,7 @@ const utils = require('../utils');
|
||||
const user = require('../user');
|
||||
const privileges = require('../privileges');
|
||||
const plugins = require('../plugins');
|
||||
const activitypub = require('../activitypub');
|
||||
|
||||
const Posts = module.exports;
|
||||
|
||||
@@ -44,6 +45,9 @@ Posts.getPostsByPids = async function (pids, uid) {
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const remotePids = pids.filter(pid => !utils.isNumber(pid));
|
||||
await activitypub.assertNotes(uid, remotePids);
|
||||
let posts = await Posts.getPostsData(pids);
|
||||
posts = await Promise.all(posts.map(Posts.parsePost));
|
||||
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 plugins = require('../plugins');
|
||||
const activitypub = require('../activitypub');
|
||||
const translator = require('../translator');
|
||||
const utils = require('../utils');
|
||||
|
||||
@@ -51,7 +52,7 @@ module.exports = function (Posts) {
|
||||
if (!postData) {
|
||||
return postData;
|
||||
}
|
||||
postData.content = String(postData.content || '');
|
||||
postData.content = String(postData.sourceContent || postData.content || '');
|
||||
const cache = require('./cache');
|
||||
const pid = String(postData.pid);
|
||||
const cachedContent = cache.get(pid);
|
||||
@@ -60,12 +61,14 @@ module.exports = function (Posts) {
|
||||
return postData;
|
||||
}
|
||||
|
||||
const data = await plugins.hooks.fire('filter:parse.post', { postData: postData });
|
||||
data.postData.content = translator.escape(data.postData.content);
|
||||
if (data.postData.pid) {
|
||||
cache.set(pid, data.postData.content);
|
||||
if (!activitypub.helpers.isUri(postData.pid) || postData.hasOwnProperty('sourceContent')) {
|
||||
({ postData } = await plugins.hooks.fire('filter:parse.post', { postData }));
|
||||
}
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user