mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-30 13:17:50 +02:00
feat: activitypub response to note retrieval via pid
This commit is contained in:
@@ -186,14 +186,10 @@ Mocks.note = async (post) => {
|
|||||||
if (post.toPid) {
|
if (post.toPid) {
|
||||||
inReplyTo = activitypub.helpers.isUri(post.toPid) ? post.toPid : `${nconf.get('url')}/post/${post.toPid}`;
|
inReplyTo = activitypub.helpers.isUri(post.toPid) ? post.toPid : `${nconf.get('url')}/post/${post.toPid}`;
|
||||||
const parentId = await posts.getPostField(post.toPid, 'uid');
|
const parentId = await posts.getPostField(post.toPid, 'uid');
|
||||||
if (activitypub.helpers.isUri(parentId)) {
|
to.unshift(activitypub.helpers.isUri(parentId) ? parentId : `${nconf.get('url')}/uid/${parentId}`);
|
||||||
to.unshift(parentId);
|
} else if (!post.isMainPost) {
|
||||||
}
|
inReplyTo = `${nconf.get('url')}/post/${post.topic.mainPid}`;
|
||||||
} else {
|
to.unshift(activitypub.helpers.isUri(post.topic.uid) ? post.topic.uid : `${nconf.get('url')}/uid/${post.topic.uid}`);
|
||||||
const mainPid = await topics.getTopicFieldByPid('mainPid', post.pid);
|
|
||||||
if (mainPid !== post.pid) {
|
|
||||||
inReplyTo = `${nconf.get('url')}/post/${mainPid}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const object = {
|
const object = {
|
||||||
@@ -206,6 +202,7 @@ Mocks.note = async (post) => {
|
|||||||
url: id,
|
url: id,
|
||||||
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,
|
attributedTo: `${nconf.get('url')}/uid/${post.user.uid}`,
|
||||||
sensitive: false, // todo
|
sensitive: false, // todo
|
||||||
|
summary: null,
|
||||||
content: post.content,
|
content: post.content,
|
||||||
source: {
|
source: {
|
||||||
content: raw,
|
content: raw,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
|
|
||||||
const meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
|
const posts = require('../../posts');
|
||||||
const activitypub = require('../../activitypub');
|
const activitypub = require('../../activitypub');
|
||||||
|
|
||||||
const Actors = module.exports;
|
const Actors = module.exports;
|
||||||
@@ -46,3 +47,15 @@ Actors.userBySlug = async function (req, res) {
|
|||||||
delete req.params.userslug;
|
delete req.params.userslug;
|
||||||
Actors.user(req, res);
|
Actors.user(req, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Actors.note = async function (req, res, next) {
|
||||||
|
// technically a note isn't an actor, but it is here purely for organizational purposes.
|
||||||
|
// but also, wouldn't it be wild if you could follow a note? lol.
|
||||||
|
const post = (await posts.getPostSummaryByPids([req.params.pid], req.uid, { stripTags: false })).pop();
|
||||||
|
if (!post) {
|
||||||
|
return next('route');
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = await activitypub.mocks.note(post);
|
||||||
|
res.status(200).json(payload);
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const activitypub = require('../activitypub');
|
|||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
|
||||||
const intFields = [
|
const intFields = [
|
||||||
'uid', 'pid', 'tid', 'deleted', 'timestamp',
|
'uid', 'pid', 'tid', 'toPid', 'deleted', 'timestamp',
|
||||||
'upvotes', 'downvotes', 'deleterUid', 'edited',
|
'upvotes', 'downvotes', 'deleterUid', 'edited',
|
||||||
'replies', 'bookmarks',
|
'replies', 'bookmarks',
|
||||||
];
|
];
|
||||||
@@ -63,6 +63,9 @@ function modifyPost(post, fields) {
|
|||||||
intFields.splice(intFields.indexOf('uid'), 1);
|
intFields.splice(intFields.indexOf('uid'), 1);
|
||||||
intFields.splice(intFields.indexOf('tid'), 1);
|
intFields.splice(intFields.indexOf('tid'), 1);
|
||||||
}
|
}
|
||||||
|
if (activitypub.helpers.isUri(post.toPid)) {
|
||||||
|
intFields.splice(intFields.indexOf('toPid'), 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;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module.exports = function (Posts) {
|
|||||||
options.parse = options.hasOwnProperty('parse') ? options.parse : true;
|
options.parse = options.hasOwnProperty('parse') ? options.parse : true;
|
||||||
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];
|
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];
|
||||||
|
|
||||||
const fields = ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
|
const fields = ['pid', 'tid', 'toPid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
|
||||||
|
|
||||||
let posts = await Posts.getPostsFields(pids, fields);
|
let posts = await Posts.getPostsFields(pids, fields);
|
||||||
posts = posts.filter(Boolean);
|
posts = posts.filter(Boolean);
|
||||||
|
|||||||
@@ -12,18 +12,20 @@ module.exports = function (app, middleware, controllers) {
|
|||||||
* - See middleware.activitypub.assertS2S
|
* - See middleware.activitypub.assertS2S
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const middlewares = [middleware.activitypub.enabled, middleware.activitypub.assertS2S, middleware.exposeUid];
|
const middlewares = [middleware.activitypub.enabled, middleware.activitypub.assertS2S];
|
||||||
|
|
||||||
app.get('/actor', middlewares, controllers.activitypub.actors.application);
|
app.get('/actor', middlewares, controllers.activitypub.actors.application);
|
||||||
app.get('/uid/:uid', [middleware.activitypub.enabled, middleware.activitypub.assertS2S], controllers.activitypub.actors.user);
|
app.get('/uid/:uid', middlewares, controllers.activitypub.actors.user);
|
||||||
app.get('/user/:userslug', middlewares, controllers.activitypub.actors.userBySlug);
|
app.get('/user/:userslug', [...middlewares, middleware.exposeUid], controllers.activitypub.actors.userBySlug);
|
||||||
|
|
||||||
app.get('/user/:userslug/inbox', middlewares, controllers.activitypub.getInbox);
|
app.get('/user/:userslug/inbox', [...middlewares, middleware.exposeUid], controllers.activitypub.getInbox);
|
||||||
app.post('/user/:userslug/inbox', [...middlewares, middleware.activitypub.validate], controllers.activitypub.postInbox);
|
app.post('/user/:userslug/inbox', [...middlewares, middleware.activitypub.validate, middleware.exposeUid], controllers.activitypub.postInbox);
|
||||||
|
|
||||||
app.get('/user/:userslug/outbox', middlewares, controllers.activitypub.getOutbox);
|
app.get('/user/:userslug/outbox', [...middlewares, middleware.exposeUid], controllers.activitypub.getOutbox);
|
||||||
app.post('/user/:userslug/outbox', middlewares, controllers.activitypub.postOutbox);
|
app.post('/user/:userslug/outbox', [...middlewares, middleware.exposeUid], controllers.activitypub.postOutbox);
|
||||||
|
|
||||||
app.get('/user/:userslug/following', middlewares, controllers.activitypub.getFollowing);
|
app.get('/user/:userslug/following', [...middlewares, middleware.exposeUid], controllers.activitypub.getFollowing);
|
||||||
app.get('/user/:userslug/followers', middlewares, controllers.activitypub.getFollowers);
|
app.get('/user/:userslug/followers', [...middlewares, middleware.exposeUid], controllers.activitypub.getFollowers);
|
||||||
|
|
||||||
|
app.get('/post/:pid', middlewares, controllers.activitypub.actors.note);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user