From 1a2587be4c7a1486c29d4128554b99abf8d0bea4 Mon Sep 17 00:00:00 2001 From: Michael Barrett Date: Wed, 21 Aug 2024 14:13:45 +0100 Subject: [PATCH] wip --- features/outbox.feature | 14 ++++++++++++++ features/step_definitions/stepdefs.js | 28 +++++++++++++++++++++++++++ src/dispatchers.ts | 11 +++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 features/outbox.feature 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..2a9d8cb5 100644 --- a/src/dispatchers.ts +++ b/src/dispatchers.ts @@ -334,13 +334,19 @@ export async function followingCounter( return results.length; } +function filterOutboxActivities (activities: string[]) { + // Only return Create and Announce activities + return activities.filter(activity => /(create|announce)/.test(activity)); +} + export async function outboxDispatcher( ctx: RequestContext, handle: string, ) { console.log('Outbox Dispatcher'); - const results = (await ctx.data.db.get(['outbox'])) || []; + const results = filterOutboxActivities((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 filterOutboxActivities(results).length; } export async function articleDispatcher(