This commit is contained in:
syuilo 2025-03-22 10:30:18 +09:00
parent 37ee6ec9a8
commit 3e200c0f66
2 changed files with 18 additions and 1 deletions

View File

@ -67,8 +67,15 @@ export class ChatService {
if (toUser.chatScope === 'none') {
throw new Error('recipient is cannot chat');
} else if (toUser.chatScope === 'followers') {
const isFollower = await this.userFollowingService.isFollowing(fromUser.id, toUser.id);
if (!isFollower) {
throw new Error('recipient is cannot chat');
}
} else if (toUser.chatScope === 'following') {
const isFollowing = await this.userFollowingService.isFollowing(toUser.id, fromUser.id);
if (!isFollowing) {
throw new Error('recipient is cannot chat');
}
} else if (toUser.chatScope === 'mutual') {
const isMutual = await this.userFollowingService.isMutual(fromUser.id, toUser.id);
if (!isMutual) {

View File

@ -737,6 +737,16 @@ export class UserFollowingService implements OnModuleInit {
.getMany();
}
@bindThis
public isFollowing(followerId: MiUser['id'], followeeId: MiUser['id']) {
return this.followingsRepository.exists({
where: {
followerId,
followeeId,
},
});
}
@bindThis
public async isMutual(aUserId: MiUser['id'], bUserId: MiUser['id']) {
const count = await this.followingsRepository.createQueryBuilder('following')