mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: accept and undo logic saving improper id into database, updated follow logic so remote follow is not added to collection until an accept is received
This commit is contained in:
@@ -48,9 +48,11 @@ inbox.isFollowed = async (actorId, uid) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inbox.accept = async (req) => {
|
inbox.accept = async (req) => {
|
||||||
const { actor, object } = req.body;
|
let { actor, object } = req.body;
|
||||||
const { type } = object;
|
const { type } = object;
|
||||||
|
|
||||||
|
actor = await activitypub.getActor(actor);
|
||||||
|
|
||||||
if (type === 'Follow') {
|
if (type === 'Follow') {
|
||||||
// todo: should check that actor and object.actor are the same person?
|
// todo: should check that actor and object.actor are the same person?
|
||||||
const uid = await helpers.resolveLocalUid(object.actor);
|
const uid = await helpers.resolveLocalUid(object.actor);
|
||||||
@@ -60,25 +62,27 @@ inbox.accept = async (req) => {
|
|||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetAdd(`followingRemote:${uid}`, now, actor.name),
|
db.sortedSetAdd(`followingRemote:${uid}`, now, actor.id),
|
||||||
db.incrObjectField(`user:${uid}`, 'followingRemoteCount'),
|
db.incrObjectField(`user:${uid}`, 'followingRemoteCount'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inbox.undo = async (req) => {
|
inbox.undo = async (req) => {
|
||||||
const { actor, object } = req.body;
|
let { actor, object } = req.body;
|
||||||
const { type } = object;
|
const { type } = object;
|
||||||
|
|
||||||
|
actor = await activitypub.getActor(actor);
|
||||||
|
|
||||||
if (type === 'Follow') {
|
if (type === 'Follow') {
|
||||||
// todo: should check that actor and object.actor are the same person?
|
// todo: should check that actor and object.actor are the same person?
|
||||||
const uid = await helpers.resolveLocalUid(object.actor);
|
const uid = await helpers.resolveLocalUid(object.object);
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
throw new Error('[[error:invalid-uid]]');
|
throw new Error('[[error:invalid-uid]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetRemove(`followingRemote:${uid}`, actor.name),
|
db.sortedSetRemove(`followingRemote:${uid}`, actor.id),
|
||||||
db.decrObjectField(`user:${uid}`, 'followingRemoteCount'),
|
db.decrObjectField(`user:${uid}`, 'followingRemoteCount'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ activitypubApi.follow = async (caller, { actorId } = {}) => {
|
|||||||
type: 'Follow',
|
type: 'Follow',
|
||||||
object: object.id,
|
object: object.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const now = Date.now();
|
|
||||||
await Promise.all([
|
|
||||||
db.sortedSetAdd(`followingRemote:${caller.uid}`, now, actorId),
|
|
||||||
db.incrObjectField(`user:${caller.uid}`, 'followingRemoteCount'),
|
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
activitypubApi.unfollow = async (caller, { actorId }) => {
|
activitypubApi.unfollow = async (caller, { actorId }) => {
|
||||||
@@ -51,7 +45,7 @@ activitypubApi.unfollow = async (caller, { actorId }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
db.sortedSetRemove(`followingRemote:${caller.uid}`, actorId),
|
db.sortedSetRemove(`followingRemote:${caller.uid}`, object.id),
|
||||||
db.decrObjectField(`user:${caller.uid}`, 'followingRemoteCount'),
|
db.decrObjectField(`user:${caller.uid}`, 'followingRemoteCount'),
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user