Skip to content

Node.js based forum software built for the modern web

fix: remote categories should not show up in a user's follow lists

Julian Lam4d1d7c3dcaa0
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 };
+}