mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: handle Announce(Update(Note)) as well, #13320
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user