Wrap getAPObject to match given type + refactor

This commit is contained in:
Niko 2022-02-16 14:17:22 +01:00
parent c8bba73b99
commit c7d8a075b9
2 changed files with 19 additions and 8 deletions

View File

@ -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')
{

View File

@ -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
},
}