Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: サウンド設定でドライブのファイルを利用可否をロールで制御可能に #3

Open
wants to merge 12 commits into
base: hanami
Choose a base branch
from
Open
8 changes: 8 additions & 0 deletions CHANGELOG_HANAMI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Unreleased

### General

### Client
- Feat: サウンド設定でドライブのファイルを利用可否をロールで制御可能に

### Server
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6734,6 +6734,10 @@ export interface Locale extends ILocale {
* 翻訳機能の利用
*/
"canUseTranslator": string;
/**
* サウンド設定でドライブのファイルを利用
*/
"canUseDriveFileInSoundSettings": string;
/**
* アイコンデコレーションの最大取付個数
*/
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,7 @@ _role:
canHideAds: "広告の非表示"
canSearchNotes: "ノート検索の利用"
canUseTranslator: "翻訳機能の利用"
canUseDriveFileInSoundSettings: "サウンド設定でドライブのファイルを利用"
avatarDecorationLimit: "アイコンデコレーションの最大取付個数"
_condition:
roleAssignedTo: "マニュアルロールにアサイン済み"
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/core/RoleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type RolePolicies = {
canManageAvatarDecorations: boolean;
canSearchNotes: boolean;
canUseTranslator: boolean;
canUseDriveFileInSoundSettings: boolean;
canHideAds: boolean;
driveCapacityMb: number;
alwaysMarkNsfw: boolean;
Expand Down Expand Up @@ -73,6 +74,7 @@ export const DEFAULT_POLICIES: RolePolicies = {
canManageAvatarDecorations: false,
canSearchNotes: false,
canUseTranslator: true,
canUseDriveFileInSoundSettings: false,
canHideAds: false,
driveCapacityMb: 100,
alwaysMarkNsfw: false,
Expand Down Expand Up @@ -375,6 +377,7 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
canManageAvatarDecorations: calc('canManageAvatarDecorations', vs => vs.some(v => v === true)),
canSearchNotes: calc('canSearchNotes', vs => vs.some(v => v === true)),
canUseTranslator: calc('canUseTranslator', vs => vs.some(v => v === true)),
canUseDriveFileInSoundSettings: calc('canUseDriveFileInSoundSettings', vs => vs.some(v => v === true)),
canHideAds: calc('canHideAds', vs => vs.some(v => v === true)),
driveCapacityMb: calc('driveCapacityMb', vs => Math.max(...vs)),
alwaysMarkNsfw: calc('alwaysMarkNsfw', vs => vs.some(v => v === true)),
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ export const packedRolePoliciesSchema = {
type: 'boolean',
optional: false, nullable: false,
},
canUseDriveFileInSoundSettings: {
type: 'boolean',
optional: false, nullable: false,
},
canHideAds: {
type: 'boolean',
optional: false, nullable: false,
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const ROLE_POLICIES = [
'canManageAvatarDecorations',
'canSearchNotes',
'canUseTranslator',
'canUseDriveFileInSoundSettings',
'canHideAds',
'driveCapacityMb',
'alwaysMarkNsfw',
Expand Down
20 changes: 20 additions & 0 deletions packages/frontend/src/pages/admin/roles.editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,26 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
</MkFolder>

<MkFolder v-if="matchQuery([i18n.ts._role._options.canUseDriveFileInSoundSettings, 'canUseDriveFileInSoundSettings'])">
<template #label>{{ i18n.ts._role._options.canUseDriveFileInSoundSettings }}</template>
<template #suffix>
<span v-if="role.policies.canUseDriveFileInSoundSettings.useDefault" :class="$style.useDefaultLabel">{{ i18n.ts._role.useBaseValue }}</span>
<span v-else>{{ role.policies.canUseDriveFileInSoundSettings.value ? i18n.ts.yes : i18n.ts.no }}</span>
<span :class="$style.priorityIndicator"><i :class="getPriorityIcon(role.policies.canUseDriveFileInSoundSettings)"></i></span>
</template>
<div class="_gaps">
<MkSwitch v-model="role.policies.canUseDriveFileInSoundSettings.useDefault" :readonly="readonly">
<template #label>{{ i18n.ts._role.useBaseValue }}</template>
</MkSwitch>
<MkSwitch v-model="role.policies.canUseDriveFileInSoundSettings.value" :disabled="role.policies.canUseDriveFileInSoundSettings.useDefault" :readonly="readonly">
<template #label>{{ i18n.ts.enable }}</template>
</MkSwitch>
<MkRange v-model="role.policies.canUseDriveFileInSoundSettings.priority" :min="0" :max="2" :step="1" easing :textConverter="(v) => v === 0 ? i18n.ts._role._priority.low : v === 1 ? i18n.ts._role._priority.middle : v === 2 ? i18n.ts._role._priority.high : ''">
<template #label>{{ i18n.ts._role.priority }}</template>
</MkRange>
</div>
</MkFolder>

<MkFolder v-if="matchQuery([i18n.ts._role._options.driveCapacity, 'driveCapacityMb'])">
<template #label>{{ i18n.ts._role._options.driveCapacity }}</template>
<template #suffix>
Expand Down
10 changes: 9 additions & 1 deletion packages/frontend/src/pages/admin/roles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,22 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSwitch>
</MkFolder>

<MkFolder v-if="matchQuery([i18n.ts._role._options.canUseTranslator, 'canSearchNotes'])">
<MkFolder v-if="matchQuery([i18n.ts._role._options.canUseTranslator, 'canUseTranslator'])">
<template #label>{{ i18n.ts._role._options.canUseTranslator }}</template>
<template #suffix>{{ policies.canUseTranslator ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canUseTranslator">
<template #label>{{ i18n.ts.enable }}</template>
</MkSwitch>
</MkFolder>

<MkFolder v-if="matchQuery([i18n.ts._role._options.canUseDriveFileInSoundSettings, 'canUseDriveFileInSoundSettings'])">
<template #label>{{ i18n.ts._role._options.canUseDriveFileInSoundSettings }}</template>
<template #suffix>{{ policies.canUseDriveFileInSoundSettings ? i18n.ts.yes : i18n.ts.no }}</template>
<MkSwitch v-model="policies.canUseDriveFileInSoundSettings">
<template #label>{{ i18n.ts.enable }}</template>
</MkSwitch>
</MkFolder>

<MkFolder v-if="matchQuery([i18n.ts._role._options.driveCapacity, 'driveCapacityMb'])">
<template #label>{{ i18n.ts._role._options.driveCapacity }}</template>
<template #suffix>{{ policies.driveCapacityMb }}MB</template>
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/src/scripts/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

import type { SoundStore } from '@/store.js';
import { defaultStore } from '@/store.js';
import { $i } from '@/account.js';

let ctx: AudioContext;
const cache = new Map<string, AudioBuffer>();
let canPlay = true;

export const soundsTypes = [
const defaultSoundsTypes = [
// 音声なし
null,

Expand Down Expand Up @@ -71,6 +72,8 @@ export const soundsTypes = [
'noizenecio/kick_gaba7',
] as const;

export const soundsTypes = ($i && $i.policies.canUseDriveFileInSoundSettings) ? defaultSoundsTypes : defaultSoundsTypes.filter(s => s !== '_driveFile_');

export const operationTypes = [
'noteMy',
'note',
Expand Down Expand Up @@ -159,7 +162,7 @@ export async function playMisskeySfxFile(soundStore: SoundStore): Promise<boolea
}

async function playMisskeySfxFileInternal(soundStore: SoundStore): Promise<boolean> {
if (soundStore.type === null || (soundStore.type === '_driveFile_' && !soundStore.fileUrl)) {
if (soundStore.type === null || (soundStore.type === '_driveFile_' && (!$i?.policies.canUseDriveFileInSoundSettings || !soundStore.fileUrl))) {
return false;
}
const masterVolume = defaultStore.state.sound_masterVolume;
Expand Down
1 change: 1 addition & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4787,6 +4787,7 @@ export type components = {
canManageAvatarDecorations: boolean;
canSearchNotes: boolean;
canUseTranslator: boolean;
canUseDriveFileInSoundSettings: boolean;
canHideAds: boolean;
driveCapacityMb: number;
alwaysMarkNsfw: boolean;
Expand Down
Loading