From a01ae38a07f949cbcd5ce555cd90e8570bb985cc Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Tue, 25 Mar 2025 15:51:45 +0900 Subject: enhance: モデレーターがチャットルームの内容を確認・削除できるように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/ChatService.ts | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'packages/backend/src/core/ChatService.ts') diff --git a/packages/backend/src/core/ChatService.ts b/packages/backend/src/core/ChatService.ts index 4c010b2ef7..35819a4bc2 100644 --- a/packages/backend/src/core/ChatService.ts +++ b/packages/backend/src/core/ChatService.ts @@ -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 -- cgit v1.2.3-freya