Skip to content

Commit

Permalink
allow undo of block via actorId, like how unfollow works
Browse files Browse the repository at this point in the history
  • Loading branch information
wmurphyrd committed Jun 23, 2022
1 parent e216c90 commit a62d14d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
17 changes: 12 additions & 5 deletions net/validators.js
Expand Up @@ -323,18 +323,25 @@ function outboxActivityObject (req, res, next) {
}
Promise.resolve(object).then(async obj => {
resLocal.object = obj
// for unfollow, clients dont have easy access to old follow activitiy ids,
// so they can send an actor id and server will find related follow
if (!obj && type === 'undo') {
const actorId = apex.objectIdFromActivity(activity)
// for unfollow/unblock, clients dont have easy access to old activitiy ids,
// so they can send an actor id and server will find related follow/block
const actorId = apex.objectIdFromActivity(activity)
if (!obj && type === 'undo' && resLocal.target._local.blockList.includes(actorId)) {
const blockedCollection = apex.utils.nameToBlockedIRI(resLocal.target.preferredUsername)
const block = await apex.store
.findActivityByCollectionAndObjectId(blockedCollection, actorId, true)
if (block) {
activity.object = [block]
resLocal.object = block
}
} else if (!obj && type === 'undo') {
const follow = await apex.store
.findActivityByCollectionAndObjectId(resLocal.target.following[0], actorId, true)
if (follow) {
activity.object = [follow]
resLocal.object = follow
}
} else if (!obj && type === 'reject') {
const actorId = apex.objectIdFromActivity(activity)
const follow = await apex.store
.findActivityByCollectionAndActorId(resLocal.target.followers[0], actorId, true)
if (follow) {
Expand Down
28 changes: 28 additions & 0 deletions spec/functional/outbox.spec.js
Expand Up @@ -387,6 +387,34 @@ describe('outbox', function () {
.expect(201)
.end(err => { if (err) done(err) })
})
it('unblocks if object is blocked actor', async function (done) {
const mockedUser = 'https://mocked.com/user/mocked'
undone.type = 'Block'
undone.object = [mockedUser]
apex.addMeta(undone, 'collection', apex.utils.nameToBlockedIRI(testUser.preferredUsername))
undone.to = [mockedUser]
await apex.store.saveActivity(undone)
expect((await apex.getBlocked(testUser, Infinity, true)).orderedItems)
.toEqual([mockedUser])
undo = {
type: 'Undo',
actor: testUser.id,
object: mockedUser,
to: mockedUser
}
app.once('apex-outbox', async () => {
// blocklist updated
expect((await apex.getBlocked(testUser, Infinity, true)).orderedItems)
.toEqual([])
done()
})
request(app)
.post('/authorized/outbox/test')
.set('Content-Type', 'application/activity+json')
.send(undo)
.expect(201)
.end(err => { if (err) done(err) })
})
})
describe('update', function () {
let sourceObj
Expand Down
2 changes: 2 additions & 0 deletions spec/helpers/jasmine.js
@@ -0,0 +1,2 @@
/* global jasmine */
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000

0 comments on commit a62d14d

Please sign in to comment.