feat: handle Announce(Update(Note)) as well, #13320

This commit is contained in:
Julian Lam
2025-04-23 13:17:10 -04:00
parent 74e32a170f
commit 044736696e
3 changed files with 46 additions and 1 deletions

View File

@@ -286,6 +286,12 @@ inbox.announce = async (req) => {
break;
}
case object.type === 'Update': {
req.body = object;
await inbox.update(req);
break;
}
case activitypub._constants.acceptedPostTypes.includes(object.type): {
if (String(object.id).startsWith(nconf.get('url'))) { // Local object
const { type, id } = await activitypub.helpers.resolveLocalId(object.id);

View File

@@ -176,3 +176,26 @@ Helpers.mocks.announce = (override = {}) => {
return { activity };
};
Helpers.mocks.update = (override = {}) => {
let actor = override.actor;
let object = override.object;
if (!actor) {
({ id: actor } = Helpers.mocks.person());
}
if (!object) {
({ id: object } = Helpers.mocks.note());
}
const activity = {
'@context': 'https://www.w3.org/ns/activitystreams',
id: `${Helpers.mocks._baseUrl}/update/${encodeURIComponent(object.id || object)}`,
type: 'Update',
to: [activitypub._constants.publicAddress],
cc: [`${actor}/followers`],
actor,
object,
};
return { activity };
};

View File

@@ -411,7 +411,7 @@ describe('Notes', () => {
});
});
describe.only('Inbox handling', () => {
describe('Inbox handling', () => {
describe('helper self-check', () => {
it('should generate a Like activity', () => {
const object = utils.generateUUID();
@@ -544,6 +544,22 @@ describe('Notes', () => {
assert.strictEqual(upvotes, 1);
});
});
describe('(Update)', () => {
it('should update a note\'s content', async () => {
const { id: actor } = helpers.mocks.person();
const { id, note } = helpers.mocks.note({ attributedTo: actor });
await activitypub.notes.assert(0, [id], { skipChecks: true });
note.content = utils.generateUUID();
const { activity: update } = helpers.mocks.update({ object: note });
const { activity } = helpers.mocks.announce({ object: update });
await activitypub.inbox.announce({ body: activity });
const content = await posts.getPostField(id, 'content');
assert.strictEqual(content, note.content);
});
});
});
});