mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: use one internal rejection method
This commit is contained in:
@@ -17,6 +17,17 @@ const helpers = require('./helpers');
|
|||||||
|
|
||||||
const inbox = module.exports;
|
const inbox = module.exports;
|
||||||
|
|
||||||
|
function reject(type, object, target, senderType = 'uid', id = 0) {
|
||||||
|
activitypub.send(senderType, id, target, {
|
||||||
|
type: 'Reject',
|
||||||
|
object: {
|
||||||
|
type,
|
||||||
|
target,
|
||||||
|
object,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
inbox.create = async (req) => {
|
inbox.create = async (req) => {
|
||||||
const { object } = req.body;
|
const { object } = req.body;
|
||||||
|
|
||||||
@@ -50,14 +61,7 @@ inbox.update = async (req) => {
|
|||||||
await activitypub.notes.assert(0, object.id);
|
await activitypub.notes.assert(0, object.id);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
activitypub.send('uid', 0, actor, {
|
reject('Update', object, actor);
|
||||||
type: 'Reject',
|
|
||||||
object: {
|
|
||||||
type: 'Update',
|
|
||||||
actor,
|
|
||||||
object,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -72,25 +76,15 @@ inbox.update = async (req) => {
|
|||||||
inbox.like = async (req) => {
|
inbox.like = async (req) => {
|
||||||
const { actor, object } = req.body;
|
const { actor, object } = req.body;
|
||||||
const { type, id } = await activitypub.helpers.resolveLocalId(object);
|
const { type, id } = await activitypub.helpers.resolveLocalId(object);
|
||||||
const reject = () => {
|
|
||||||
activitypub.send('uid', 0, actor, {
|
|
||||||
type: 'Reject',
|
|
||||||
object: {
|
|
||||||
type: 'Like',
|
|
||||||
actor,
|
|
||||||
object,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (type !== 'post' || !(await posts.exists(id))) {
|
if (type !== 'post' || !(await posts.exists(id))) {
|
||||||
return reject();
|
return reject('Like', object, actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
const allowed = await privileges.posts.can('posts:upvote', id, activitypub._constants.uid);
|
const allowed = await privileges.posts.can('posts:upvote', id, activitypub._constants.uid);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
winston.info(`[activitypub/inbox.like] ${id} not allowed to be upvoted.`);
|
winston.info(`[activitypub/inbox.like] ${id} not allowed to be upvoted.`);
|
||||||
return reject();
|
return reject('Like', object, actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
winston.info(`[activitypub/inbox/like] id ${id} via ${actor}`);
|
winston.info(`[activitypub/inbox/like] id ${id} via ${actor}`);
|
||||||
@@ -208,14 +202,7 @@ inbox.follow = async (req) => {
|
|||||||
throw new Error('[[error:invalid-cid]]');
|
throw new Error('[[error:invalid-cid]]');
|
||||||
}
|
}
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
return activitypub.send('uid', 0, actor, {
|
return reject('Follow', object, actor);
|
||||||
type: 'Reject',
|
|
||||||
object: {
|
|
||||||
type: 'Follow',
|
|
||||||
actor,
|
|
||||||
object,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const watchState = await categories.getWatchState([id], actor);
|
const watchState = await categories.getWatchState([id], actor);
|
||||||
@@ -321,14 +308,7 @@ inbox.undo = async (req) => {
|
|||||||
const allowed = await privileges.posts.can('posts:upvote', id, activitypub._constants.uid);
|
const allowed = await privileges.posts.can('posts:upvote', id, activitypub._constants.uid);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
winston.info(`[activitypub/inbox.like] ${id} not allowed to be upvoted.`);
|
winston.info(`[activitypub/inbox.like] ${id} not allowed to be upvoted.`);
|
||||||
activitypub.send('uid', 0, actor, {
|
reject('Like', object, actor);
|
||||||
type: 'Reject',
|
|
||||||
object: {
|
|
||||||
type: 'Like',
|
|
||||||
actor,
|
|
||||||
object,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user