diff options
| author | tamaina <tamaina@hotmail.co.jp> | 2022-03-27 22:42:05 +0900 |
|---|---|---|
| committer | tamaina <tamaina@hotmail.co.jp> | 2022-03-27 22:42:05 +0900 |
| commit | 7314643b8d80445bcc24c0056f9236763efec4de (patch) | |
| tree | 2c2b67bb7bc406c0d2633eaddfa438c1f528138c /packages/client/src/scripts | |
| parent | Merge branch 'develop' into pizzax-indexeddb (diff) | |
| parent | Update CONTRIBUTING.md (diff) | |
| download | misskey-7314643b8d80445bcc24c0056f9236763efec4de.tar.gz misskey-7314643b8d80445bcc24c0056f9236763efec4de.tar.bz2 misskey-7314643b8d80445bcc24c0056f9236763efec4de.zip | |
Merge branch 'develop' into pizzax-indexeddb
Diffstat (limited to 'packages/client/src/scripts')
| -rw-r--r-- | packages/client/src/scripts/array.ts | 11 | ||||
| -rw-r--r-- | packages/client/src/scripts/get-user-menu.ts | 43 |
2 files changed, 49 insertions, 5 deletions
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<T>(xs: T[]): T[] { return [...new Set(xs)]; } +export function uniqueBy<TValue, TKey>(values: TValue[], keySelector: (value: TValue) => TKey): TValue[] { + const map = new Map<TKey, TValue>(); + + 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); } 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() { |