forked from misskey-dev/misskey
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ages/backend/src/server/api/endpoints/admin/federation/remove-all-following-by-user-id.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { Endpoint } from '@/server/api/endpoint-base.js'; | ||
import type { FollowingsRepository, User, UsersRepository } from '@/models/index.js'; | ||
import { UserFollowingService } from '@/core/UserFollowingService.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
|
||
export const meta = { | ||
tags: ['admin'], | ||
|
||
requireCredential: true, | ||
requireModerator: true, | ||
} as const; | ||
|
||
export const paramDef = { | ||
type: 'object', | ||
properties: { | ||
userId: { type: 'string' }, | ||
}, | ||
required: ['userId'], | ||
} as const; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
@Injectable() | ||
export default class extends Endpoint<typeof meta, typeof paramDef> { | ||
constructor( | ||
@Inject(DI.usersRepository) | ||
private usersRepository: UsersRepository, | ||
|
||
@Inject(DI.followingsRepository) | ||
private followingsRepository: FollowingsRepository, | ||
|
||
private userFollowingService: UserFollowingService, | ||
) { | ||
super(meta, paramDef, async (ps, me) => { | ||
const follower = await this.usersRepository.findOne({ where: { id: ps.userId } }); | ||
|
||
if (!follower) { | ||
throw new Error(`User not found: ${ps.userId}`); | ||
} | ||
|
||
await this.unFollowAll(follower); | ||
}); | ||
} | ||
|
||
@bindThis | ||
private async unFollowAll(follower: User) { | ||
const followings = await this.followingsRepository.findBy({ | ||
followerId: follower.id, | ||
}); | ||
|
||
for (const following of followings) { | ||
const followee = await this.usersRepository.findOneBy({ | ||
id: following.followeeId, | ||
}); | ||
|
||
if (followee == null) { | ||
throw `Cant find followee ${following.followeeId}`; | ||
} | ||
|
||
await this.userFollowingService.unfollow(follower, followee, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters