Wrap getAPObject to match given type + refactor
This commit is contained in:
parent
c8bba73b99
commit
c7d8a075b9
|
@ -27,22 +27,23 @@ 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
|
||||
}
|
||||
}
|
||||
if (msg.activity.type === 'Block')
|
||||
{
|
||||
if (areActorsValid(msg.activity.object, true))
|
||||
|
|
|
@ -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
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue