diff --git a/features/outbox.feature b/features/outbox.feature new file mode 100644 index 00000000..7c7d9689 --- /dev/null +++ b/features/outbox.feature @@ -0,0 +1,14 @@ +Feature: Outbox + In order to view the activities performed by an actor + As a fediverse server + I want be able to retrieve an actor's activities from their outbox + + Scenario: outbox contains relevant activities + Given an Actor "Alice" + And a "Create(Article)" Activity "C" by "Alice" + And a "Announce(C)" Activity "An" by "Alice" + And a "Follow(Us)" Activity "F" by "Alice" + And a "Accept(F)" Activity "A" by "Alice" + When the contents of the outbox is requested + Then the outbox contains 1 activity + And a "Create(Article)" activity is in the Outbox diff --git a/features/step_definitions/stepdefs.js b/features/step_definitions/stepdefs.js index 9904a9f5..c300da9d 100644 --- a/features/step_definitions/stepdefs.js +++ b/features/step_definitions/stepdefs.js @@ -46,6 +46,20 @@ async function createActivity(activityType, object, actor, remote = true) { actor: actor, }; } + + if (activityType === 'Announce') { + return { + '@context': [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/data-integrity/v1', + ], + 'type': 'Announce', + 'id': 'http://wiremock:8080/announce/1', + 'to': 'as:Public', + 'object': object, + actor: actor, + }; + } } async function createActor(name = 'Test', remote = true) { @@ -332,3 +346,17 @@ Then('{string} is in our Followers once only', async function (actorName) { assert.equal(found.length, 1); }); + +When('the contents of the outbox is requested', async function () { + const response = await fetch('http://activitypub-testing:8083/.ghost/activitypub/outbox/index', { + headers: { + 'Content-Type': 'application/ld+json' + }, + }); + + this.response = await response.json(); +}); + +Then('the outbox contains {int} activity', function (count) { + assert.equal(this.response.totalItems, count); +}); diff --git a/src/dispatchers.ts b/src/dispatchers.ts index b49a220b..f78fedc5 100644 --- a/src/dispatchers.ts +++ b/src/dispatchers.ts @@ -334,13 +334,19 @@ export async function followingCounter( return results.length; } +function filterOutboxActivityUris (activityUris: string[]) { + // Only return Create and Announce activityUris + return activityUris.filter(uri => /(create|announce)/.test(uri)); +} + export async function outboxDispatcher( ctx: RequestContext, handle: string, ) { console.log('Outbox Dispatcher'); - const results = (await ctx.data.db.get(['outbox'])) || []; + const results = filterOutboxActivityUris((await ctx.data.db.get(['outbox'])) || []); console.log(results); + let items: Activity[] = []; for (const result of results) { try { @@ -361,7 +367,8 @@ export async function outboxCounter( handle: string, ) { const results = (await ctx.data.db.get(['outbox'])) || []; - return results.length; + + return filterOutboxActivityUris(results).length; } export async function articleDispatcher(