mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: added mocks.note in preparation for AP note retrieval logic, inReplyTo is always populated now, unless new topic
This commit is contained in:
@@ -5,6 +5,8 @@ const mime = require('mime');
|
|||||||
|
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
|
const posts = require('../posts');
|
||||||
|
const topics = require('../topics');
|
||||||
|
|
||||||
const activitypub = module.parent.exports;
|
const activitypub = module.parent.exports;
|
||||||
const Mocks = module.exports;
|
const Mocks = module.exports;
|
||||||
@@ -166,3 +168,51 @@ Mocks.actor = async (uid) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Mocks.note = async (post) => {
|
||||||
|
const id = `${nconf.get('url')}/post/${post.pid}`;
|
||||||
|
const published = new Date(post.timestamp).toISOString();
|
||||||
|
|
||||||
|
const [raw, userslug] = await Promise.all([
|
||||||
|
posts.getPostField(post.pid, 'content'),
|
||||||
|
user.getUserField(post.user.uid, 'userslug'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// todo: post visibility, category privileges integration
|
||||||
|
const to = [activitypub._constants.publicAddress];
|
||||||
|
const cc = [`${nconf.get('url')}/user/${userslug}/followers`];
|
||||||
|
|
||||||
|
let inReplyTo = null;
|
||||||
|
if (post.toPid) {
|
||||||
|
inReplyTo = activitypub.helpers.isUri(post.toPid) ? post.toPid : `${nconf.get('url')}/post/${post.toPid}`;
|
||||||
|
const parentId = await posts.getPostField(post.toPid, 'uid');
|
||||||
|
if (activitypub.helpers.isUri(parentId)) {
|
||||||
|
to.unshift(parentId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const mainPid = await topics.getTopicFieldByPid('mainPid', post.pid);
|
||||||
|
if (mainPid !== post.pid) {
|
||||||
|
inReplyTo = `${nconf.get('url')}/post/${mainPid}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const object = {
|
||||||
|
id,
|
||||||
|
type: 'Note',
|
||||||
|
to,
|
||||||
|
cc,
|
||||||
|
inReplyTo,
|
||||||
|
published,
|
||||||
|
url: id,
|
||||||
|
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,
|
||||||
|
sensitive: false, // todo
|
||||||
|
content: post.content,
|
||||||
|
source: {
|
||||||
|
content: raw,
|
||||||
|
mediaType: 'text/markdown',
|
||||||
|
},
|
||||||
|
// replies: {} todo...
|
||||||
|
};
|
||||||
|
|
||||||
|
return object;
|
||||||
|
};
|
||||||
|
|||||||
@@ -53,52 +53,28 @@ activitypubApi.unfollow = async (caller, { uid: actorId }) => {
|
|||||||
|
|
||||||
activitypubApi.create = {};
|
activitypubApi.create = {};
|
||||||
|
|
||||||
activitypubApi.create.post = async (caller, { post }) => {
|
activitypubApi.create.post = async (caller, { pid }) => {
|
||||||
const id = `${nconf.get('url')}/post/${post.pid}`;
|
const post = (await posts.getPostSummaryByPids([pid], caller.uid, { stripTags: false })).pop();
|
||||||
const published = new Date(post.timestamp).toISOString();
|
if (!post) {
|
||||||
const [userslug, raw, followers] = await Promise.all([
|
return;
|
||||||
user.getUserField(caller.uid, 'userslug'),
|
}
|
||||||
posts.getPostField(post.pid, 'content'),
|
|
||||||
db.getSortedSetMembers(`followersRemote:${caller.uid}`),
|
const [object, followers] = await Promise.all([
|
||||||
|
activitypub.mocks.note(post),
|
||||||
|
db.getSortedSetMembers(`followersRemote:${post.user.uid}`),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// todo: post visibility, category privileges integration
|
const { to, cc } = object;
|
||||||
const recipients = {
|
|
||||||
to: [activitypub._constants.publicAddress],
|
|
||||||
cc: [`${nconf.get('url')}/user/${userslug}/followers`],
|
|
||||||
};
|
|
||||||
const targets = new Set(followers);
|
const targets = new Set(followers);
|
||||||
|
const parentId = await posts.getPostField(object.inReplyTo, 'uid');
|
||||||
let inReplyTo = null;
|
|
||||||
if (post.toPid) {
|
|
||||||
inReplyTo = activitypub.helpers.isUri(post.toPid) ? post.toPid : id;
|
|
||||||
const parentId = await posts.getPostField(post.toPid, 'uid');
|
|
||||||
if (activitypub.helpers.isUri(parentId)) {
|
if (activitypub.helpers.isUri(parentId)) {
|
||||||
recipients.to.unshift(parentId);
|
to.unshift(parentId);
|
||||||
targets.add(parentId);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const object = {
|
|
||||||
id,
|
|
||||||
type: 'Note',
|
|
||||||
...recipients,
|
|
||||||
inReplyTo,
|
|
||||||
published,
|
|
||||||
url: id,
|
|
||||||
attributedTo: `${nconf.get('url')}/user/${post.user.userslug}`,
|
|
||||||
sensitive: false, // todo
|
|
||||||
content: post.content,
|
|
||||||
source: {
|
|
||||||
content: raw,
|
|
||||||
mediaType: 'text/markdown',
|
|
||||||
},
|
|
||||||
// replies: {} todo...
|
|
||||||
};
|
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
type: 'Create',
|
type: 'Create',
|
||||||
...recipients,
|
to,
|
||||||
|
cc,
|
||||||
object,
|
object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ topicsAPI.create = async function (caller, data) {
|
|||||||
socketHelpers.emitToUids('event:new_post', { posts: [result.postData] }, [caller.uid]);
|
socketHelpers.emitToUids('event:new_post', { posts: [result.postData] }, [caller.uid]);
|
||||||
socketHelpers.emitToUids('event:new_topic', result.topicData, [caller.uid]);
|
socketHelpers.emitToUids('event:new_topic', result.topicData, [caller.uid]);
|
||||||
socketHelpers.notifyNew(caller.uid, 'newTopic', { posts: [result.postData], topic: result.topicData });
|
socketHelpers.notifyNew(caller.uid, 'newTopic', { posts: [result.postData], topic: result.topicData });
|
||||||
activitypubApi.create.post(caller, { post: result.postData });
|
activitypubApi.create.post(caller, { pid: result.postData.pid });
|
||||||
|
|
||||||
return result.topicData;
|
return result.topicData;
|
||||||
};
|
};
|
||||||
@@ -115,7 +115,7 @@ topicsAPI.reply = async function (caller, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
socketHelpers.notifyNew(caller.uid, 'newPost', result);
|
socketHelpers.notifyNew(caller.uid, 'newPost', result);
|
||||||
activitypubApi.create.post(caller, { post: postData });
|
activitypubApi.create.post(caller, { pid: postData.pid });
|
||||||
|
|
||||||
return postObj[0];
|
return postObj[0];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ module.exports = function (Categories) {
|
|||||||
let results = await plugins.hooks.fire('filter:category.topics.prepare', data);
|
let results = await plugins.hooks.fire('filter:category.topics.prepare', data);
|
||||||
const tids = await Categories.getTopicIds(results);
|
const tids = await Categories.getTopicIds(results);
|
||||||
let topicsData = await topics.getTopicsByTids(tids, data.uid);
|
let topicsData = await topics.getTopicsByTids(tids, data.uid);
|
||||||
console.log(topicsData);
|
|
||||||
topicsData = await user.blocks.filter(data.uid, topicsData);
|
topicsData = await user.blocks.filter(data.uid, topicsData);
|
||||||
|
|
||||||
if (!topicsData.length) {
|
if (!topicsData.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user