mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +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;
|
const activitypubApi = module.exports;
|
||||||
|
|
||||||
activitypubApi.follow = async (caller, { actorId } = {}) => {
|
activitypubApi.follow = async (caller, { uid: actorId } = {}) => {
|
||||||
const object = await activitypub.getActor(caller.uid, actorId);
|
const object = await activitypub.getActor(caller.uid, actorId);
|
||||||
if (!object) {
|
if (!object) {
|
||||||
throw new Error('[[error:activitypub.invalid-id]]');
|
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 object = await activitypub.getActor(caller.uid, actorId);
|
||||||
const userslug = await user.getUserField(caller.uid, 'userslug');
|
const userslug = await user.getUserField(caller.uid, 'userslug');
|
||||||
if (!object) {
|
if (!object) {
|
||||||
|
|||||||
@@ -105,17 +105,3 @@ Controller.postInbox = async (req, res) => {
|
|||||||
|
|
||||||
res.sendStatus(201);
|
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) => {
|
Users.follow = async (req, res) => {
|
||||||
if (req.params.uid.indexOf('@') !== -1) {
|
const remote = String(req.params.uid).includes('@');
|
||||||
return await activitypubController.follow(req, res);
|
const controller = remote ? api.activitypub.follow : api.users.follow;
|
||||||
}
|
await controller(req, req.params);
|
||||||
|
|
||||||
await api.users.follow(req, req.params);
|
|
||||||
helpers.formatApiResponse(200, res);
|
helpers.formatApiResponse(200, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
Users.unfollow = async (req, res) => {
|
Users.unfollow = async (req, res) => {
|
||||||
if (req.params.uid.indexOf('@') !== -1) {
|
const remote = String(req.params.uid).includes('@');
|
||||||
return await activitypubController.unfollow(req, res);
|
const controller = remote ? api.activitypub.unfollow : api.users.unfollow;
|
||||||
}
|
await controller(req, req.params);
|
||||||
|
|
||||||
await api.users.unfollow(req, req.params);
|
|
||||||
helpers.formatApiResponse(200, res);
|
helpers.formatApiResponse(200, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user