diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-03-13 22:12:23 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-03-13 22:12:23 +0900 |
| commit | 8c9ec5827fa2040c8d705d2a01329da593d19fa3 (patch) | |
| tree | 59f90cc0aeb39f7366c24aea20441d17508997dd /packages/frontend/src/i.ts | |
| parent | enhance(frontend): improve preferences (diff) | |
| download | sharkey-8c9ec5827fa2040c8d705d2a01329da593d19fa3.tar.gz sharkey-8c9ec5827fa2040c8d705d2a01329da593d19fa3.tar.bz2 sharkey-8c9ec5827fa2040c8d705d2a01329da593d19fa3.zip | |
enhance(frontend): improve accounts management
Diffstat (limited to 'packages/frontend/src/i.ts')
| -rw-r--r-- | packages/frontend/src/i.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/frontend/src/i.ts b/packages/frontend/src/i.ts new file mode 100644 index 0000000000..aa84c6aa61 --- /dev/null +++ b/packages/frontend/src/i.ts @@ -0,0 +1,34 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { reactive } from 'vue'; +import * as Misskey from 'misskey-js'; +import { miLocalStorage } from '@/local-storage.js'; + +// TODO: 他のタブと永続化されたstateを同期 + +type AccountWithToken = Misskey.entities.MeDetailed & { token: string }; + +const accountData = miLocalStorage.getItem('account'); + +// TODO: 外部からはreadonlyに +export const $i = accountData ? reactive(JSON.parse(accountData) as AccountWithToken) : null; + +export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true); +export const iAmAdmin = $i != null && $i.isAdmin; + +export function signinRequired() { + if ($i == null) throw new Error('signin required'); + return $i; +} + +export let notesCount = $i == null ? 0 : $i.notesCount; +export function incNotesCount() { + notesCount++; +} + +if (_DEV_) { + (window as any).$i = $i; +} |