diff --git a/api/src/activity/federation.js b/api/src/activity/federation.js index 3fc5080..f50a0ac 100644 --- a/api/src/activity/federation.js +++ b/api/src/activity/federation.js @@ -27,21 +27,22 @@ module.exports = { if (msg.activity.type === 'Accept') { if (msg.object.type === 'Follow') { - const follow = await db.table.objects().findOne({ id: msg.object.id }) - if (follow !== null && follow.type === 'Follow') + const follow = await db.getAPObject(msg.object.id, 'Follow') + if (follow !== null) await db.table.objects().updateOne({ _id: follow._id }, { $set: { accepted: true } }) return true } } - if (msg.activity.type === 'Reject' && msg.object.type === 'Follow') + if (msg.activity.type === 'Reject') { - const follow = await db.table.objects().findOne({ id: msg.object.id }) - if (follow !== null) { - follow.rejected = true - await db.table.objects().replaceOne({ _id: follow._id }, follow) + if (msg.object.type === 'Follow') { + const follow = await db.getAPObject(msg.object.id, 'Follow') + if (follow !== null) + await db.table.objects().updateOne({ _id: follow._id }, + { $set: { rejected: true } }) + return true } - return true } if (msg.activity.type === 'Block') { diff --git a/api/src/db.js b/api/src/db.js index b94bcf1..c752f10 100644 --- a/api/src/db.js +++ b/api/src/db.js @@ -22,4 +22,14 @@ module.exports = { users: () => { return mdb.collection('u__users') }, sessions: () => { return mdb.collection('u__sessions') }, }, + getAPObject: async (objID, checkType) => { + const object = await module.exports.table + .objects().findOne({ id: objID }) + if (object === null) + return null + if (checkType !== undefined && + object.type !== checkType) + return null + return object + }, }