enhance: モデレーターがチャットルームの内容を確認・削除できるように

This commit is contained in:
syuilo 2025-03-25 15:51:45 +09:00
parent 304d0eb83b
commit a01ae38a07
12 changed files with 73 additions and 7 deletions

View file

@ -27,6 +27,7 @@ import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
import { emojiRegex } from '@/misc/emoji-regex.js';
import { NotificationService } from '@/core/NotificationService.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
const MAX_ROOM_MEMBERS = 30;
const MAX_REACTIONS_PER_MESSAGE = 100;
@ -75,6 +76,7 @@ export class ChatService {
private roleService: RoleService,
private userFollowingService: UserFollowingService,
private customEmojiService: CustomEmojiService,
private moderationLogService: ModerationLogService,
) {
}
@ -285,6 +287,20 @@ export class ChatService {
return this.chatMessagesRepository.findOneBy({ id: messageId, fromUserId: userId });
}
@bindThis
public async hasPermissionToViewRoomTimeline(meId: MiUser['id'], room: MiChatRoom) {
if (await this.isRoomMember(room, meId)) {
return true;
} else {
const iAmModerator = await this.roleService.isModerator({ id: meId });
if (iAmModerator) {
return true;
}
return false;
}
}
@bindThis
public async deleteMessage(message: MiChatMessage) {
await this.chatMessagesRepository.delete(message.id);
@ -493,8 +509,29 @@ export class ChatService {
}
@bindThis
public async deleteRoom(room: MiChatRoom) {
public async hasPermissionToDeleteRoom(meId: MiUser['id'], room: MiChatRoom) {
if (room.ownerId === meId) {
return true;
}
const iAmModerator = await this.roleService.isModerator({ id: meId });
if (iAmModerator) {
return true;
}
return false;
}
@bindThis
public async deleteRoom(room: MiChatRoom, moderator?: MiUser) {
await this.chatRoomsRepository.delete(room.id);
if (moderator) {
this.moderationLogService.log(moderator, 'deleteChatRoom', {
roomId: room.id,
room: room,
});
}
}
@bindThis