If Follow (Match-Try) is rejected, do not permit more matches until the other "unblocks"

This commit is contained in:
Niko 2022-02-15 23:46:55 +01:00
parent 458f7c28fa
commit 0c0729b24e
2 changed files with 22 additions and 2 deletions

View File

@ -1,9 +1,18 @@
module.exports = { 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('INBOX')
console.log(msg) console.log(msg)
}, },
outbox: (msg) => { outbox: async (msg) => {
console.log('OUTBOX') console.log('OUTBOX')
console.log(msg) console.log(msg)
}, },

View File

@ -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 = { module.exports = {
follow: { follow: {
post: [auth.enforceSession, async (req, res) => { post: [auth.enforceSession, async (req, res) => {
@ -20,6 +28,9 @@ module.exports = {
if (follow !== null) if (follow !== null)
return res.json({ error: 'already_following' }) return res.json({ error: 'already_following' })
if (await isFollowRejected(req, res))
return res.json({ error: 'follow_rejected' })
const actor = await apex.store.getObject( const actor = await apex.store.getObject(
apID(res.locals.user.username), true) apID(res.locals.user.username), true)
const payload = { const payload = {