Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mike182uk committed Aug 21, 2024
1 parent a9d248d commit 33f1c03
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
13 changes: 13 additions & 0 deletions features/outbox.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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 "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
14 changes: 14 additions & 0 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,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);
});
12 changes: 9 additions & 3 deletions src/dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,18 @@ 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<ContextData>,
handle: string,
) {
console.log('Outbox Dispatcher');
const results = (await ctx.data.db.get<string[]>(['outbox'])) || [];
console.log(results);
const results = filterOutboxActivities((await ctx.data.db.get<string[]>(['outbox'])) || []);

let items: Activity[] = [];
for (const result of results) {
try {
Expand All @@ -361,7 +366,8 @@ export async function outboxCounter(
handle: string,
) {
const results = (await ctx.data.db.get<string[]>(['outbox'])) || [];
return results.length;

return filterOutboxActivities(results).length;
}

export async function articleDispatcher(
Expand Down

0 comments on commit 33f1c03

Please sign in to comment.