enhance(backend): 凍結されたアカウントのフォローリクエストを表示しないように
This commit is contained in:
		
							parent
							
								
									41936c16c4
								
							
						
					
					
						commit
						cd210001e6
					
				
					 4 changed files with 81 additions and 64 deletions
				
			
		| 
						 | 
					@ -12,6 +12,7 @@
 | 
				
			||||||
- Fix: mCaptchaを使用していてもbotプロテクションに関する警告が消えないのを修正
 | 
					- Fix: mCaptchaを使用していてもbotプロテクションに関する警告が消えないのを修正
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Server
 | 
					### Server
 | 
				
			||||||
 | 
					- Enhance: 凍結されたアカウントのフォローリクエストを表示しないように
 | 
				
			||||||
- Fix: WSの`readAllNotifications` メッセージが `body` を持たない場合に動作しない問題 #14374
 | 
					- Fix: WSの`readAllNotifications` メッセージが `body` を持たない場合に動作しない問題 #14374
 | 
				
			||||||
  - 通知ページや通知カラム(デッキ)を開いている状態において、新たに発生した通知が既読されない問題が修正されます。
 | 
					  - 通知ページや通知カラム(デッキ)を開いている状態において、新たに発生した通知が既読されない問題が修正されます。
 | 
				
			||||||
  - これにより、プッシュ通知が有効な同条件下の環境において、プッシュ通知が常に発生してしまう問題も修正されます。
 | 
					  - これにより、プッシュ通知が有効な同条件下の環境において、プッシュ通知が常に発生してしまう問題も修正されます。
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Inject, Injectable } from '@nestjs/common';
 | 
					import { Inject, Injectable } from '@nestjs/common';
 | 
				
			||||||
import { Not, IsNull } from 'typeorm';
 | 
					import { Not, IsNull } from 'typeorm';
 | 
				
			||||||
import type { FollowingsRepository } from '@/models/_.js';
 | 
					import type { FollowingsRepository, FollowRequestsRepository, UsersRepository } from '@/models/_.js';
 | 
				
			||||||
import type { MiUser } from '@/models/User.js';
 | 
					import type { MiUser } from '@/models/User.js';
 | 
				
			||||||
import { QueueService } from '@/core/QueueService.js';
 | 
					import { QueueService } from '@/core/QueueService.js';
 | 
				
			||||||
import { GlobalEventService } from '@/core/GlobalEventService.js';
 | 
					import { GlobalEventService } from '@/core/GlobalEventService.js';
 | 
				
			||||||
| 
						 | 
					@ -13,24 +13,75 @@ import { DI } from '@/di-symbols.js';
 | 
				
			||||||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
 | 
					import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
 | 
				
			||||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
 | 
					import { UserEntityService } from '@/core/entities/UserEntityService.js';
 | 
				
			||||||
import { bindThis } from '@/decorators.js';
 | 
					import { bindThis } from '@/decorators.js';
 | 
				
			||||||
 | 
					import { RelationshipJobData } from '@/queue/types.js';
 | 
				
			||||||
 | 
					import { ModerationLogService } from '@/core/ModerationLogService.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Injectable()
 | 
					@Injectable()
 | 
				
			||||||
export class UserSuspendService {
 | 
					export class UserSuspendService {
 | 
				
			||||||
	constructor(
 | 
						constructor(
 | 
				
			||||||
 | 
							@Inject(DI.usersRepository)
 | 
				
			||||||
 | 
							private usersRepository: UsersRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		@Inject(DI.followingsRepository)
 | 
							@Inject(DI.followingsRepository)
 | 
				
			||||||
		private followingsRepository: FollowingsRepository,
 | 
							private followingsRepository: FollowingsRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							@Inject(DI.followRequestsRepository)
 | 
				
			||||||
 | 
							private followRequestsRepository: FollowRequestsRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private userEntityService: UserEntityService,
 | 
							private userEntityService: UserEntityService,
 | 
				
			||||||
		private queueService: QueueService,
 | 
							private queueService: QueueService,
 | 
				
			||||||
		private globalEventService: GlobalEventService,
 | 
							private globalEventService: GlobalEventService,
 | 
				
			||||||
		private apRendererService: ApRendererService,
 | 
							private apRendererService: ApRendererService,
 | 
				
			||||||
 | 
							private moderationLogService: ModerationLogService,
 | 
				
			||||||
	) {
 | 
						) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@bindThis
 | 
						@bindThis
 | 
				
			||||||
	public async doPostSuspend(user: { id: MiUser['id']; host: MiUser['host'] }): Promise<void> {
 | 
						public async suspend(user: MiUser, moderator: MiUser): Promise<void> {
 | 
				
			||||||
 | 
							await this.usersRepository.update(user.id, {
 | 
				
			||||||
 | 
								isSuspended: true,
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							this.moderationLogService.log(moderator, 'suspend', {
 | 
				
			||||||
 | 
								userId: user.id,
 | 
				
			||||||
 | 
								userUsername: user.username,
 | 
				
			||||||
 | 
								userHost: user.host,
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							(async () => {
 | 
				
			||||||
 | 
								await this.postSuspend(user).catch(e => {});
 | 
				
			||||||
 | 
								await this.unFollowAll(user).catch(e => {});
 | 
				
			||||||
 | 
							})();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@bindThis
 | 
				
			||||||
 | 
						public async unsuspend(user: MiUser, moderator: MiUser): Promise<void> {
 | 
				
			||||||
 | 
							await this.usersRepository.update(user.id, {
 | 
				
			||||||
 | 
								isSuspended: false,
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							this.moderationLogService.log(moderator, 'unsuspend', {
 | 
				
			||||||
 | 
								userId: user.id,
 | 
				
			||||||
 | 
								userUsername: user.username,
 | 
				
			||||||
 | 
								userHost: user.host,
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							(async () => {
 | 
				
			||||||
 | 
								await this.postUnsuspend(user).catch(e => {});
 | 
				
			||||||
 | 
							})();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@bindThis
 | 
				
			||||||
 | 
						private async postSuspend(user: { id: MiUser['id']; host: MiUser['host'] }): Promise<void> {
 | 
				
			||||||
		this.globalEventService.publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: true });
 | 
							this.globalEventService.publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: true });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							this.followRequestsRepository.delete({
 | 
				
			||||||
 | 
								followeeId: user.id,
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							this.followRequestsRepository.delete({
 | 
				
			||||||
 | 
								followerId: user.id,
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (this.userEntityService.isLocalUser(user)) {
 | 
							if (this.userEntityService.isLocalUser(user)) {
 | 
				
			||||||
			// 知り得る全SharedInboxにDelete配信
 | 
								// 知り得る全SharedInboxにDelete配信
 | 
				
			||||||
			const content = this.apRendererService.addContext(this.apRendererService.renderDelete(this.userEntityService.genLocalUserUri(user.id), user));
 | 
								const content = this.apRendererService.addContext(this.apRendererService.renderDelete(this.userEntityService.genLocalUserUri(user.id), user));
 | 
				
			||||||
| 
						 | 
					@ -58,7 +109,7 @@ export class UserSuspendService {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@bindThis
 | 
						@bindThis
 | 
				
			||||||
	public async doPostUnsuspend(user: MiUser): Promise<void> {
 | 
						private async postUnsuspend(user: MiUser): Promise<void> {
 | 
				
			||||||
		this.globalEventService.publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false });
 | 
							this.globalEventService.publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (this.userEntityService.isLocalUser(user)) {
 | 
							if (this.userEntityService.isLocalUser(user)) {
 | 
				
			||||||
| 
						 | 
					@ -86,4 +137,26 @@ export class UserSuspendService {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@bindThis
 | 
				
			||||||
 | 
						private async unFollowAll(follower: MiUser) {
 | 
				
			||||||
 | 
							const followings = await this.followingsRepository.find({
 | 
				
			||||||
 | 
								where: {
 | 
				
			||||||
 | 
									followerId: follower.id,
 | 
				
			||||||
 | 
									followeeId: Not(IsNull()),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							const jobs: RelationshipJobData[] = [];
 | 
				
			||||||
 | 
							for (const following of followings) {
 | 
				
			||||||
 | 
								if (following.followeeId && following.followerId) {
 | 
				
			||||||
 | 
									jobs.push({
 | 
				
			||||||
 | 
										from: { id: following.followerId },
 | 
				
			||||||
 | 
										to: { id: following.followeeId },
 | 
				
			||||||
 | 
										silent: true,
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							this.queueService.createUnfollowJob(jobs);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,18 +3,13 @@
 | 
				
			||||||
 * SPDX-License-Identifier: AGPL-3.0-only
 | 
					 * SPDX-License-Identifier: AGPL-3.0-only
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { IsNull, Not } from 'typeorm';
 | 
					import { } from 'typeorm';
 | 
				
			||||||
import { Inject, Injectable } from '@nestjs/common';
 | 
					import { Inject, Injectable } from '@nestjs/common';
 | 
				
			||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
 | 
					import { Endpoint } from '@/server/api/endpoint-base.js';
 | 
				
			||||||
import type { UsersRepository, FollowingsRepository } from '@/models/_.js';
 | 
					import type { UsersRepository } from '@/models/_.js';
 | 
				
			||||||
import type { MiUser } from '@/models/User.js';
 | 
					 | 
				
			||||||
import type { RelationshipJobData } from '@/queue/types.js';
 | 
					 | 
				
			||||||
import { ModerationLogService } from '@/core/ModerationLogService.js';
 | 
					 | 
				
			||||||
import { UserSuspendService } from '@/core/UserSuspendService.js';
 | 
					import { UserSuspendService } from '@/core/UserSuspendService.js';
 | 
				
			||||||
import { DI } from '@/di-symbols.js';
 | 
					import { DI } from '@/di-symbols.js';
 | 
				
			||||||
import { bindThis } from '@/decorators.js';
 | 
					 | 
				
			||||||
import { RoleService } from '@/core/RoleService.js';
 | 
					import { RoleService } from '@/core/RoleService.js';
 | 
				
			||||||
import { QueueService } from '@/core/QueueService.js';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const meta = {
 | 
					export const meta = {
 | 
				
			||||||
	tags: ['admin'],
 | 
						tags: ['admin'],
 | 
				
			||||||
| 
						 | 
					@ -38,13 +33,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
		@Inject(DI.usersRepository)
 | 
							@Inject(DI.usersRepository)
 | 
				
			||||||
		private usersRepository: UsersRepository,
 | 
							private usersRepository: UsersRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		@Inject(DI.followingsRepository)
 | 
					 | 
				
			||||||
		private followingsRepository: FollowingsRepository,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		private userSuspendService: UserSuspendService,
 | 
							private userSuspendService: UserSuspendService,
 | 
				
			||||||
		private roleService: RoleService,
 | 
							private roleService: RoleService,
 | 
				
			||||||
		private moderationLogService: ModerationLogService,
 | 
					 | 
				
			||||||
		private queueService: QueueService,
 | 
					 | 
				
			||||||
	) {
 | 
						) {
 | 
				
			||||||
		super(meta, paramDef, async (ps, me) => {
 | 
							super(meta, paramDef, async (ps, me) => {
 | 
				
			||||||
			const user = await this.usersRepository.findOneBy({ id: ps.userId });
 | 
								const user = await this.usersRepository.findOneBy({ id: ps.userId });
 | 
				
			||||||
| 
						 | 
					@ -57,42 +47,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
				throw new Error('cannot suspend moderator account');
 | 
									throw new Error('cannot suspend moderator account');
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			await this.usersRepository.update(user.id, {
 | 
								await this.userSuspendService.suspend(user, me);
 | 
				
			||||||
				isSuspended: true,
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			this.moderationLogService.log(me, 'suspend', {
 | 
					 | 
				
			||||||
				userId: user.id,
 | 
					 | 
				
			||||||
				userUsername: user.username,
 | 
					 | 
				
			||||||
				userHost: user.host,
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			(async () => {
 | 
					 | 
				
			||||||
				await this.userSuspendService.doPostSuspend(user).catch(e => {});
 | 
					 | 
				
			||||||
				await this.unFollowAll(user).catch(e => {});
 | 
					 | 
				
			||||||
			})();
 | 
					 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	@bindThis
 | 
					 | 
				
			||||||
	private async unFollowAll(follower: MiUser) {
 | 
					 | 
				
			||||||
		const followings = await this.followingsRepository.find({
 | 
					 | 
				
			||||||
			where: {
 | 
					 | 
				
			||||||
				followerId: follower.id,
 | 
					 | 
				
			||||||
				followeeId: Not(IsNull()),
 | 
					 | 
				
			||||||
			},
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		const jobs: RelationshipJobData[] = [];
 | 
					 | 
				
			||||||
		for (const following of followings) {
 | 
					 | 
				
			||||||
			if (following.followeeId && following.followerId) {
 | 
					 | 
				
			||||||
				jobs.push({
 | 
					 | 
				
			||||||
					from: { id: following.followerId },
 | 
					 | 
				
			||||||
					to: { id: following.followeeId },
 | 
					 | 
				
			||||||
					silent: true,
 | 
					 | 
				
			||||||
				});
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		this.queueService.createUnfollowJob(jobs);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,6 @@
 | 
				
			||||||
import { Inject, Injectable } from '@nestjs/common';
 | 
					import { Inject, Injectable } from '@nestjs/common';
 | 
				
			||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
 | 
					import { Endpoint } from '@/server/api/endpoint-base.js';
 | 
				
			||||||
import type { UsersRepository } from '@/models/_.js';
 | 
					import type { UsersRepository } from '@/models/_.js';
 | 
				
			||||||
import { ModerationLogService } from '@/core/ModerationLogService.js';
 | 
					 | 
				
			||||||
import { UserSuspendService } from '@/core/UserSuspendService.js';
 | 
					import { UserSuspendService } from '@/core/UserSuspendService.js';
 | 
				
			||||||
import { DI } from '@/di-symbols.js';
 | 
					import { DI } from '@/di-symbols.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +32,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
		private usersRepository: UsersRepository,
 | 
							private usersRepository: UsersRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private userSuspendService: UserSuspendService,
 | 
							private userSuspendService: UserSuspendService,
 | 
				
			||||||
		private moderationLogService: ModerationLogService,
 | 
					 | 
				
			||||||
	) {
 | 
						) {
 | 
				
			||||||
		super(meta, paramDef, async (ps, me) => {
 | 
							super(meta, paramDef, async (ps, me) => {
 | 
				
			||||||
			const user = await this.usersRepository.findOneBy({ id: ps.userId });
 | 
								const user = await this.usersRepository.findOneBy({ id: ps.userId });
 | 
				
			||||||
| 
						 | 
					@ -42,17 +40,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
				throw new Error('user not found');
 | 
									throw new Error('user not found');
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			await this.usersRepository.update(user.id, {
 | 
								await this.userSuspendService.unsuspend(user, me);
 | 
				
			||||||
				isSuspended: false,
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			this.moderationLogService.log(me, 'unsuspend', {
 | 
					 | 
				
			||||||
				userId: user.id,
 | 
					 | 
				
			||||||
				userUsername: user.username,
 | 
					 | 
				
			||||||
				userHost: user.host,
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			this.userSuspendService.doPostUnsuspend(user);
 | 
					 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue