Skip to content

Node.js based forum software built for the modern web

fix: #13255, remote user-to-category migration should not move shares that are already in an existing cid

Julian Lam3213da1c77c8
diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js
index e86efb0fbc..58f52ac101 100644
--- a/src/activitypub/actors.js
+++ b/src/activitypub/actors.js
@@ -409,9 +409,11 @@ async function _migratePersonToGroup(categoryObjs) {
await Promise.all(ids.map(async (id) => {
const shares = await db.getSortedSetMembers(`uid:${id}:shares`);
- const exists = await topics.exists(shares);
+ let cids = await topics.getTopicsFields(shares, ['cid']);
+ cids = cids.map(o => o.cid);
await Promise.all(shares.map(async (share, idx) => {
- if (exists[idx]) {
+ const cid = cids[idx];
+ if (cid === -1) {
await topics.tools.move(share, {
cid: id,
uid: 'system',
diff --git a/test/activitypub/actors.js b/test/activitypub/actors.js
index 6cfa93de27..ab793a6235 100644
--- a/test/activitypub/actors.js
+++ b/test/activitypub/actors.js
@@ -126,6 +126,36 @@ describe('Actor asserton', () => {
assert.strictEqual(post_count, 2);
});
+ it('should not migrate shares by that user that already belong to a local category', async () => {
+ const { id } = helpers.mocks.person();
+ await activitypub.actors.assert([id]);
+
+ const { cid } = await categories.create({ name: utils.generateUUID() });
+
+ // Two shares, one moved to local cid
+ for (let x = 0; x < 2; x++) {
+ const { id: pid } = helpers.mocks.note();
+ // eslint-disable-next-line no-await-in-loop
+ const { tid } = await activitypub.notes.assert(0, pid, { skipChecks: 1 });
+ // eslint-disable-next-line no-await-in-loop
+ await db.sortedSetAdd(`uid:${id}:shares`, Date.now(), tid);
+
+ if (!x) {
+ await topics.tools.move(tid, {
+ cid,
+ uid: 'system',
+ });
+ }
+ }
+
+ helpers.mocks.group({ id });
+ await activitypub.actors.assertGroup([id]);
+
+ const { topic_count, post_count } = await categories.getCategoryData(id);
+ assert.strictEqual(topic_count, 1);
+ assert.strictEqual(post_count, 1);
+ });
+
it('should migrate any local followers into category watches', async () => {
const { id } = helpers.mocks.person();
await activitypub.actors.assert([id]);