mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: simplify remote (un)follow controller
This commit is contained in:
@@ -16,7 +16,7 @@ const user = require('../user');
|
||||
|
||||
const activitypubApi = module.exports;
|
||||
|
||||
activitypubApi.follow = async (caller, { actorId } = {}) => {
|
||||
activitypubApi.follow = async (caller, { uid: actorId } = {}) => {
|
||||
const object = await activitypub.getActor(caller.uid, actorId);
|
||||
if (!object) {
|
||||
throw new Error('[[error:activitypub.invalid-id]]');
|
||||
@@ -28,7 +28,7 @@ activitypubApi.follow = async (caller, { actorId } = {}) => {
|
||||
});
|
||||
};
|
||||
|
||||
activitypubApi.unfollow = async (caller, { actorId }) => {
|
||||
activitypubApi.unfollow = async (caller, { uid: actorId }) => {
|
||||
const object = await activitypub.getActor(caller.uid, actorId);
|
||||
const userslug = await user.getUserField(caller.uid, 'userslug');
|
||||
if (!object) {
|
||||
|
||||
@@ -105,17 +105,3 @@ Controller.postInbox = async (req, res) => {
|
||||
|
||||
res.sendStatus(201);
|
||||
};
|
||||
|
||||
/**
|
||||
* Main ActivityPub verbs
|
||||
*/
|
||||
|
||||
Controller.follow = async (req, res) => {
|
||||
const { uid: actorId } = req.params;
|
||||
helpers.formatApiResponse(200, res, await api.activitypub.follow(req, { actorId }));
|
||||
};
|
||||
|
||||
Controller.unfollow = async (req, res) => {
|
||||
const { uid: actorId } = req.params;
|
||||
helpers.formatApiResponse(200, res, await api.activitypub.unfollow(req, { actorId }));
|
||||
};
|
||||
|
||||
@@ -94,20 +94,16 @@ Users.changePassword = async (req, res) => {
|
||||
};
|
||||
|
||||
Users.follow = async (req, res) => {
|
||||
if (req.params.uid.indexOf('@') !== -1) {
|
||||
return await activitypubController.follow(req, res);
|
||||
}
|
||||
|
||||
await api.users.follow(req, req.params);
|
||||
const remote = String(req.params.uid).includes('@');
|
||||
const controller = remote ? api.activitypub.follow : api.users.follow;
|
||||
await controller(req, req.params);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Users.unfollow = async (req, res) => {
|
||||
if (req.params.uid.indexOf('@') !== -1) {
|
||||
return await activitypubController.unfollow(req, res);
|
||||
}
|
||||
|
||||
await api.users.unfollow(req, req.params);
|
||||
const remote = String(req.params.uid).includes('@');
|
||||
const controller = remote ? api.activitypub.unfollow : api.users.unfollow;
|
||||
await controller(req, req.params);
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user