Support "Block" operations on ActivityPub
* TODO: inhibit interactions on our side from a blocked Actor
This commit is contained in:
parent
27ac14da3d
commit
98a4449de4
|
@ -1,4 +1,27 @@
|
||||||
|
async function areActorsValid(actors, ourDomain) {
|
||||||
|
if (!actors instanceof Array && typeof actors !== 'string') {
|
||||||
|
console.error('Unexpected type of "actors" in "federation.doesActorsExistAndOurs"')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (typeof actors === 'string') actors = [actors]
|
||||||
|
for (var i = 0; i < actors.length; i++) {
|
||||||
|
let url
|
||||||
|
try { url = new URL(actors[i]) }
|
||||||
|
catch (e) { return false }
|
||||||
|
if (ourDomain && url.hostname !== apex.domain)
|
||||||
|
return false
|
||||||
|
|
||||||
|
actors[i] = url.href
|
||||||
|
const actor = await apex.store.getObject(actors[i])
|
||||||
|
// TODO: check account is deleted/disabled/banned/...?
|
||||||
|
if (actor === null || actor.type !== 'Person')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
areActorsValid,
|
||||||
inbox: async (msg) => {
|
inbox: async (msg) => {
|
||||||
// TODO: add logging for every matches params
|
// TODO: add logging for every matches params
|
||||||
if (msg.activity.type === 'Reject' && msg.object.type === 'Follow')
|
if (msg.activity.type === 'Reject' && msg.object.type === 'Follow')
|
||||||
|
@ -8,14 +31,20 @@ module.exports = {
|
||||||
follow.rejected = true
|
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
|
||||||
|
}
|
||||||
|
if (msg.activity.type === 'Block')
|
||||||
|
{
|
||||||
|
if (areActorsValid(msg.activity.object, true))
|
||||||
|
await apex.store.saveObject(msg.activity)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
if (msg.activity.type === 'Undo')
|
if (msg.activity.type === 'Undo')
|
||||||
{
|
{
|
||||||
if (msg.object.type === 'Block') {
|
if (msg.object.type === 'Block') {
|
||||||
await db.table.objects().deleteOne(
|
await db.table.objects().deleteOne(
|
||||||
{ id: msg.object.id, type: 'Block' })
|
{ id: msg.object.id, type: 'Block' })
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue