mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
feat: inbox handler for Remove(Context)
This commit is contained in:
@@ -13,6 +13,7 @@ const notifications = require('../notifications');
|
|||||||
const messaging = require('../messaging');
|
const messaging = require('../messaging');
|
||||||
const flags = require('../flags');
|
const flags = require('../flags');
|
||||||
const api = require('../api');
|
const api = require('../api');
|
||||||
|
const utils = require('../utils');
|
||||||
const activitypub = require('.');
|
const activitypub = require('.');
|
||||||
|
|
||||||
const socketHelpers = require('../socket.io/helpers');
|
const socketHelpers = require('../socket.io/helpers');
|
||||||
@@ -78,6 +79,42 @@ inbox.add = async (req) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inbox.remove = async (req) => {
|
||||||
|
const { actor, object } = req.body;
|
||||||
|
|
||||||
|
const isContext = activitypub._constants.acceptable.contextTypes.has(object.type);
|
||||||
|
if (!isContext) {
|
||||||
|
return; // don't know how to handle other types
|
||||||
|
}
|
||||||
|
console.log('isContext?', isContext);
|
||||||
|
|
||||||
|
const mainPid = await activitypub.contexts.getItems(0, object.id, { returnRootId: true });
|
||||||
|
const exists = await posts.exists(mainPid);
|
||||||
|
if (!exists) {
|
||||||
|
return; // post not cached; do nothing.
|
||||||
|
}
|
||||||
|
console.log('mainPid is', mainPid);
|
||||||
|
|
||||||
|
// Ensure that cid is same-origin as the actor
|
||||||
|
const tid = await posts.getPostField(mainPid, 'tid');
|
||||||
|
const cid = await topics.getTopicField(tid, 'cid');
|
||||||
|
if (utils.isNumber(cid)) {
|
||||||
|
// remote removal of topic in local cid; what??
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const actorHostname = new URL(actor).hostname;
|
||||||
|
const cidHostname = new URL(cid).hostname;
|
||||||
|
if (actorHostname !== cidHostname) {
|
||||||
|
throw new Error('[[error:activitypub.origin-mismatch]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
activitypub.helpers.log(`[activitypub/inbox/remove] Removing topic ${tid} from ${cid}`);
|
||||||
|
await topics.tools.move(tid, {
|
||||||
|
cid: -1,
|
||||||
|
uid: 'system',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
inbox.update = async (req) => {
|
inbox.update = async (req) => {
|
||||||
const { actor, object } = req.body;
|
const { actor, object } = req.body;
|
||||||
const isPublic = publiclyAddressed([...(object.to || []), ...(object.cc || [])]);
|
const isPublic = publiclyAddressed([...(object.to || []), ...(object.cc || [])]);
|
||||||
@@ -182,7 +219,6 @@ inbox.update = async (req) => {
|
|||||||
|
|
||||||
inbox.delete = async (req) => {
|
inbox.delete = async (req) => {
|
||||||
const { actor, object } = req.body;
|
const { actor, object } = req.body;
|
||||||
console.log(actor, object);
|
|
||||||
if (typeof object !== 'string') {
|
if (typeof object !== 'string') {
|
||||||
const { id } = object;
|
const { id } = object;
|
||||||
if (!id) {
|
if (!id) {
|
||||||
@@ -220,7 +256,6 @@ inbox.delete = async (req) => {
|
|||||||
// db.isSortedSetMember('usersRemote:lastCrawled', object.id),
|
// db.isSortedSetMember('usersRemote:lastCrawled', object.id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
console.log(isNote, isContext);
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case isNote: {
|
case isNote: {
|
||||||
const cid = await posts.getCidByPid(id);
|
const cid = await posts.getCidByPid(id);
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ activitypubApi.remove.context = enabledCheck(async ({ uid }, { tid }) => {
|
|||||||
}, { cid });
|
}, { cid });
|
||||||
|
|
||||||
// Remove(Context)
|
// Remove(Context)
|
||||||
await activitypub.send('cid', cid, Array.from(targets), {
|
await activitypub.send('uid', uid, Array.from(targets), {
|
||||||
id: `${nconf.get('url')}/topic/${tid}#activity/remove/${now.getTime()}`,
|
id: `${nconf.get('url')}/topic/${tid}#activity/remove/${now.getTime()}`,
|
||||||
type: 'Remove',
|
type: 'Remove',
|
||||||
actor: `${nconf.get('url')}/uid/${uid}`,
|
actor: `${nconf.get('url')}/uid/${uid}`,
|
||||||
|
|||||||
@@ -322,11 +322,11 @@ topicsAPI.move = async (caller, { tid, cid }) => {
|
|||||||
socketHelpers.sendNotificationToTopicOwner(tid, caller.uid, 'move', 'notifications:moved-your-topic');
|
socketHelpers.sendNotificationToTopicOwner(tid, caller.uid, 'move', 'notifications:moved-your-topic');
|
||||||
|
|
||||||
if (cid === -1) {
|
if (cid === -1) {
|
||||||
// tbd: activitypubApi.move (to null target)
|
activitypubApi.remove.context(caller, { tid });
|
||||||
// tbd: activitypubApi.undo.announce?
|
// tbd: activitypubApi.undo.announce?
|
||||||
} else {
|
} else {
|
||||||
|
// tbd: activitypubApi.move
|
||||||
activitypubApi.announce.category(caller, { tid });
|
activitypubApi.announce.category(caller, { tid });
|
||||||
// tbd: api.activitypub.move
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user