Allow user to Follow (Match) a person to a maximum of 3 times being rejected
* TODO: add a block method for a single-time "reject" that eliminates any relationship between parties
This commit is contained in:
parent
0c0729b24e
commit
56f46070fe
|
@ -4,8 +4,10 @@ module.exports = {
|
||||||
if (msg.activity.type === 'Reject' && msg.object.type === 'Follow')
|
if (msg.activity.type === 'Reject' && msg.object.type === 'Follow')
|
||||||
{
|
{
|
||||||
const follow = await db.table.objects().findOne({ id: msg.object.id })
|
const follow = await db.table.objects().findOne({ id: msg.object.id })
|
||||||
follow.type = 'Follow-Rejected'
|
if (follow !== null) {
|
||||||
|
follow.rejected = true
|
||||||
await db.table.objects().replaceOne({ _id: follow._id }, follow)
|
await db.table.objects().replaceOne({ _id: follow._id }, follow)
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,20 +2,27 @@ const crypto = require('crypto')
|
||||||
const auth = require('../auth.js')
|
const auth = require('../auth.js')
|
||||||
const utils = require('../api-utils.js')
|
const utils = require('../api-utils.js')
|
||||||
|
|
||||||
async function getFollow(req, res) {
|
const REJECT_TIMES_MAX = 3
|
||||||
|
|
||||||
|
async function getValidFollow(req, res) {
|
||||||
return await db.table.objects().findOne({
|
return await db.table.objects().findOne({
|
||||||
actor: apID(res.locals.user.username),
|
actor: apID(res.locals.user.username),
|
||||||
to: req.query.url,
|
to: req.query.url,
|
||||||
type: 'Follow',
|
type: 'Follow',
|
||||||
|
rejected: undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isFollowRejected(req, res) {
|
async function getRejectedTimes(req, res) {
|
||||||
return await db.table.objects().findOne({
|
var times = 0
|
||||||
|
const follows = await db.table.objects().find({
|
||||||
actor: apID(res.locals.user.username),
|
actor: apID(res.locals.user.username),
|
||||||
to: req.query.url,
|
to: req.query.url,
|
||||||
type: 'Follow-Rejected',
|
type: 'Follow',
|
||||||
}) !== null
|
rejected: true,
|
||||||
|
})
|
||||||
|
await follows.forEach(() => { times++ })
|
||||||
|
return times
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -24,12 +31,11 @@ module.exports = {
|
||||||
if (!utils.isURLValid(req.query.url))
|
if (!utils.isURLValid(req.query.url))
|
||||||
return res.json({ error: 'invalid_url' })
|
return res.json({ error: 'invalid_url' })
|
||||||
|
|
||||||
const follow = await getFollow(req, res)
|
if (await getRejectedTimes(req, res) >= REJECT_TIMES_MAX)
|
||||||
if (follow !== null)
|
return res.json({ error: 'follow_rejected_max' })
|
||||||
return res.json({ error: 'already_following' })
|
|
||||||
|
|
||||||
if (await isFollowRejected(req, res))
|
if (await getValidFollow(req, res) !== null)
|
||||||
return res.json({ error: 'follow_rejected' })
|
return res.json({ error: 'follow_already_requested' })
|
||||||
|
|
||||||
const actor = await apex.store.getObject(
|
const actor = await apex.store.getObject(
|
||||||
apID(res.locals.user.username), true)
|
apID(res.locals.user.username), true)
|
||||||
|
@ -50,7 +56,7 @@ module.exports = {
|
||||||
if (!utils.isURLValid(req.query.url))
|
if (!utils.isURLValid(req.query.url))
|
||||||
return res.json({ error: 'invalid_url' })
|
return res.json({ error: 'invalid_url' })
|
||||||
|
|
||||||
const follow = await getFollow(req, res)
|
const follow = await getValidFollow(req, res)
|
||||||
if (follow === null)
|
if (follow === null)
|
||||||
return res.json({ error: 'no_following' })
|
return res.json({ error: 'no_following' })
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue