From e68278f93e82ba396ea2b1fbe0c7e0231c640421 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 4 Mar 2022 20:23:53 +0900 Subject: feat: 時限ミュート MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #7677 --- packages/client/src/scripts/get-user-menu.ts | 43 ++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'packages/client/src/scripts') diff --git a/packages/client/src/scripts/get-user-menu.ts b/packages/client/src/scripts/get-user-menu.ts index 6d1f25a942..192d14b83e 100644 --- a/packages/client/src/scripts/get-user-menu.ts +++ b/packages/client/src/scripts/get-user-menu.ts @@ -56,11 +56,44 @@ export function getUserMenu(user) { } async function toggleMute() { - os.apiWithDialog(user.isMuted ? 'mute/delete' : 'mute/create', { - userId: user.id - }).then(() => { - user.isMuted = !user.isMuted; - }); + if (user.isMuted) { + os.apiWithDialog('mute/delete', { + userId: user.id, + }).then(() => { + user.isMuted = false; + }); + } else { + const { canceled, result: period } = await os.select({ + title: i18n.ts.mutePeriod, + items: [{ + value: 'indefinitely', text: i18n.ts.indefinitely, + }, { + value: 'tenMinutes', text: i18n.ts.tenMinutes, + }, { + value: 'oneHour', text: i18n.ts.oneHour, + }, { + value: 'oneDay', text: i18n.ts.oneDay, + }, { + value: 'oneWeek', text: i18n.ts.oneWeek, + }], + default: 'indefinitely', + }); + if (canceled) return; + + const expiresAt = period === 'indefinitely' ? null + : period === 'tenMinutes' ? Date.now() + (1000 * 60 * 10) + : period === 'oneHour' ? Date.now() + (1000 * 60 * 60) + : period === 'oneDay' ? Date.now() + (1000 * 60 * 60 * 24) + : period === 'oneWeek' ? Date.now() + (1000 * 60 * 60 * 24 * 7) + : null; + + os.apiWithDialog('mute/create', { + userId: user.id, + expiresAt, + }).then(() => { + user.isMuted = true; + }); + } } async function toggleBlock() { -- cgit v1.2.3-freya From a07037affc38d9f753682dacc4d941838648c74d Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Wed, 9 Mar 2022 22:18:14 +0900 Subject: テーマ選択から重複要素を排除するように (#8385) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/client/src/pages/settings/theme.vue | 4 ++-- packages/client/src/scripts/array.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'packages/client/src/scripts') diff --git a/packages/client/src/pages/settings/theme.vue b/packages/client/src/pages/settings/theme.vue index 92a6fee7a4..d134a092b6 100644 --- a/packages/client/src/pages/settings/theme.vue +++ b/packages/client/src/pages/settings/theme.vue @@ -101,7 +101,7 @@ import { ColdDeviceStorage } from '@/store'; import { i18n } from '@/i18n'; import { defaultStore } from '@/store'; import { instance } from '@/instance'; -import { concat } from '@/scripts/array'; +import { concat, uniqueBy } from '@/scripts/array'; import { fetchThemes, getThemes } from '@/theme-store'; import * as symbols from '@/symbols'; @@ -128,7 +128,7 @@ export default defineComponent({ const instanceThemes = []; if (instance.defaultLightTheme != null) instanceThemes.push(JSON5.parse(instance.defaultLightTheme)); if (instance.defaultDarkTheme != null) instanceThemes.push(JSON5.parse(instance.defaultDarkTheme)); - const themes = computed(() => instanceThemes.concat(builtinThemes.concat(installedThemes.value))); + const themes = computed(() => uniqueBy(instanceThemes.concat(builtinThemes.concat(installedThemes.value)), theme => theme.id)); const darkThemes = computed(() => themes.value.filter(t => t.base === 'dark' || t.kind === 'dark')); const lightThemes = computed(() => themes.value.filter(t => t.base === 'light' || t.kind === 'light')); const darkTheme = ColdDeviceStorage.ref('darkTheme'); diff --git a/packages/client/src/scripts/array.ts b/packages/client/src/scripts/array.ts index d63f0475d0..29d027de14 100644 --- a/packages/client/src/scripts/array.ts +++ b/packages/client/src/scripts/array.ts @@ -52,6 +52,17 @@ export function unique(xs: T[]): T[] { return [...new Set(xs)]; } +export function uniqueBy(values: TValue[], keySelector: (value: TValue) => TKey): TValue[] { + const map = new Map(); + + for (const value of values) { + const key = keySelector(value); + if (!map.has(key)) map.set(key, value); + } + + return [...map.values()]; +} + export function sum(xs: number[]): number { return xs.reduce((a, b) => a + b, 0); } -- cgit v1.2.3-freya