diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2025-04-07 19:09:11 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-07 19:09:11 +0900 |
| commit | 9d3f3264fdd059f47537da48fd125cdd2f4bad1e (patch) | |
| tree | dedbf1433d0e003465b37e805519c5635b135466 /packages/backend/src/core/ChatService.ts | |
| parent | Update CHANGELOG.md (diff) | |
| download | misskey-9d3f3264fdd059f47537da48fd125cdd2f4bad1e.tar.gz misskey-9d3f3264fdd059f47537da48fd125cdd2f4bad1e.tar.bz2 misskey-9d3f3264fdd059f47537da48fd125cdd2f4bad1e.zip | |
enhance: チャットの閲覧を無効化できるように (#15765)
* enhance: チャットの閲覧を無効化できるように
* fix
* fix
* fix
* readonlyの説明を追加
* enhance: チャットが無効な場合はチャット関連の設定も隠すように
* fix
* refactor: ChatServiceからApiに関するドメイン知識を排除
Diffstat (limited to 'packages/backend/src/core/ChatService.ts')
| -rw-r--r-- | packages/backend/src/core/ChatService.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/packages/backend/src/core/ChatService.ts b/packages/backend/src/core/ChatService.ts index 3984cefc80..b0e8cfb61c 100644 --- a/packages/backend/src/core/ChatService.ts +++ b/packages/backend/src/core/ChatService.ts @@ -95,6 +95,40 @@ export class ChatService { } @bindThis + public async getChatAvailability(userId: MiUser['id']): Promise<{ read: boolean; write: boolean; }> { + const policies = await this.roleService.getUserPolicies(userId); + + switch (policies.chatAvailability) { + case 'available': + return { + read: true, + write: true, + }; + case 'readonly': + return { + read: true, + write: false, + }; + case 'unavailable': + return { + read: false, + write: false, + }; + default: + throw new Error('invalid chat availability (unreachable)'); + } + } + + /** getChatAvailabilityの糖衣。主にAPI呼び出し時に走らせて、権限的に問題ない場合はそのまま続行する */ + @bindThis + public async checkChatAvailability(userId: MiUser['id'], permission: 'read' | 'write') { + const policy = await this.getChatAvailability(userId); + if (policy[permission] === false) { + throw new Error('ROLE_PERMISSION_DENIED'); + } + } + + @bindThis public async createMessageToUser(fromUser: { id: MiUser['id']; host: MiUser['host']; }, toUser: MiUser, params: { text?: string | null; file?: MiDriveFile | null; @@ -140,7 +174,7 @@ export class ChatService { } } - if (!(await this.roleService.getUserPolicies(toUser.id)).canChat) { + if (!(await this.getChatAvailability(toUser.id)).write) { throw new Error('recipient is cannot chat (policy)'); } |