Added docs to $i, iAmModerator, iAmAdmin.
This commit is contained in:
parent
a11b77a415
commit
a2dc196a07
|
@ -22,11 +22,35 @@ type Account = Misskey.entities.MeDetailed & { token: string };
|
||||||
const accountData = miLocalStorage.getItem('account');
|
const accountData = miLocalStorage.getItem('account');
|
||||||
|
|
||||||
// TODO: 外部からはreadonlyに
|
// TODO: 外部からはreadonlyに
|
||||||
|
/**
|
||||||
|
* Reactive state for the current account. "I" as in "I am logged in".
|
||||||
|
* Initialized from local storage if available, otherwise null.
|
||||||
|
*
|
||||||
|
* @type {Account | null}
|
||||||
|
*/
|
||||||
export const $i = accountData ? reactive(JSON.parse(accountData) as Account) : null;
|
export const $i = accountData ? reactive(JSON.parse(accountData) as Account) : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the current account is a moderator.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true);
|
export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the current account is an administrator.
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
export const iAmAdmin = $i != null && $i.isAdmin;
|
export const iAmAdmin = $i != null && $i.isAdmin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether it is necessary to sign in; checks if the current
|
||||||
|
* account is null and throws an error if so.
|
||||||
|
*
|
||||||
|
* @throws {Error} If the current account is null
|
||||||
|
* @returns {Account} The current account
|
||||||
|
*/
|
||||||
export function signinRequired() {
|
export function signinRequired() {
|
||||||
if ($i == null) throw new Error('signin required');
|
if ($i == null) throw new Error('signin required');
|
||||||
return $i;
|
return $i;
|
||||||
|
|
Loading…
Reference in a new issue