2023-12-08 10:55:16 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DEVELOPMENT NOTE
|
|
|
|
|
*
|
|
|
|
|
* THIS FILE IS UNDER ACTIVE DEVELOPMENT AND IS EXPLICITLY EXCLUDED FROM IMMUTABILITY GUARANTEES
|
|
|
|
|
*
|
|
|
|
|
* If you use api methods in this file, be prepared that they may be removed or modified with no warning.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-12-22 15:53:04 -05:00
|
|
|
const nconf = require('nconf');
|
|
|
|
|
|
2023-12-08 10:55:16 -05:00
|
|
|
const db = require('../database');
|
|
|
|
|
const activitypub = require('../activitypub');
|
2023-12-22 15:53:04 -05:00
|
|
|
const user = require('../user');
|
2023-12-08 10:55:16 -05:00
|
|
|
|
|
|
|
|
const activitypubApi = module.exports;
|
|
|
|
|
|
|
|
|
|
activitypubApi.follow = async (caller, { actorId } = {}) => {
|
2024-01-05 22:45:33 -05:00
|
|
|
const object = await activitypub.getActor(caller.uid, actorId);
|
2023-12-22 13:56:18 -05:00
|
|
|
if (!object) {
|
2024-01-08 14:30:09 -05:00
|
|
|
throw new Error('[[error:activitypub.invalid-id]]');
|
2023-12-08 10:55:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await activitypub.send(caller.uid, actorId, {
|
|
|
|
|
type: 'Follow',
|
2023-12-22 15:53:04 -05:00
|
|
|
object: object.id,
|
2023-12-08 10:55:16 -05:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
activitypubApi.unfollow = async (caller, { actorId }) => {
|
2024-01-05 22:45:33 -05:00
|
|
|
const object = await activitypub.getActor(caller.uid, actorId);
|
2023-12-22 15:53:04 -05:00
|
|
|
const userslug = await user.getUserField(caller.uid, 'userslug');
|
|
|
|
|
if (!object) {
|
2024-01-08 14:30:09 -05:00
|
|
|
throw new Error('[[error:activitypub.invalid-id]]');
|
2023-12-08 10:55:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await activitypub.send(caller.uid, actorId, {
|
2023-12-22 15:53:04 -05:00
|
|
|
type: 'Undo',
|
2023-12-08 10:55:16 -05:00
|
|
|
object: {
|
2023-12-22 15:53:04 -05:00
|
|
|
type: 'Follow',
|
|
|
|
|
actor: `${nconf.get('url')}/user/${userslug}`,
|
|
|
|
|
object: object.id,
|
2023-12-08 10:55:16 -05:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await Promise.all([
|
2024-01-03 13:54:17 -05:00
|
|
|
db.sortedSetRemove(`followingRemote:${caller.uid}`, object.id),
|
2023-12-08 10:55:16 -05:00
|
|
|
db.decrObjectField(`user:${caller.uid}`, 'followingRemoteCount'),
|
|
|
|
|
]);
|
|
|
|
|
};
|