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

This commit is contained in:
Julian Lam
2025-03-26 12:28:10 -04:00
parent f2e0ba2165
commit 3213da1c77
2 changed files with 34 additions and 2 deletions

View File

@@ -409,9 +409,11 @@ async function _migratePersonToGroup(categoryObjs) {
await Promise.all(ids.map(async (id) => { await Promise.all(ids.map(async (id) => {
const shares = await db.getSortedSetMembers(`uid:${id}:shares`); 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) => { await Promise.all(shares.map(async (share, idx) => {
if (exists[idx]) { const cid = cids[idx];
if (cid === -1) {
await topics.tools.move(share, { await topics.tools.move(share, {
cid: id, cid: id,
uid: 'system', uid: 'system',

View File

@@ -126,6 +126,36 @@ describe('Actor asserton', () => {
assert.strictEqual(post_count, 2); 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 () => { it('should migrate any local followers into category watches', async () => {
const { id } = helpers.mocks.person(); const { id } = helpers.mocks.person();
await activitypub.actors.assert([id]); await activitypub.actors.assert([id]);