From 4d1d7c3dcaa0c6709f4f9be0fc380b3ecd3d6474 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 26 Mar 2025 14:08:26 -0400 Subject: [PATCH] fix: remote categories should not show up in a user's follow lists --- src/user/follow.js | 6 +++++- test/activitypub/actors.js | 15 +++++++++++++++ test/activitypub/helpers.js | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/user/follow.js b/src/user/follow.js index 0595e50ff8..5faf912ed2 100644 --- a/src/user/follow.js +++ b/src/user/follow.js @@ -79,11 +79,15 @@ module.exports = function (User) { if (parseInt(uid, 10) <= 0) { return []; } - const uids = await db.getSortedSetRevRange([ + let uids = await db.getSortedSetRevRange([ `${type}:${uid}`, `${type}Remote:${uid}`, ], start, stop); + // Filter out remote categories + const isCategory = await db.exists(uids.map(uid => `categoryRemote:${uid}`)); + uids = uids.filter((uid, idx) => !isCategory[idx]) + const data = await plugins.hooks.fire(`filter:user.${type}`, { uids: uids, uid: uid, diff --git a/test/activitypub/actors.js b/test/activitypub/actors.js index ab793a6235..0a3ca34e60 100644 --- a/test/activitypub/actors.js +++ b/test/activitypub/actors.js @@ -334,6 +334,21 @@ describe('as:Group', () => { assert.strictEqual(activity.type, 'Follow'); assert.strictEqual(activity.object, cid); }); + + it.only('should not show up in the user\'s following list', async () => { + await user.setCategoryWatchState(uid, cid, categories.watchStates.watching); + + // Trigger inbox accept + const { activity: body } = helpers.mocks.accept(cid, { + type: 'Follow', + actor: `${nconf.get('url')}/uid/${uid}`, + }); + await activitypub.inbox.accept({ body }); + + const following = await user.getFollowing(uid, 0, 1); + assert(Array.isArray(following)); + assert.strictEqual(following.length, 0); + }); }); describe('user already following', () => { diff --git a/test/activitypub/helpers.js b/test/activitypub/helpers.js index 4bb3abe385..f557b90007 100644 --- a/test/activitypub/helpers.js +++ b/test/activitypub/helpers.js @@ -106,3 +106,20 @@ Helpers.mocks.create = (object) => { return { id, activity }; }; + +Helpers.mocks.accept = (actor, object) => { + const baseUrl = 'https://example.org'; + const uuid = utils.generateUUID(); + const id = `${baseUrl}/activity/${uuid}`; + + const activity = { + '@context': 'https://www.w3.org/ns/activitystreams', + id, + type: 'Accept', + to: ['https://www.w3.org/ns/activitystreams#Public'], + actor, + object, + }; + + return { activity }; +}