feat: 1b12 category announce on post move to a new tid, #13236

This commit is contained in:
Julian Lam
2025-03-11 15:06:01 -04:00
parent d7116adcd3
commit 254f0738bb
2 changed files with 31 additions and 24 deletions

View File

@@ -321,6 +321,10 @@ postsAPI.move = async function (caller, data) {
if (!postDeleted && !topicDeleted) {
socketHelpers.sendNotificationToPostOwner(data.pid, caller.uid, 'move', 'notifications:moved-your-post');
// ideally we should federate a "move" activity instead. tbd
const { activity } = await activitypub.mocks.activities.create(data.pid, caller.uid);
await activitypub.feps.announce(data.pid, activity);
}
};

View File

@@ -97,34 +97,37 @@ describe('FEPs', () => {
assert.strictEqual(activity.object.id, `${nconf.get('url')}/post/${reply1Pid}`);
});
// it('should be called when a post is moved to another topic', async () => {
//
// });
});
it('should be called when a post is moved to another topic', async () => {
const [{ topicData: topic1 }, { topicData: topic2 }] = await Promise.all([
topics.post({
uid,
cid,
title: utils.generateUUID(),
content: utils.generateUUID(),
}),
topics.post({
uid,
cid,
title: utils.generateUUID(),
content: utils.generateUUID(),
}),
]);
describe('announceObject()', () => {
let cid;
let uid;
let adminUid;
assert(topic1 && topic2);
before(async () => {
const name = utils.generateUUID();
const description = utils.generateUUID();
({ cid } = await categories.create({ name, description }));
// Create new reply and move it to topic 2
const { pid } = await topics.reply({ uid, tid: topic1.tid, content: utils.generateUUID() });
await api.posts.move({ uid: adminUid }, { pid, tid: topic2.tid });
adminUid = await user.create({ username: utils.generateUUID() });
await groups.join('administrators', adminUid);
uid = await user.create({ username: utils.generateUUID() });
assert.strictEqual(activitypub._sent.size, 1);
const activities = Array.from(activitypub._sent.keys()).map(key => activitypub._sent.get(key));
const { id: followerId, actor } = helpers.mocks.actor();
activitypub._cache.set(`0;${followerId}`, actor);
user.setCategoryWatchState(followerId, [cid], categories.watchStates.tracking);
activitypub._sent.clear();
});
afterEach(() => {
activitypub._sent.clear();
const activity = activities.pop();
assert.strictEqual(activity.type, 'Announce');
assert(activity.object && activity.object.type);
assert.strictEqual(activity.object.type, 'Create');
assert(activity.object.object && activity.object.object.type);
assert.strictEqual(activity.object.object.type, 'Note');
});
});
});