automatically transfer blocks and mutes on moves #383

Open
Johann150 wants to merge 7 commits from move-autoblock into main
1 changed files with 28 additions and 2 deletions
Showing only changes of commit 2f0ad5ee2d - Show all commits

View File

@ -1,8 +1,10 @@
import { IsNull } from 'typeorm';
import { IRemoteUser } from '@/models/entities/user.js';
import { resolvePerson } from '@/remote/activitypub/models/person.js';
import { Followings, Users } from '@/models/index.js';
import { Blockings, Followings, Mutings, Users } from '@/models/index.js';
import { createNotification } from '@/services/create-notification.js';
import { createBlock } from '@/services/blocking/create.js';
import { createMute } from '@/services/mute/create.js';
import Resolver from '../../resolver.js';
import { IMove, isActor, getApId } from '../../type.js';
@ -36,7 +38,7 @@ export async function move(actor: IRemoteUser, activity: IMove, resolver: Resolv
if (movedTo.isSuspended) return;
// process move for local followers
const followings = Followings.find({
const followings = await Followings.find({
select: {
followerId: true,
},
@ -46,6 +48,22 @@ export async function move(actor: IRemoteUser, activity: IMove, resolver: Resolv
},
});
// create blocks/mutes for the new account analogous to the old account
const blockings = await Blockings.createQueryBuilder('blocking')
.leftJoinAndSelect('blocking.blocker', 'blocker')
// accounts that blocked the previous account
.where('blockeeId = :blockee', { blockee: actor.id })
// ... and are not already blocking the new account
.andWhere('"blocking"."blockerId" NOT IN (SELECT "blockerId" FROM "blocking" WHERE "blockeeId" = :movedTo)', { movedTo: movedTo.id })
.getRawMany();
const mutes = await Mutings.createQueryBuilder('muting')
.leftJoinAndSelect('muting.muter', 'muter')
// accounts that muted the previous account
.where('muteeId = :mutee', { mutee: actor.id })
// ... and are not already muting the new account
.andWhere('"muting"."muterId" NOT IN (SELECT "muterId" FROM "muting" WHERE "muteeId" = :movedTo)', { movedTo: movedTo.id })
.getRawMany();
await Promise.all([
Users.update(actor.id, {
movedToId: movedTo.id,
@ -58,5 +76,13 @@ export async function move(actor: IRemoteUser, activity: IMove, resolver: Resolv
moveTargetId: movedTo.id,
});
}),
...blockings.map(async ({ blocker }) => {
// create block with all side effects
await createBlock(blocker, actor);
}),
...mutes.map(async ({ muter, expiresAt }) => {
// create mute with all side effects
await createMute(muter, actor, expiresAt);
});
]);
}