Skip to content

Node.js based forum software built for the modern web

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

Julian Lam254f0738bbf8
diff --git a/src/api/posts.js b/src/api/posts.js
index 04c9384177..dbdec5817d 100644
--- a/src/api/posts.js
+++ b/src/api/posts.js
@@ -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);
}
};
diff --git a/test/activitypub/feps.js b/test/activitypub/feps.js
index ff9738a80b..274de2b3ea 100644
--- a/test/activitypub/feps.js
+++ b/test/activitypub/feps.js
@@ -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() });
-
- const { id: followerId, actor } = helpers.mocks.actor();
- activitypub._cache.set(`0;${followerId}`, actor);
- user.setCategoryWatchState(followerId, [cid], categories.watchStates.tracking);
+ assert.strictEqual(activitypub._sent.size, 1);
+ const activities = Array.from(activitypub._sent.keys()).map(key => activitypub._sent.get(key));
- 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');
});
});
});