server: automatically copy blocks & mutes on Move
This is not configurable because it would be more complicated to make it so and also because it seems sensible to always do this. Changelog: Added
This commit is contained in:
parent
7fc328acef
commit
2f0ad5ee2d
1 changed files with 28 additions and 2 deletions
|
@ -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);
|
||||
});
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue