fix: topic crosspost delete and purge handling

This commit is contained in:
Julian Lam
2025-12-29 14:32:34 -05:00
parent 0a0a7da9ba
commit f6cc556d37
3 changed files with 71 additions and 0 deletions

View File

@@ -127,4 +127,14 @@ Crossposts.remove = async function (tid, cid, uid) {
crossposts = await Crossposts.get(tid);
return crossposts;
};
Crossposts.removeAll = async function (tid) {
const crosspostIds = await db.getSortedSetMembers(`tid:${tid}:crossposts`);
const crossposts = await db.getObjects(crosspostIds.map(id => `crosspost:${id}`));
await Promise.all(crossposts.map(async ({ tid, cid, uid }) => {
return Crossposts.remove(tid, cid, uid);
}));
return [];
};

View File

@@ -102,6 +102,7 @@ module.exports = function (Topics) {
Topics.deleteTopicTags(tid),
Topics.events.purge(tid),
Topics.thumbs.deleteAll(tid),
Topics.crossposts.removeAll(tid),
reduceCounters(tid),
]);
plugins.hooks.fire('action:topic.purge', { topic: deletedTopic, uid: uid });

View File

@@ -288,6 +288,66 @@ describe('Crossposting (& related logic)', () => {
});
});
describe('Deletion', () => {
let tid;
let cid1;
let cid2;
let uid;
before(async () => {
({ cid: cid1 } = await categories.create({ name: utils.generateUUID().slice(0, 8) }));
const crosspostCategory = await categories.create({ name: utils.generateUUID().slice(0, 8) });
cid2 = crosspostCategory.cid;
uid = await user.create({ username: utils.generateUUID().slice(0, 8) });
const { topicData } = await topics.post({
uid,
cid: cid1,
title: utils.generateUUID(),
content: utils.generateUUID(),
});
tid = topicData.tid;
await topics.crossposts.add(tid, cid2, uid);
await topics.delete(tid, uid);
});
it('should maintain crossposts when topic is deleted', async () => {
const crossposts = await topics.crossposts.get(tid);
assert(Array.isArray(crossposts));
assert.strictEqual(crossposts.length, 1);
});
});
describe('Purging', () => {
let tid;
let cid1;
let cid2;
let uid;
before(async () => {
({ cid: cid1 } = await categories.create({ name: utils.generateUUID().slice(0, 8) }));
const crosspostCategory = await categories.create({ name: utils.generateUUID().slice(0, 8) });
cid2 = crosspostCategory.cid;
uid = await user.create({ username: utils.generateUUID().slice(0, 8) });
const { topicData } = await topics.post({
uid,
cid: cid1,
title: utils.generateUUID(),
content: utils.generateUUID(),
});
tid = topicData.tid;
await topics.crossposts.add(tid, cid2, uid);
await topics.purge(tid, uid);
});
it('should remove crossposts when topic is purged', async () => {
const crossposts = await topics.crossposts.get(tid);
assert(Array.isArray(crossposts));
assert.strictEqual(crossposts.length, 0);
});
});
describe('ActivityPub effects (or lack thereof)', () => {
describe('local canonical category', () => {
let tid;