From 0c0729b24e93deb35cc1bd695d712cc27439877e Mon Sep 17 00:00:00 2001 From: Niko Date: Tue, 15 Feb 2022 23:46:55 +0100 Subject: [PATCH] If Follow (Match-Try) is rejected, do not permit more matches until the other "unblocks" --- api/src/activity/federation.js | 13 +++++++++++-- api/src/api/accounts.js | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/src/activity/federation.js b/api/src/activity/federation.js index e69223a..89559b9 100644 --- a/api/src/activity/federation.js +++ b/api/src/activity/federation.js @@ -1,9 +1,18 @@ module.exports = { - inbox: (msg) => { + inbox: async (msg) => { + // TODO: add logging for every matches params + if (msg.activity.type === 'Reject' && msg.object.type === 'Follow') + { + const follow = await db.table.objects().findOne({ id: msg.object.id }) + follow.type = 'Follow-Rejected' + await db.table.objects().replaceOne({ _id: follow._id }, follow) + return true; + } + console.log('INBOX') console.log(msg) }, - outbox: (msg) => { + outbox: async (msg) => { console.log('OUTBOX') console.log(msg) }, diff --git a/api/src/api/accounts.js b/api/src/api/accounts.js index 0cdd353..de6d649 100644 --- a/api/src/api/accounts.js +++ b/api/src/api/accounts.js @@ -10,6 +10,14 @@ async function getFollow(req, res) { }) } +async function isFollowRejected(req, res) { + return await db.table.objects().findOne({ + actor: apID(res.locals.user.username), + to: req.query.url, + type: 'Follow-Rejected', + }) !== null +} + module.exports = { follow: { post: [auth.enforceSession, async (req, res) => { @@ -20,6 +28,9 @@ module.exports = { if (follow !== null) return res.json({ error: 'already_following' }) + if (await isFollowRejected(req, res)) + return res.json({ error: 'follow_rejected' }) + const actor = await apex.store.getObject( apID(res.locals.user.username), true) const payload = {