refactor (client): replace confusing expressions like $i != null

This commit is contained in:
naskya 2024-01-11 01:21:21 +00:00 committed by Kainoa Kanter
parent 7cd615f0f7
commit 8f956f4978
43 changed files with 184 additions and 186 deletions

View file

@ -12,9 +12,6 @@ import { reloadChannel, unisonReload } from "@/scripts/unison-reload";
export type Account = firefish.entities.MeDetailed; export type Account = firefish.entities.MeDetailed;
export const iAmModerator = $i != null && ($i.isAdmin || $i.isModerator);
export const iAmAdmin = $i?.isAdmin;
export async function signout() { export async function signout() {
waiting(); waiting();
localStorage.removeItem("account"); localStorage.removeItem("account");

View file

@ -8,7 +8,7 @@
<i :class="icon('ph-dots-three-outline')"></i> <i :class="icon('ph-dots-three-outline')"></i>
</button> </button>
<button <button
v-if="$i != null && $i.id != user.id" v-if="isSignedIn && $i.id != user.id"
v-tooltip="full ? null : `${state} ${user.name || user.username}`" v-tooltip="full ? null : `${state} ${user.name || user.username}`"
class="kpoogebi _button follow-button" class="kpoogebi _button follow-button"
:class="{ :class="{
@ -66,7 +66,7 @@ import type * as firefish from "firefish-js";
import * as os from "@/os"; import * as os from "@/os";
import { stream } from "@/stream"; import { stream } from "@/stream";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { getUserMenu } from "@/scripts/get-user-menu"; import { getUserMenu } from "@/scripts/get-user-menu";
import { useRouter } from "@/router"; import { useRouter } from "@/router";
import { vibrate } from "@/scripts/vibrate"; import { vibrate } from "@/scripts/vibrate";

View file

@ -35,9 +35,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { toUnicode } from "punycode"; import { toUnicode } from "punycode";
import {} from "vue";
import { host as localHost } from "@/config"; import { host as localHost } from "@/config";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
const props = defineProps<{ const props = defineProps<{
@ -53,7 +52,7 @@ const canonical =
const url = `/${canonical}`; const url = `/${canonical}`;
const isMe = const isMe =
$i && isSignedIn &&
`@${props.username}@${toUnicode(props.host)}` === `@${props.username}@${toUnicode(props.host)}` ===
`@${$i.username}@${toUnicode(localHost)}`.toLowerCase(); `@${$i.username}@${toUnicode(localHost)}`.toLowerCase();
</script> </script>

View file

@ -225,7 +225,7 @@
<XQuoteButton class="button" :note="appearNote" /> <XQuoteButton class="button" :note="appearNote" />
<button <button
v-if=" v-if="
$i != null && isSignedIn &&
isForeignLanguage && isForeignLanguage &&
translation == null translation == null
" "
@ -294,7 +294,7 @@ import { userPage } from "@/filters/user";
import * as os from "@/os"; import * as os from "@/os";
import { defaultStore, noteViewInterruptors } from "@/store"; import { defaultStore, noteViewInterruptors } from "@/store";
import { reactionPicker } from "@/scripts/reaction-picker"; import { reactionPicker } from "@/scripts/reaction-picker";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { getNoteMenu } from "@/scripts/get-note-menu"; import { getNoteMenu } from "@/scripts/get-note-menu";
import { useNoteCapture } from "@/scripts/use-note-capture"; import { useNoteCapture } from "@/scripts/use-note-capture";
@ -353,7 +353,7 @@ const reactButton = ref<HTMLElement>();
const appearNote = computed(() => const appearNote = computed(() =>
isRenote ? (note.value.renote as firefish.entities.Note) : note.value, isRenote ? (note.value.renote as firefish.entities.Note) : note.value,
); );
const isMyRenote = $i && $i.id === note.value.userId; const isMyRenote = isSignedIn && $i.id === note.value.userId;
const showContent = ref(false); const showContent = ref(false);
const isDeleted = ref(false); const isDeleted = ref(false);
const muted = ref( const muted = ref(

View file

@ -126,7 +126,7 @@
<XQuoteButton class="button" :note="appearNote" /> <XQuoteButton class="button" :note="appearNote" />
<button <button
v-if=" v-if="
$i != null && isSignedIn &&
isForeignLanguage && isForeignLanguage &&
translation == null translation == null
" "
@ -210,7 +210,7 @@ import { useRouter } from "@/router";
import { userPage } from "@/filters/user"; import { userPage } from "@/filters/user";
import * as os from "@/os"; import * as os from "@/os";
import { reactionPicker } from "@/scripts/reaction-picker"; import { reactionPicker } from "@/scripts/reaction-picker";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { useNoteCapture } from "@/scripts/use-note-capture"; import { useNoteCapture } from "@/scripts/use-note-capture";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";

View file

@ -16,7 +16,7 @@
<MkButton <MkButton
v-else-if=" v-else-if="
!showOnlyToRegister && !showOnlyToRegister &&
($i ? pushRegistrationInServer : pushSubscription) (isSignedIn ? pushRegistrationInServer : pushSubscription)
" "
type="button" type="button"
:primary="false" :primary="false"
@ -31,7 +31,7 @@
{{ i18n.ts.unsubscribePushNotification }} {{ i18n.ts.unsubscribePushNotification }}
</MkButton> </MkButton>
<MkButton <MkButton
v-else-if="$i && pushRegistrationInServer" v-else-if="isSignedIn && pushRegistrationInServer"
disabled disabled
:rounded="rounded" :rounded="rounded"
:inline="inline" :inline="inline"
@ -56,7 +56,7 @@
import { ref } from "vue"; import { ref } from "vue";
import { getAccounts } from "@/account"; import { getAccounts } from "@/account";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import MkButton from "@/components/MkButton.vue"; import MkButton from "@/components/MkButton.vue";
import { instance } from "@/instance"; import { instance } from "@/instance";
import { api, apiWithDialog, promiseDialog } from "@/os"; import { api, apiWithDialog, promiseDialog } from "@/os";
@ -147,7 +147,7 @@ async function unsubscribe() {
pushRegistrationInServer.value = undefined; pushRegistrationInServer.value = undefined;
if ($i && accounts.length >= 2) { if (isSignedIn && accounts.length >= 2) {
apiWithDialog("sw/unregister", { apiWithDialog("sw/unregister", {
i: $i.token, i: $i.token,
endpoint, endpoint,
@ -193,7 +193,12 @@ if (navigator.serviceWorker == null) {
pushSubscription.value = pushSubscription.value =
await registration.value.pushManager.getSubscription(); await registration.value.pushManager.getSubscription();
if (instance.swPublickey && "PushManager" in window && $i && $i.token) { if (
instance.swPublickey &&
"PushManager" in window &&
isSignedIn &&
$i.token
) {
supported.value = true; supported.value = true;
if (pushSubscription.value) { if (pushSubscription.value) {

View file

@ -28,7 +28,7 @@ import XDetails from "@/components/MkReactionsViewer.details.vue";
import XReactionIcon from "@/components/MkReactionIcon.vue"; import XReactionIcon from "@/components/MkReactionIcon.vue";
import * as os from "@/os"; import * as os from "@/os";
import { useTooltip } from "@/scripts/use-tooltip"; import { useTooltip } from "@/scripts/use-tooltip";
import { $i } from "@/reactiveAccount"; import { isSignedIn } from "@/reactiveAccount";
const props = defineProps<{ const props = defineProps<{
reaction: string; reaction: string;
@ -43,7 +43,7 @@ const emit = defineEmits<{
const buttonRef = ref<HTMLElement>(); const buttonRef = ref<HTMLElement>();
const canToggle = computed(() => !props.reaction.match(/@\w/) && $i); const canToggle = computed(() => isSignedIn && !props.reaction.match(/@\w/));
const toggleReaction = () => { const toggleReaction = () => {
if (!canToggle.value) return; if (!canToggle.value) return;

View file

@ -19,7 +19,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from "vue"; import { computed, ref } from "vue";
import type * as firefish from "firefish-js"; import type * as firefish from "firefish-js";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import XReaction from "@/components/MkReactionsViewer.reaction.vue"; import XReaction from "@/components/MkReactionsViewer.reaction.vue";
const props = defineProps<{ const props = defineProps<{
@ -30,7 +30,7 @@ const reactionsEl = ref<HTMLElement>();
const initialReactions = new Set(Object.keys(props.note.reactions)); const initialReactions = new Set(Object.keys(props.note.reactions));
const isMe = computed(() => $i && $i.id === props.note.userId); const isMe = computed(() => isSignedIn && $i.id === props.note.userId);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View file

@ -27,7 +27,7 @@ import Ripple from "@/components/MkRipple.vue";
import XDetails from "@/components/MkUsersTooltip.vue"; import XDetails from "@/components/MkUsersTooltip.vue";
import { pleaseLogin } from "@/scripts/please-login"; import { pleaseLogin } from "@/scripts/please-login";
import * as os from "@/os"; import * as os from "@/os";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { useTooltip } from "@/scripts/use-tooltip"; import { useTooltip } from "@/scripts/use-tooltip";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
@ -74,7 +74,7 @@ useTooltip(buttonRef, async (showing) => {
const hasRenotedBefore = ref(false); const hasRenotedBefore = ref(false);
if ($i != null) { if (isSignedIn) {
os.api("notes/renotes", { os.api("notes/renotes", {
noteId: props.note.id, noteId: props.note.id,
userId: $i.id, userId: $i.id,

View file

@ -33,7 +33,7 @@ import XNotes from "@/components/MkNotes.vue";
import MkInfo from "@/components/MkInfo.vue"; import MkInfo from "@/components/MkInfo.vue";
import { stream } from "@/stream"; import { stream } from "@/stream";
import * as sound from "@/scripts/sound"; import * as sound from "@/scripts/sound";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
@ -67,7 +67,7 @@ const prepend = (note) => {
emit("note"); emit("note");
if (props.sound) { if (props.sound) {
sound.play($i && note.userId === $i.id ? "noteMy" : "note"); sound.play(isSignedIn && note.userId === $i.id ? "noteMy" : "note");
} }
}; };

View file

@ -211,19 +211,15 @@ import MkPushNotificationAllowButton from "@/components/MkPushNotificationAllowB
import FormSwitch from "@/components/form/switch.vue"; import FormSwitch from "@/components/form/switch.vue";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { $i } from "@/reactiveAccount"; import { isModerator } from "@/reactiveAccount";
import { instance } from "@/instance"; import { instance } from "@/instance";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
const isLocalTimelineAvailable = const isLocalTimelineAvailable = !instance.disableLocalTimeline || isModerator;
!instance.disableLocalTimeline ||
($i != null && ($i.isModerator || $i.isAdmin));
const isRecommendedTimelineAvailable = const isRecommendedTimelineAvailable =
!instance.disableRecommendedTimeline || !instance.disableRecommendedTimeline || isModerator;
($i != null && ($i.isModerator || $i.isAdmin));
const isGlobalTimelineAvailable = const isGlobalTimelineAvailable =
!instance.disableGlobalTimeline || !instance.disableGlobalTimeline || isModerator;
($i != null && ($i.isModerator || $i.isAdmin));
const timelines = ["home"]; const timelines = ["home"];

View file

@ -8,7 +8,7 @@
:class="{ detailed }" :class="{ detailed }"
> >
<span <span
v-if="$i && $i.id != user.id && user.isFollowed" v-if="isSignedIn && $i.id !== user.id && user.isFollowed"
class="followed" class="followed"
>{{ i18n.ts.followsYou }}</span >{{ i18n.ts.followsYou }}</span
> >
@ -79,7 +79,10 @@
</div> </div>
<div class="buttons"> <div class="buttons">
<slot> <slot>
<MkFollowButton v-if="$i && user.id != $i.id" :user="user" /> <MkFollowButton
v-if="isSignedIn && user.id !== $i.id"
:user="user"
/>
</slot> </slot>
</div> </div>
</article> </article>
@ -94,6 +97,7 @@ import XShowMoreButton from "@/components/MkShowMoreButton.vue";
import MkNumber from "@/components/MkNumber.vue"; import MkNumber from "@/components/MkNumber.vue";
import { userPage } from "@/filters/user"; import { userPage } from "@/filters/user";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { $i, isSignedIn } from "@/reactiveAccount";
const props = defineProps<{ const props = defineProps<{
user: firefish.entities.UserDetailed; user: firefish.entities.UserDetailed;

View file

@ -40,7 +40,7 @@ import directives from "@/directives";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { fetchInstance, instance } from "@/instance"; import { fetchInstance, instance } from "@/instance";
import { alert, api, confirm, popup, post, toast } from "@/os"; import { alert, api, confirm, popup, post, toast } from "@/os";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { deviceKind } from "@/scripts/device-kind"; import { deviceKind } from "@/scripts/device-kind";
import { getAccountFromId } from "@/scripts/get-account-from-id"; import { getAccountFromId } from "@/scripts/get-account-from-id";
import { makeHotkey } from "@/scripts/hotkey"; import { makeHotkey } from "@/scripts/hotkey";
@ -274,7 +274,7 @@ function checkForSplash() {
} }
if ( if (
$i && isSignedIn &&
defaultStore.state.tutorial === -1 && defaultStore.state.tutorial === -1 &&
!["/announcements", "/announcements/"].includes(window.location.pathname) !["/announcements", "/announcements/"].includes(window.location.pathname)
) { ) {
@ -426,7 +426,7 @@ function checkForSplash() {
s: search, s: search,
}; };
if ($i) { if (isSignedIn) {
// only add post shortcuts if logged in // only add post shortcuts if logged in
hotkeys["p|n"] = post; hotkeys["p|n"] = post;

View file

@ -2,7 +2,7 @@ import { computed, reactive } from "vue";
import { ui } from "@/config"; import { ui } from "@/config";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import * as os from "@/os"; import * as os from "@/os";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import { search } from "@/scripts/search"; import { search } from "@/scripts/search";
import { unisonReload } from "@/scripts/unison-reload"; import { unisonReload } from "@/scripts/unison-reload";
@ -11,21 +11,21 @@ export const navbarItemDef = reactive({
notifications: { notifications: {
title: "notifications", title: "notifications",
icon: `${icon("ph-bell")}`, icon: `${icon("ph-bell")}`,
show: computed(() => $i != null), show: computed(() => isSignedIn),
indicated: computed(() => $i?.hasUnreadNotification), indicated: computed(() => $i?.hasUnreadNotification),
to: "/my/notifications", to: "/my/notifications",
}, },
messaging: { messaging: {
title: "messaging", title: "messaging",
icon: `${icon("ph-chats-teardrop")}`, icon: `${icon("ph-chats-teardrop")}`,
show: computed(() => $i != null), show: computed(() => isSignedIn),
indicated: computed(() => $i?.hasUnreadMessagingMessage), indicated: computed(() => $i?.hasUnreadMessagingMessage),
to: "/my/messaging", to: "/my/messaging",
}, },
drive: { drive: {
title: "drive", title: "drive",
icon: `${icon("ph-cloud")}`, icon: `${icon("ph-cloud")}`,
show: computed(() => $i != null), show: computed(() => isSignedIn),
to: "/my/drive", to: "/my/drive",
}, },
followRequests: { followRequests: {
@ -54,19 +54,19 @@ export const navbarItemDef = reactive({
lists: { lists: {
title: "lists", title: "lists",
icon: `${icon("ph-list-bullets")}`, icon: `${icon("ph-list-bullets")}`,
show: computed(() => $i != null), show: computed(() => isSignedIn),
to: "/my/lists", to: "/my/lists",
}, },
antennas: { antennas: {
title: "antennas", title: "antennas",
icon: `${icon("ph-flying-saucer")}`, icon: `${icon("ph-flying-saucer")}`,
show: computed(() => $i != null), show: computed(() => isSignedIn),
to: "/my/antennas", to: "/my/antennas",
}, },
favorites: { favorites: {
title: "favorites", title: "favorites",
icon: `${icon("ph-bookmark-simple")}`, icon: `${icon("ph-bookmark-simple")}`,
show: computed(() => $i != null), show: computed(() => isSignedIn),
to: "/my/favorites", to: "/my/favorites",
}, },
pages: { pages: {
@ -82,7 +82,7 @@ export const navbarItemDef = reactive({
clips: { clips: {
title: "clips", title: "clips",
icon: `${icon("ph-paperclip")}`, icon: `${icon("ph-paperclip")}`,
show: computed(() => $i != null), show: computed(() => isSignedIn),
to: "/my/clips", to: "/my/clips",
}, },
channels: { channels: {

View file

@ -190,7 +190,7 @@ import number from "@/filters/number";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { deviceKind } from "@/scripts/device-kind"; import { deviceKind } from "@/scripts/device-kind";
import { iAmModerator } from "@/account"; import { isModerator } from "@/reactiveAccount";
import { instance } from "@/instance"; import { instance } from "@/instance";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
@ -215,7 +215,7 @@ const tabs = ["overview", "emojis", "charts"];
const tab = ref(tabs[0]); const tab = ref(tabs[0]);
watch(tab, () => syncSlide(tabs.indexOf(tab.value))); watch(tab, () => syncSlide(tabs.indexOf(tab.value)));
if (iAmModerator) tabs.push("federation"); if (isModerator) tabs.push("federation");
const initStats = () => const initStats = () =>
os.api("stats", {}).then((res) => { os.api("stats", {}).then((res) => {
@ -242,7 +242,7 @@ const theTabs = [
}, },
]; ];
if (iAmModerator) { if (isModerator) {
theTabs.push({ theTabs.push({
key: "federation", key: "federation",
title: i18n.ts.federation, title: i18n.ts.federation,

View file

@ -119,7 +119,7 @@
</swiper-slide> </swiper-slide>
<swiper-slide> <swiper-slide>
<div v-if="info" class="_formRoot"> <div v-if="info" class="_formRoot">
<MkInfo v-if="!iAmAdmin" warn>{{ <MkInfo v-if="!isAdmin" warn>{{
i18n.ts.requireAdminForView i18n.ts.requireAdminForView
}}</MkInfo> }}</MkInfo>
<MkKeyValue <MkKeyValue
@ -172,14 +172,14 @@ import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { deviceKind } from "@/scripts/device-kind"; import { deviceKind } from "@/scripts/device-kind";
import { iAmAdmin, iAmModerator } from "@/account"; import { isAdmin, isModerator } from "@/reactiveAccount";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import "swiper/scss"; import "swiper/scss";
import "swiper/scss/virtual"; import "swiper/scss/virtual";
const tabs = ["overview"]; const tabs = ["overview"];
if (iAmModerator) tabs.push("ip"); if (isModerator) tabs.push("ip");
tabs.push("raw"); tabs.push("raw");
const tab = ref(tabs[0]); const tab = ref(tabs[0]);
watch(tab, () => syncSlide(tabs.indexOf(tab.value))); watch(tab, () => syncSlide(tabs.indexOf(tab.value)));
@ -238,7 +238,7 @@ const headerTabs = computed(() => [
title: i18n.ts.overview, title: i18n.ts.overview,
icon: `${icon("ph-info")}`, icon: `${icon("ph-info")}`,
}, },
iAmModerator isModerator
? { ? {
key: "ip", key: "ip",
title: "IP", title: "IP",

View file

@ -17,7 +17,7 @@
> >
<div class="_title"> <div class="_title">
<h3> <h3>
<span v-if="$i && !announcement.isRead"> <span v-if="isSignedIn && !announcement.isRead">
🆕&nbsp; 🆕&nbsp;
</span> </span>
{{ announcement.title }} {{ announcement.title }}
@ -36,7 +36,10 @@
:src="announcement.imageUrl" :src="announcement.imageUrl"
/> />
</div> </div>
<div v-if="$i && !announcement.isRead" class="_footer"> <div
v-if="isSignedIn && !announcement.isRead"
class="_footer"
>
<MkButton primary @click="read(announcement.id)" <MkButton primary @click="read(announcement.id)"
><i :class="icon('ph-check')"></i> ><i :class="icon('ph-check')"></i>
{{ i18n.ts.gotIt }}</MkButton {{ i18n.ts.gotIt }}</MkButton
@ -56,6 +59,7 @@ import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import { isSignedIn } from "@/reactiveAccount";
const pagination = { const pagination = {
endpoint: "announcements" as const, endpoint: "announcements" as const,

View file

@ -1,8 +1,8 @@
<template> <template>
<div v-if="$i && fetching" class=""> <div v-if="isSignedIn && fetching" class="">
<MkLoading /> <MkLoading />
</div> </div>
<div v-else-if="$i"> <div v-else-if="isSignedIn">
<XForm <XForm
v-if="state == 'waiting'" v-if="state == 'waiting'"
ref="form" ref="form"
@ -52,7 +52,7 @@ import MkSignin from "@/components/MkSignin.vue";
import MkKeyValue from "@/components/MkKeyValue.vue"; import MkKeyValue from "@/components/MkKeyValue.vue";
import * as os from "@/os"; import * as os from "@/os";
import { login } from "@/account"; import { login } from "@/account";
import { $i } from "@/reactiveAccount"; import { isSignedIn } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
const props = defineProps<{ const props = defineProps<{
@ -64,7 +64,7 @@ const fetching = ref(true);
const auth_code = ref(""); const auth_code = ref("");
onMounted(() => { onMounted(() => {
if (!$i) return; if (!isSignedIn) return;
os.api("auth/session/show", { token: props.token }) os.api("auth/session/show", { token: props.token })
.then((sess: any) => { .then((sess: any) => {

View file

@ -31,7 +31,7 @@
import { computed, provide, ref, watch } from "vue"; import { computed, provide, ref, watch } from "vue";
import type * as firefish from "firefish-js"; import type * as firefish from "firefish-js";
import XNotes from "@/components/MkNotes.vue"; import XNotes from "@/components/MkNotes.vue";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import * as os from "@/os"; import * as os from "@/os";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
@ -51,7 +51,7 @@ const pagination = {
}; };
const isOwned: boolean | null = computed<boolean | null>( const isOwned: boolean | null = computed<boolean | null>(
() => $i && clip.value && $i.id === clip.value.userId, () => isSignedIn && clip.value && $i.id === clip.value.userId,
); );
watch( watch(

View file

@ -17,7 +17,7 @@
<XUserList :pagination="pinnedUsers" /> <XUserList :pagination="pinnedUsers" />
</MkFolder> </MkFolder>
<MkFolder <MkFolder
v-if="$i != null" v-if="isSignedIn"
class="_gap" class="_gap"
persist-key="explore-popular-users" persist-key="explore-popular-users"
> >
@ -31,7 +31,7 @@
<XUserList :pagination="popularUsers" /> <XUserList :pagination="popularUsers" />
</MkFolder> </MkFolder>
<MkFolder <MkFolder
v-if="$i != null" v-if="isSignedIn"
class="_gap" class="_gap"
persist-key="explore-recently-updated-users" persist-key="explore-recently-updated-users"
> >
@ -45,7 +45,7 @@
<XUserList :pagination="recentlyUpdatedUsers" /> <XUserList :pagination="recentlyUpdatedUsers" />
</MkFolder> </MkFolder>
<MkFolder <MkFolder
v-if="$i != null" v-if="isSignedIn"
class="_gap" class="_gap"
persist-key="explore-recently-registered-users" persist-key="explore-recently-registered-users"
> >
@ -103,7 +103,7 @@
<XUserList :pagination="tagUsers" /> <XUserList :pagination="tagUsers" />
</MkFolder> </MkFolder>
<template v-if="tag == null && $i != null"> <template v-if="tag == null && isSignedIn">
<MkFolder class="_gap"> <MkFolder class="_gap">
<template #header <template #header
><i ><i
@ -146,7 +146,7 @@ import MkFolder from "@/components/MkFolder.vue";
import MkTab from "@/components/MkTab.vue"; import MkTab from "@/components/MkTab.vue";
import * as os from "@/os"; import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { $i } from "@/reactiveAccount"; import { isSignedIn } from "@/reactiveAccount";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
const props = defineProps<{ const props = defineProps<{

View file

@ -58,7 +58,9 @@
</div> </div>
<div class="other"> <div class="other">
<button <button
v-if="$i && $i.id === post.user.id" v-if="
isSignedIn && $i.id === post.user.id
"
v-tooltip="i18n.ts.edit" v-tooltip="i18n.ts.edit"
v-click-anime v-click-anime
class="_button" class="_button"
@ -161,6 +163,7 @@ import { definePageMetadata } from "@/scripts/page-metadata";
import { shareAvailable } from "@/scripts/share-available"; import { shareAvailable } from "@/scripts/share-available";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import { isSignedIn } from "@/reactiveAccount";
const router = useRouter(); const router = useRouter();
@ -350,8 +353,5 @@ definePageMetadata(
grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
grid-gap: 12px; grid-gap: 12px;
margin: var(--margin); margin: var(--margin);
> .post {
}
} }
</style> </style>

View file

@ -84,7 +84,7 @@
}}</template> }}</template>
</MkKeyValue> </MkKeyValue>
<FormSection v-if="iAmAdmin"> <FormSection v-if="isAdmin">
<template #label>Moderation</template> <template #label>Moderation</template>
<FormSuspense :p="init"> <FormSuspense :p="init">
<FormSwitch <FormSwitch
@ -346,11 +346,10 @@ import MkLink from "@/components/MkLink.vue";
import MkButton from "@/components/MkButton.vue"; import MkButton from "@/components/MkButton.vue";
import FormSection from "@/components/form/section.vue"; import FormSection from "@/components/form/section.vue";
import MkKeyValue from "@/components/MkKeyValue.vue"; import MkKeyValue from "@/components/MkKeyValue.vue";
import MkSelect from "@/components/form/select.vue";
import FormSwitch from "@/components/form/switch.vue"; import FormSwitch from "@/components/form/switch.vue";
import * as os from "@/os"; import * as os from "@/os";
import number from "@/filters/number"; import number from "@/filters/number";
import { iAmAdmin } from "@/account"; import { isAdmin } from "@/reactiveAccount";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { deviceKind } from "@/scripts/device-kind"; import { deviceKind } from "@/scripts/device-kind";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
@ -376,7 +375,7 @@ const props = defineProps<{
}>(); }>();
const tabs = ["overview"]; const tabs = ["overview"];
if (iAmAdmin) tabs.push("chart", "users", "raw"); if (isAdmin) tabs.push("chart", "users", "raw");
const tab = ref(tabs[0]); const tab = ref(tabs[0]);
watch(tab, () => syncSlide(tabs.indexOf(tab.value))); watch(tab, () => syncSlide(tabs.indexOf(tab.value)));
@ -389,7 +388,7 @@ const isSilenced = ref(false);
const faviconUrl = ref(null); const faviconUrl = ref(null);
const usersPagination = { const usersPagination = {
endpoint: iAmAdmin ? "admin/show-users" : ("users" as const), endpoint: isAdmin ? "admin/show-users" : ("users" as const),
limit: 10, limit: 10,
params: { params: {
sort: "+updatedAt", sort: "+updatedAt",
@ -400,7 +399,7 @@ const usersPagination = {
}; };
async function fetch() { async function fetch() {
if (iAmAdmin) if (isAdmin)
meta.value = (await os.api("admin/meta")) as AugmentedInstanceMetadata; meta.value = (await os.api("admin/meta")) as AugmentedInstanceMetadata;
instance.value = (await os.api("federation/show-instance", { instance.value = (await os.api("federation/show-instance", {
host: props.host, host: props.host,
@ -485,7 +484,7 @@ const theTabs = [
}, },
]; ];
if (iAmAdmin) { if (isAdmin) {
theTabs.push( theTabs.push(
{ {
key: "chart", key: "chart",

View file

@ -51,7 +51,9 @@
><i :class="icon('ph-code')" ><i :class="icon('ph-code')"
/></MkA> /></MkA>
<template <template
v-if="$i && $i.id === page.userId" v-if="
isSignedIn && $i.id === page.userId
"
> >
<MkA <MkA
v-tooltip="i18n.ts._pages.editPage" v-tooltip="i18n.ts._pages.editPage"
@ -159,7 +161,7 @@
</div> </div>
<!-- <div class="links"> <!-- <div class="links">
<MkA :to="`/@${username}/pages/${pageName}/view-source`" class="link">{{ i18n.ts._pages.viewSource }}</MkA> <MkA :to="`/@${username}/pages/${pageName}/view-source`" class="link">{{ i18n.ts._pages.viewSource }}</MkA>
<template v-if="$i && $i.id === page.userId"> <template v-if="isSignedIn && $i.id === page.userId">
<MkA :to="`/pages/edit/${page.id}`" class="link">{{ i18n.ts._pages.editThisPage }}</MkA> <MkA :to="`/pages/edit/${page.id}`" class="link">{{ i18n.ts._pages.editThisPage }}</MkA>
<button v-if="$i.pinnedPageId === page.id" class="link _textButton" @click="pin(false)">{{ i18n.ts.unpin }}</button> <button v-if="$i.pinnedPageId === page.id" class="link _textButton" @click="pin(false)">{{ i18n.ts.unpin }}</button>
<button v-else class="link _textButton" @click="pin(true)">{{ i18n.ts.pin }}</button> <button v-else class="link _textButton" @click="pin(true)">{{ i18n.ts.pin }}</button>
@ -213,6 +215,7 @@ import { definePageMetadata } from "@/scripts/page-metadata";
import { shareAvailable } from "@/scripts/share-available"; import { shareAvailable } from "@/scripts/share-available";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import { isSignedIn } from "@/reactiveAccount";
const props = defineProps<{ const props = defineProps<{
pageName: string; pageName: string;

View file

@ -159,13 +159,13 @@
<MkKeyValue oneline style="margin: 1em 0"> <MkKeyValue oneline style="margin: 1em 0">
<template #key>isModerator</template> <template #key>isModerator</template>
<template #value>{{ <template #value>{{
$i.isModerator ? i18n.ts.yes : i18n.ts.no isModerator ? i18n.ts.yes : i18n.ts.no
}}</template> }}</template>
</MkKeyValue> </MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0"> <MkKeyValue oneline style="margin: 1em 0">
<template #key>isAdmin</template> <template #key>isAdmin</template>
<template #value>{{ <template #value>{{
$i.isAdmin ? i18n.ts.yes : i18n.ts.no isAdmin ? i18n.ts.yes : i18n.ts.no
}}</template> }}</template>
</MkKeyValue> </MkKeyValue>
</FormSection> </FormSection>
@ -179,7 +179,7 @@ import MkKeyValue from "@/components/MkKeyValue.vue";
import * as os from "@/os"; import * as os from "@/os";
import number from "@/filters/number"; import number from "@/filters/number";
import bytes from "@/filters/bytes"; import bytes from "@/filters/bytes";
import { $i } from "@/reactiveAccount"; import { $i, isAdmin, isModerator } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";

View file

@ -85,15 +85,15 @@ import { defaultStore } from "@/store";
import MkChart from "@/components/MkChart.vue"; import MkChart from "@/components/MkChart.vue";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
const fetching = ref(true); const fetching = ref(true);
const usage = ref<any>(null); const usage = ref<any>(null);
const capacity = ref<any>(null); const capacity = ref<any>(null);
const uploadFolder = ref<any>(null); const uploadFolder = ref<any>(null);
const alwaysMarkNsfw = ref<boolean>($i != null && $i.alwaysMarkNsfw); const alwaysMarkNsfw = ref<boolean>(isSignedIn && $i.alwaysMarkNsfw);
const autoSensitive = ref<boolean>($i != null && $i.autoSensitive); const autoSensitive = ref<boolean>(isSignedIn && $i.autoSensitive);
const meterStyle = computed(() => { const meterStyle = computed(() => {
return { return {

View file

@ -65,7 +65,7 @@ import * as os from "@/os";
import { ColdDeviceStorage, defaultStore } from "@/store"; import { ColdDeviceStorage, defaultStore } from "@/store";
import { unisonReload } from "@/scripts/unison-reload"; import { unisonReload } from "@/scripts/unison-reload";
import { stream } from "@/stream"; import { stream } from "@/stream";
import { $i } from "@/reactiveAccount"; import { isSignedIn } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { host, version } from "@/config"; import { host, version } from "@/config";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
@ -163,7 +163,7 @@ interface Profile {
}; };
} }
const connection = $i && stream.useChannel("main"); const connection = isSignedIn && stream.useChannel("main");
const profiles = ref<Record<string, Profile> | null>(null); const profiles = ref<Record<string, Profile> | null>(null);

View file

@ -74,24 +74,28 @@ import * as os from "@/os";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { instance } from "@/instance"; import { instance } from "@/instance";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn, isModerator } from "@/reactiveAccount";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { deviceKind } from "@/scripts/device-kind"; import { deviceKind } from "@/scripts/device-kind";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import "swiper/scss"; import "swiper/scss";
import "swiper/scss/virtual"; import "swiper/scss/virtual";
if (defaultStore.reactiveState.tutorial.value !== -1) { if (isSignedIn && defaultStore.reactiveState.tutorial.value !== -1) {
os.popup(XTutorial, {}, {}, "closed"); os.popup(XTutorial, {}, {}, "closed");
} }
const isLocalTimelineAvailable = const isLocalTimelineAvailable =
!instance.disableLocalTimeline || (!instance.disableLocalTimeline &&
($i != null && ($i.isModerator || $i.isAdmin)); (isSignedIn || instance.enableGuestTimeline)) ||
const isRecommendedTimelineAvailable = !instance.disableRecommendedTimeline; isModerator;
const isSocialTimelineAvailable = isLocalTimelineAvailable && isSignedIn;
const isRecommendedTimelineAvailable =
!instance.disableRecommendedTimeline && isSignedIn;
const isGlobalTimelineAvailable = const isGlobalTimelineAvailable =
!instance.disableGlobalTimeline || (!instance.disableGlobalTimeline &&
($i != null && ($i.isModerator || $i.isAdmin)); (isSignedIn || instance.enableGuestTimeline)) ||
isModerator;
const keymap = { const keymap = {
t: focus, t: focus,
}; };

View file

@ -181,7 +181,7 @@
<FormSwitch <FormSwitch
v-if=" v-if="
user.host == null && user.host == null &&
$i.isAdmin && isAdmin &&
(moderator || !user.isAdmin) (moderator || !user.isAdmin)
" "
v-model="moderator" v-model="moderator"
@ -204,7 +204,7 @@
{{ i18n.ts.reflectMayTakeTime }} {{ i18n.ts.reflectMayTakeTime }}
<div class="_formBlock"> <div class="_formBlock">
<FormButton <FormButton
v-if="user.host == null && iAmModerator" v-if="user.host == null && isModerator"
inline inline
style="margin-bottom: 0.4rem" style="margin-bottom: 0.4rem"
@click="resetPassword" @click="resetPassword"
@ -212,14 +212,14 @@
{{ i18n.ts.resetPassword }}</FormButton {{ i18n.ts.resetPassword }}</FormButton
> >
<FormButton <FormButton
v-if="user.host == null && iAmModerator" v-if="user.host == null && isModerator"
inline inline
@click="sendModMail" @click="sendModMail"
><i :class="icon('ph-warning-diamond')"></i> ><i :class="icon('ph-warning-diamond')"></i>
{{ i18n.ts.sendModMail }}</FormButton {{ i18n.ts.sendModMail }}</FormButton
> >
<FormButton <FormButton
v-if="user.host == null && $i.isAdmin" v-if="user.host == null && isAdmin"
inline inline
danger danger
@click="delete2fa" @click="delete2fa"
@ -227,7 +227,7 @@
{{ i18n.ts.delete2fa }}</FormButton {{ i18n.ts.delete2fa }}</FormButton
> >
<FormButton <FormButton
v-if="user.host == null && $i.isAdmin" v-if="user.host == null && isAdmin"
inline inline
danger danger
@click="deletePasskeys" @click="deletePasskeys"
@ -235,7 +235,7 @@
{{ i18n.ts.deletePasskeys }}</FormButton {{ i18n.ts.deletePasskeys }}</FormButton
> >
<FormButton <FormButton
v-if="$i.isAdmin" v-if="isAdmin"
inline inline
primary primary
danger danger
@ -253,14 +253,14 @@
</FormTextarea> </FormTextarea>
<FormFolder class="_formBlock"> <FormFolder class="_formBlock">
<template #label>IP</template> <template #label>IP</template>
<MkInfo v-if="!iAmAdmin" warn>{{ <MkInfo v-if="!isAdmin" warn>{{
i18n.ts.requireAdminForView i18n.ts.requireAdminForView
}}</MkInfo> }}</MkInfo>
<MkInfo v-else <MkInfo v-else
>The date is the IP address was first >The date is the IP address was first
acknowledged.</MkInfo acknowledged.</MkInfo
> >
<template v-if="iAmAdmin && ips"> <template v-if="isAdmin && ips">
<div <div
v-for="record in ips" v-for="record in ips"
:key="record.ip" :key="record.ip"
@ -346,7 +346,7 @@
</div> </div>
</div> </div>
<div v-else-if="tab === 'raw'" class="_formRoot"> <div v-else-if="tab === 'raw'" class="_formRoot">
<MkObjectView v-if="info && $i.isAdmin" tall :value="info"> <MkObjectView v-if="info && isAdmin" tall :value="info">
</MkObjectView> </MkObjectView>
<MkObjectView tall :value="user"> </MkObjectView> <MkObjectView tall :value="user"> </MkObjectView>
@ -369,7 +369,6 @@ import FormButton from "@/components/MkButton.vue";
import FormInput from "@/components/form/input.vue"; import FormInput from "@/components/form/input.vue";
import FormFolder from "@/components/form/folder.vue"; import FormFolder from "@/components/form/folder.vue";
import MkKeyValue from "@/components/MkKeyValue.vue"; import MkKeyValue from "@/components/MkKeyValue.vue";
import MkSelect from "@/components/form/select.vue";
import FormSuspense from "@/components/form/suspense.vue"; import FormSuspense from "@/components/form/suspense.vue";
import MkFileListForAdmin from "@/components/MkFileListForAdmin.vue"; import MkFileListForAdmin from "@/components/MkFileListForAdmin.vue";
import MkInfo from "@/components/MkInfo.vue"; import MkInfo from "@/components/MkInfo.vue";
@ -378,7 +377,7 @@ import { url } from "@/config";
import { acct, userPage } from "@/filters/user"; import { acct, userPage } from "@/filters/user";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { iAmAdmin, iAmModerator } from "@/account"; import { isAdmin, isModerator } from "@/reactiveAccount";
import { instance } from "@/instance"; import { instance } from "@/instance";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
@ -407,7 +406,7 @@ const filesPagination = {
}; };
function createFetcher() { function createFetcher() {
if (iAmModerator) { if (isModerator) {
return () => return () =>
Promise.all([ Promise.all([
os.api("users/show", { os.api("users/show", {
@ -416,7 +415,7 @@ function createFetcher() {
os.api("admin/show-user", { os.api("admin/show-user", {
userId: props.userId, userId: props.userId,
}), }),
iAmAdmin isAdmin
? os.api("admin/get-user-ips", { ? os.api("admin/get-user-ips", {
userId: props.userId, userId: props.userId,
}) })
@ -640,7 +639,7 @@ const headerTabs = computed(() =>
title: i18n.ts.overview, title: i18n.ts.overview,
icon: `${icon("ph-info")}`, icon: `${icon("ph-info")}`,
}, },
iAmModerator isModerator
? { ? {
key: "moderation", key: "moderation",
title: i18n.ts.moderation, title: i18n.ts.moderation,

View file

@ -43,7 +43,7 @@
:user="user" :user="user"
:nowrap="true" :nowrap="true"
/> />
<div v-if="$i?.isModerator || $i?.isAdmin"> <div v-if="isModerator">
<span <span
v-if="user.isSilenced" v-if="user.isSilenced"
style=" style="
@ -67,8 +67,8 @@
</div> </div>
<span <span
v-if=" v-if="
$i && isSignedIn &&
$i.id != user.id && $i.id !== user.id &&
user.isFollowed user.isFollowed
" "
class="followed" class="followed"
@ -131,14 +131,14 @@
/> />
<span <span
v-if=" v-if="
$i && isSignedIn &&
$i.id != user.id && $i.id !== user.id &&
user.isFollowed user.isFollowed
" "
class="followed" class="followed"
>{{ i18n.ts.followsYou }}</span >{{ i18n.ts.followsYou }}</span
> >
<div v-if="$i?.isModerator || $i?.isAdmin"> <div v-if="isModerator">
<span <span
v-if="user.isSilenced" v-if="user.isSilenced"
style="color: var(--warn); padding: 5px" style="color: var(--warn); padding: 5px"
@ -339,7 +339,7 @@
/> />
</div> </div>
<MkInfo <MkInfo
v-else-if="$i && $i.id === user.id" v-else-if="isSignedIn && $i.id === user.id"
style="margin: 12px 0" style="margin: 12px 0"
>{{ i18n.ts.userPagePinTip }}</MkInfo >{{ i18n.ts.userPagePinTip }}</MkInfo
> >
@ -392,7 +392,7 @@ import { userPage } from "@/filters/user";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import * as os from "@/os"; import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn, isModerator } from "@/reactiveAccount";
import { host } from "@/config"; import { host } from "@/config";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";

View file

@ -37,7 +37,7 @@ import * as os from "@/os";
import { useRouter } from "@/router"; import { useRouter } from "@/router";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
const XHome = defineAsyncComponent(() => import("./home.vue")); const XHome = defineAsyncComponent(() => import("./home.vue"));
@ -88,7 +88,7 @@ const headerTabs = computed(() =>
title: i18n.ts.overview, title: i18n.ts.overview,
icon: `${icon("ph-user")}`, icon: `${icon("ph-user")}`,
}, },
...(($i && $i.id === user.value.id) || ...((isSignedIn && $i.id === user.value.id) ||
user.value.publicReactions user.value.publicReactions
? [ ? [
{ {

View file

@ -4,7 +4,7 @@ import type { Ref } from "vue";
import { onUnmounted, ref, watch } from "vue"; import { onUnmounted, ref, watch } from "vue";
import { api } from "./os"; import { api } from "./os";
import { stream } from "./stream"; import { stream } from "./stream";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
type StateDef = Record< type StateDef = Record<
string, string,
@ -16,7 +16,7 @@ type StateDef = Record<
type ArrayElement<A> = A extends readonly (infer T)[] ? T : never; type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;
const connection = $i && stream.useChannel("main"); const connection = isSignedIn && stream.useChannel("main");
export class Storage<T extends StateDef> { export class Storage<T extends StateDef> {
public readonly key: string; public readonly key: string;
@ -42,12 +42,12 @@ export class Storage<T extends StateDef> {
const deviceState = JSON.parse( const deviceState = JSON.parse(
localStorage.getItem(this.keyForLocalStorage) || "{}", localStorage.getItem(this.keyForLocalStorage) || "{}",
); );
const deviceAccountState = $i const deviceAccountState = isSignedIn
? JSON.parse( ? JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::${$i.id}`) || "{}", localStorage.getItem(`${this.keyForLocalStorage}::${$i.id}`) || "{}",
) )
: {}; : {};
const registryCache = $i const registryCache = isSignedIn
? JSON.parse( ? JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::cache::${$i.id}`) || localStorage.getItem(`${this.keyForLocalStorage}::cache::${$i.id}`) ||
"{}", "{}",
@ -64,7 +64,7 @@ export class Storage<T extends StateDef> {
state[k] = deviceState[k]; state[k] = deviceState[k];
} else if ( } else if (
v.where === "account" && v.where === "account" &&
$i && isSignedIn &&
Object.prototype.hasOwnProperty.call(registryCache, k) Object.prototype.hasOwnProperty.call(registryCache, k)
) { ) {
state[k] = registryCache[k]; state[k] = registryCache[k];
@ -84,7 +84,7 @@ export class Storage<T extends StateDef> {
this.state = state as any; this.state = state as any;
this.reactiveState = reactiveState as any; this.reactiveState = reactiveState as any;
if ($i) { if (isSignedIn) {
// なぜかsetTimeoutしないとapi関数内でエラーになる(おそらく循環参照してることに原因がありそう) // なぜかsetTimeoutしないとapi関数内でエラーになる(おそらく循環参照してることに原因がありそう)
window.setTimeout(() => { window.setTimeout(() => {
api("i/registry/get-all", { scope: ["client", this.key] }).then( api("i/registry/get-all", { scope: ["client", this.key] }).then(
@ -168,7 +168,7 @@ export class Storage<T extends StateDef> {
break; break;
} }
case "deviceAccount": { case "deviceAccount": {
if ($i == null) break; if (!isSignedIn) break;
const deviceAccountState = JSON.parse( const deviceAccountState = JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::${$i.id}`) || "{}", localStorage.getItem(`${this.keyForLocalStorage}::${$i.id}`) || "{}",
); );
@ -180,7 +180,7 @@ export class Storage<T extends StateDef> {
break; break;
} }
case "account": { case "account": {
if ($i == null) break; if (!isSignedIn) break;
const cache = JSON.parse( const cache = JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::cache::${$i.id}`) || localStorage.getItem(`${this.keyForLocalStorage}::cache::${$i.id}`) ||
"{}", "{}",

View file

@ -7,3 +7,7 @@ const accountData = localStorage.getItem("account");
export const $i = accountData export const $i = accountData
? reactive(JSON.parse(accountData) as Account) ? reactive(JSON.parse(accountData) as Account)
: null; : null;
export const isSignedIn = $i != null;
export const isModerator = $i != null && ($i.isModerator || $i.isAdmin);
export const isAdmin = $i != null && $i.isAdmin;

View file

@ -1,21 +1,9 @@
import type { AsyncComponentLoader } from "vue"; import type { AsyncComponentLoader } from "vue";
import { defineAsyncComponent, inject } from "vue"; import { defineAsyncComponent, inject } from "vue";
import { iAmModerator } from "@/account"; import { $i, isModerator } from "@/reactiveAccount";
import { Router } from "@/nirax"; import { Router } from "@/nirax";
import MkError from "@/pages/_error_.vue"; import MkError from "@/pages/_error_.vue";
import MkLoading from "@/pages/_loading_.vue"; import MkLoading from "@/pages/_loading_.vue";
import { $i } from "@/reactiveAccount";
// import { api } from "@/os";
// function getGuestTimelineStatus() {
// api("meta", {
// detail: false,
// }).then((meta) => {
// return meta.enableGuestTimeline;
// });
// }
// const guestTimeline = getGuestTimelineStatus();
const page = (loader: AsyncComponentLoader<any>) => const page = (loader: AsyncComponentLoader<any>) =>
defineAsyncComponent({ defineAsyncComponent({
@ -430,13 +418,13 @@ export const routes = [
}, },
{ {
path: "/admin/file/:fileId", path: "/admin/file/:fileId",
component: iAmModerator component: isModerator
? page(() => import("./pages/admin-file.vue")) ? page(() => import("./pages/admin-file.vue"))
: page(() => import("./pages/not-found.vue")), : page(() => import("./pages/not-found.vue")),
}, },
{ {
path: "/admin", path: "/admin",
component: iAmModerator component: isModerator
? page(() => import("./pages/admin/index.vue")) ? page(() => import("./pages/admin/index.vue"))
: page(() => import("./pages/not-found.vue")), : page(() => import("./pages/not-found.vue")),
children: [ children: [

View file

@ -1,7 +1,7 @@
import type { Ref } from "vue"; import type { Ref } from "vue";
import { defineAsyncComponent } from "vue"; import { defineAsyncComponent } from "vue";
import type * as firefish from "firefish-js"; import type * as firefish from "firefish-js";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn, isModerator } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { instance } from "@/instance"; import { instance } from "@/instance";
import * as os from "@/os"; import * as os from "@/os";
@ -217,18 +217,18 @@ export function getNoteMenu(props: {
props.isDeleted.value = true; props.isDeleted.value = true;
} }
async function promote(): Promise<void> { // async function promote(): Promise<void> {
const { canceled, result: days } = await os.inputNumber({ // const { canceled, result: days } = await os.inputNumber({
title: i18n.ts.numberOfDays, // title: i18n.ts.numberOfDays,
}); // });
if (canceled) return; // if (canceled) return;
os.apiWithDialog("admin/promo/create", { // os.apiWithDialog("admin/promo/create", {
noteId: appearNote.id, // noteId: appearNote.id,
expiresAt: Date.now() + 86400000 * days, // expiresAt: Date.now() + 86400000 * days,
}); // });
} // }
function share(): void { function share(): void {
navigator.share({ navigator.share({
@ -270,13 +270,12 @@ export function getNoteMenu(props: {
} }
let menu; let menu;
if ($i) { if (isSignedIn) {
const statePromise = os.api("notes/state", { const statePromise = os.api("notes/state", {
noteId: appearNote.id, noteId: appearNote.id,
}); });
const isAppearAuthor = appearNote.userId === $i.id; const isAppearAuthor = appearNote.userId === $i.id;
const isModerator = $i.isAdmin || $i.isModerator;
menu = [ menu = [
...(props.currentClipPage?.value.userId === $i.id ...(props.currentClipPage?.value.userId === $i.id
@ -397,7 +396,7 @@ export function getNoteMenu(props: {
], ],
}, },
/* /*
...($i.isModerator || $i.isAdmin ? [ ...(isModerator ? [
null, null,
{ {
icon: `${icon('ph-megaphone-simple')}`, icon: `${icon('ph-megaphone-simple')}`,

View file

@ -5,15 +5,12 @@ import copyToClipboard from "@/scripts/copy-to-clipboard";
import { host } from "@/config"; import { host } from "@/config";
import * as os from "@/os"; import * as os from "@/os";
import { userActions } from "@/store"; import { userActions } from "@/store";
import { iAmModerator } from "@/account"; import { $i, isModerator, isSignedIn } from "@/reactiveAccount";
import { $i } from "@/reactiveAccount";
import { mainRouter } from "@/router"; import { mainRouter } from "@/router";
import type { Router } from "@/nirax"; import type { Router } from "@/nirax";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
export function getUserMenu(user, router: Router = mainRouter) { export function getUserMenu(user, router: Router = mainRouter) {
const meId = $i ? $i.id : null;
async function pushList() { async function pushList() {
const t = i18n.ts.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく const t = i18n.ts.selectList; // なぜか後で参照すると null になるので最初にメモリに確保しておく
const lists = await os.api("users/lists/list"); const lists = await os.api("users/lists/list");
@ -282,7 +279,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
os.post({ specified: user }); os.post({ specified: user });
}, },
}, },
meId !== user.id $i.id !== user.id
? { ? {
type: "link", type: "link",
icon: `${icon("ph-chats-teardrop")}`, icon: `${icon("ph-chats-teardrop")}`,
@ -305,7 +302,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
text: i18n.ts.addToList, text: i18n.ts.addToList,
action: pushList, action: pushList,
}, },
meId !== user.id $i.id !== user.id
? { ? {
icon: `${icon("ph-users-three")}`, icon: `${icon("ph-users-three")}`,
text: i18n.ts.inviteToGroup, text: i18n.ts.inviteToGroup,
@ -320,7 +317,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
}, },
] as any; ] as any;
if ($i && meId !== user.id) { if (isSignedIn && $i.id !== user.id) {
menu = menu.concat([ menu = menu.concat([
{ {
icon: user.isMuted ? "ph-eye ph-lg" : "ph-eye-slash ph-lg", icon: user.isMuted ? "ph-eye ph-lg" : "ph-eye-slash ph-lg",
@ -354,7 +351,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
}, },
]); ]);
if (iAmModerator) { if (isModerator) {
menu = menu.concat([ menu = menu.concat([
null, null,
{ {
@ -371,7 +368,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
} }
} }
if ($i && meId === user.id) { if (isSignedIn && $i.id === user.id) {
menu = menu.concat([ menu = menu.concat([
null, null,
{ {

View file

@ -1,11 +1,11 @@
import { defineAsyncComponent } from "vue"; import { defineAsyncComponent } from "vue";
import { $i } from "@/reactiveAccount"; import { isSignedIn } from "@/reactiveAccount";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { popup } from "@/os"; import { popup } from "@/os";
import { vibrate } from "@/scripts/vibrate"; import { vibrate } from "@/scripts/vibrate";
export function pleaseLogin(path?: string) { export function pleaseLogin(path?: string) {
if ($i) return; if (isSignedIn) return;
vibrate(100); vibrate(100);
popup( popup(

View file

@ -2,7 +2,7 @@ import type { Ref } from "vue";
import { onUnmounted } from "vue"; import { onUnmounted } from "vue";
import type * as firefish from "firefish-js"; import type * as firefish from "firefish-js";
import { stream } from "@/stream"; import { stream } from "@/stream";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import * as os from "@/os"; import * as os from "@/os";
export function useNoteCapture(props: { export function useNoteCapture(props: {
@ -11,7 +11,7 @@ export function useNoteCapture(props: {
isDeletedRef: Ref<boolean>; isDeletedRef: Ref<boolean>;
}) { }) {
const note = props.note; const note = props.note;
const connection = $i ? stream : null; const connection = isSignedIn ? stream : null;
async function onStreamNoteUpdated(noteData): Promise<void> { async function onStreamNoteUpdated(noteData): Promise<void> {
const { type, id, body } = noteData; const { type, id, body } = noteData;
@ -34,7 +34,7 @@ export function useNoteCapture(props: {
note.value.reactions[reaction] = currentCount + 1; note.value.reactions[reaction] = currentCount + 1;
if ($i && body.userId === $i.id) { if (isSignedIn && body.userId === $i.id) {
note.value.myReaction = reaction; note.value.myReaction = reaction;
} }
break; break;
@ -48,7 +48,7 @@ export function useNoteCapture(props: {
note.value.reactions[reaction] = Math.max(0, currentCount - 1); note.value.reactions[reaction] = Math.max(0, currentCount - 1);
if ($i && body.userId === $i.id) { if (isSignedIn && body.userId === $i.id) {
note.value.myReaction = undefined; note.value.myReaction = undefined;
} }
break; break;
@ -62,7 +62,7 @@ export function useNoteCapture(props: {
choices[choice] = { choices[choice] = {
...choices[choice], ...choices[choice],
votes: choices[choice].votes + 1, votes: choices[choice].votes + 1,
...($i && body.userId === $i.id ...(isSignedIn && body.userId === $i.id
? { ? {
isVoted: true, isVoted: true,
} }

View file

@ -1,15 +1,15 @@
import type { Theme } from "./scripts/theme"; import type { Theme } from "./scripts/theme";
import { api } from "@/os"; import { api } from "@/os";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
const lsCacheKey = $i ? `themes:${$i.id}` : ""; const lsCacheKey = isSignedIn ? `themes:${$i.id}` : "";
export function getThemes(): Theme[] { export function getThemes(): Theme[] {
return JSON.parse(localStorage.getItem(lsCacheKey) || "[]"); return JSON.parse(localStorage.getItem(lsCacheKey) || "[]");
} }
export async function fetchThemes(): Promise<void> { export async function fetchThemes(): Promise<void> {
if ($i == null) return; if (!isSignedIn) return;
try { try {
const themes = await api("i/registry/get", { const themes = await api("i/registry/get", {

View file

@ -22,7 +22,7 @@ import { swInject } from "./sw-inject";
import { popup, popups } from "@/os"; import { popup, popups } from "@/os";
import { uploads } from "@/scripts/upload"; import { uploads } from "@/scripts/upload";
import * as sound from "@/scripts/sound"; import * as sound from "@/scripts/sound";
import { $i } from "@/reactiveAccount"; import { $i, isSignedIn } from "@/reactiveAccount";
import { stream } from "@/stream"; import { stream } from "@/stream";
const XStreamIndicator = defineAsyncComponent( const XStreamIndicator = defineAsyncComponent(
@ -55,7 +55,7 @@ const onNotification = (notification) => {
sound.play("notification"); sound.play("notification");
}; };
if ($i) { if (isSignedIn) {
const connection = stream.useChannel("main", null, "UI"); const connection = stream.useChannel("main", null, "UI");
connection.on("notification", onNotification); connection.on("notification", onNotification);

View file

@ -71,7 +71,7 @@
</template> </template>
<div class="divider"></div> <div class="divider"></div>
<MkA <MkA
v-if="$i.isAdmin || $i.isModerator" v-if="isModerator"
v-click-anime v-click-anime
class="item" class="item"
active-class="active" active-class="active"
@ -130,6 +130,7 @@ import { computed, defineAsyncComponent, toRef } from "vue";
import * as os from "@/os"; import * as os from "@/os";
import { navbarItemDef } from "@/navbar"; import { navbarItemDef } from "@/navbar";
import { openAccountMenu as openAccountMenu_ } from "@/account"; import { openAccountMenu as openAccountMenu_ } from "@/account";
import { $i, isModerator } from "@/reactiveAccount";
import { openHelpMenu_ } from "@/scripts/helpMenu"; import { openHelpMenu_ } from "@/scripts/helpMenu";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";

View file

@ -72,7 +72,7 @@
</template> </template>
<div class="divider"></div> <div class="divider"></div>
<MkA <MkA
v-if="$i.isAdmin || $i.isModerator" v-if="isModerator"
v-click-anime v-click-anime
v-tooltip.noDelay.right="i18n.ts.controlPanel" v-tooltip.noDelay.right="i18n.ts.controlPanel"
class="item _button" class="item _button"
@ -150,7 +150,7 @@ import { computed, defineAsyncComponent, ref, watch } from "vue";
import * as os from "@/os"; import * as os from "@/os";
import { navbarItemDef } from "@/navbar"; import { navbarItemDef } from "@/navbar";
import { openAccountMenu as openAccountMenu_ } from "@/account"; import { openAccountMenu as openAccountMenu_ } from "@/account";
import { $i } from "@/reactiveAccount"; import { $i, isAdmin, isModerator } from "@/reactiveAccount";
import { openHelpMenu_ } from "@/scripts/helpMenu"; import { openHelpMenu_ } from "@/scripts/helpMenu";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
@ -195,7 +195,7 @@ const noEmailServer = !instance.enableEmail;
const thereIsUnresolvedAbuseReport = ref(false); const thereIsUnresolvedAbuseReport = ref(false);
const updateAvailable = ref(false); const updateAvailable = ref(false);
if ($i?.isAdmin) { if (isAdmin) {
os.api("admin/abuse-user-reports", { os.api("admin/abuse-user-reports", {
state: "unresolved", state: "unresolved",
limit: 1, limit: 1,

View file

@ -241,7 +241,7 @@ watch(route, () => {
const columns = deckStore.reactiveState.columns; const columns = deckStore.reactiveState.columns;
const layout = deckStore.reactiveState.layout; const layout = deckStore.reactiveState.layout;
const menuIndicated = computed(() => { const menuIndicated = computed(() => {
if ($i == null) return false; if (!isSignedIn) return false;
for (const def in navbarItemDef) { for (const def in navbarItemDef) {
if (navbarItemDef[def].indicated) return true; if (navbarItemDef[def].indicated) return true;
} }

View file

@ -50,7 +50,7 @@ import type { Column } from "./deck-store";
import { removeColumn, updateColumn } from "./deck-store"; import { removeColumn, updateColumn } from "./deck-store";
import XTimeline from "@/components/MkTimeline.vue"; import XTimeline from "@/components/MkTimeline.vue";
import * as os from "@/os"; import * as os from "@/os";
import { $i } from "@/reactiveAccount"; import { isSignedIn, isModerator } from "@/reactiveAccount";
import { instance } from "@/instance"; import { instance } from "@/instance";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
@ -72,10 +72,9 @@ const columnActive = ref(true);
onMounted(() => { onMounted(() => {
if (props.column.tl == null) { if (props.column.tl == null) {
setType(); setType();
} else if ($i) { } else if (isSignedIn) {
disabled.value = disabled.value =
!$i.isModerator && !isModerator &&
!$i.isAdmin &&
((instance.disableLocalTimeline && ((instance.disableLocalTimeline &&
["local", "social"].includes(props.column.tl)) || ["local", "social"].includes(props.column.tl)) ||
(instance.disableRecommendedTimeline && (instance.disableRecommendedTimeline &&