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

View file

@ -59,7 +59,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchRoom);
}
if (!(await this.chatService.isRoomMember(room, me.id))) {
if (!await this.chatService.hasPermissionToViewRoomTimeline(me.id, room)) {
throw new ApiError(meta.errors.noSuchRoom);
}

View file

@ -42,11 +42,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private chatService: ChatService,
) {
super(meta, paramDef, async (ps, me) => {
const room = await this.chatService.findMyRoomById(me.id, ps.roomId);
const room = await this.chatService.findRoomById(ps.roomId);
if (room == null) {
throw new ApiError(meta.errors.noSuchRoom);
}
await this.chatService.deleteRoom(room);
if (!await this.chatService.hasPermissionToDeleteRoom(me.id, room)) {
throw new ApiError(meta.errors.noSuchRoom);
}
await this.chatService.deleteRoom(room, me);
});
}
}

View file

@ -124,6 +124,7 @@ export const moderationLogTypes = [
'deletePage',
'deleteFlash',
'deleteGalleryPost',
'deleteChatRoom',
'updateProxyAccountDescription',
] as const;
@ -377,6 +378,10 @@ export type ModerationLogPayloads = {
postUserUsername: string;
post: any;
};
deleteChatRoom: {
roomId: string;
room: any;
};
updateProxyAccountDescription: {
before: string | null;
after: string | null;