mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: remote user to category migration should also migrate local user follows into category watches
This commit is contained in:
@@ -418,6 +418,13 @@ async function _migratePersonToGroup(categoryObjs) {
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
const followers = await db.getSortedSetMembersWithScores(`followersRemote:${id}`);
|
||||
await db.sortedSetAdd(
|
||||
`cid:${id}:uid:watch:state`,
|
||||
followers.map(() => categories.watchStates.tracking),
|
||||
followers.map(({ value }) => value),
|
||||
);
|
||||
await user.deleteAccount(id);
|
||||
}));
|
||||
await categories.onTopicsMoved(ids);
|
||||
|
||||
@@ -76,6 +76,7 @@ describe('Actor asserton', () => {
|
||||
assert.strictEqual(assertion[0].cid, actor.id);
|
||||
});
|
||||
|
||||
describe('remote user to remote category migration', () => {
|
||||
it('should not migrate a user to a category if .assert is called', async () => {
|
||||
// ... because the user isn't due for an update and so is filtered out during qualification
|
||||
const { id } = helpers.mocks.person();
|
||||
@@ -95,6 +96,19 @@ describe('Actor asserton', () => {
|
||||
const { id } = helpers.mocks.person();
|
||||
await activitypub.actors.assert([id]);
|
||||
|
||||
helpers.mocks.group({ id });
|
||||
const assertion = await activitypub.actors.assertGroup([id]);
|
||||
|
||||
assert(assertion && Array.isArray(assertion) && assertion.length === 1);
|
||||
|
||||
const exists = await user.exists(id);
|
||||
assert.strictEqual(exists, false);
|
||||
});
|
||||
|
||||
it('should migrate any shares by that user, into topics in the category', async () => {
|
||||
const { id } = helpers.mocks.person();
|
||||
await activitypub.actors.assert([id]);
|
||||
|
||||
// Two shares
|
||||
for (let x = 0; x < 2; x++) {
|
||||
const { id: pid } = helpers.mocks.note();
|
||||
@@ -104,18 +118,31 @@ describe('Actor asserton', () => {
|
||||
await db.sortedSetAdd(`uid:${id}:shares`, Date.now(), tid);
|
||||
}
|
||||
|
||||
const { actor } = helpers.mocks.group({ id });
|
||||
const assertion = await activitypub.actors.assertGroup([id]);
|
||||
|
||||
assert(assertion && Array.isArray(assertion) && assertion.length === 1);
|
||||
helpers.mocks.group({ id });
|
||||
await activitypub.actors.assertGroup([id]);
|
||||
|
||||
const { topic_count, post_count } = await categories.getCategoryData(id);
|
||||
assert.strictEqual(topic_count, 2);
|
||||
assert.strictEqual(post_count, 2);
|
||||
|
||||
const exists = await user.exists(id);
|
||||
assert.strictEqual(exists, false);
|
||||
});
|
||||
|
||||
it('should migrate any local followers into category watches', async () => {
|
||||
const { id } = helpers.mocks.person();
|
||||
await activitypub.actors.assert([id]);
|
||||
|
||||
const followerUid = await user.create({ username: utils.generateUUID() });
|
||||
await Promise.all([
|
||||
db.sortedSetAdd(`followingRemote:${followerUid}`, Date.now(), id),
|
||||
db.sortedSetAdd(`followersRemote:${id}`, Date.now(), followerUid),
|
||||
]);
|
||||
|
||||
helpers.mocks.group({ id });
|
||||
await activitypub.actors.assertGroup([id]);
|
||||
|
||||
const states = await categories.getWatchState([id], followerUid);
|
||||
assert.strictEqual(states[0], categories.watchStates.tracking);
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
describe('edge cases: loopback handles and uris', () => {
|
||||
|
||||
Reference in New Issue
Block a user