refactor: make isSignedIn a function

This commit is contained in:
Lhcfl 2024-04-22 10:32:41 +08:00
parent 9acd130a22
commit c5a344c2a0
34 changed files with 86 additions and 84 deletions

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="!hideFollowButton && isSignedIn && me!.id != user.id" v-if="!hideFollowButton && isSignedIn(me) && me!.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="{

View file

@ -51,7 +51,7 @@ const canonical =
const url = `/${canonical}`; const url = `/${canonical}`;
const isMe = const isMe =
isSignedIn && isSignedIn(me) &&
`@${props.username}@${toUnicode(props.host)}`.toLowerCase() === `@${props.username}@${toUnicode(props.host)}`.toLowerCase() ===
`@${me!.username}@${toUnicode(localHost)}`.toLowerCase(); `@${me!.username}@${toUnicode(localHost)}`.toLowerCase();
</script> </script>

View file

@ -235,7 +235,7 @@
<XQuoteButton class="button" :note="appearNote" /> <XQuoteButton class="button" :note="appearNote" />
<button <button
v-if=" v-if="
isSignedIn && isSignedIn(me) &&
isForeignLanguage && isForeignLanguage &&
translation == null translation == null
" "
@ -370,7 +370,7 @@ const reactButton = ref<HTMLElement | null>(null);
const appearNote = computed(() => const appearNote = computed(() =>
isRenote ? (note.value.renote as NoteType) : note.value, isRenote ? (note.value.renote as NoteType) : note.value,
); );
const isMyRenote = isSignedIn && me!.id === note.value.userId; const isMyRenote = isSignedIn(me) && me!.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

@ -127,7 +127,7 @@
<XQuoteButton class="button" :note="appearNote" /> <XQuoteButton class="button" :note="appearNote" />
<button <button
v-if=" v-if="
isSignedIn && isSignedIn(me) &&
isForeignLanguage && isForeignLanguage &&
translation == null translation == null
" "

View file

@ -16,7 +16,7 @@
<MkButton <MkButton
v-else-if=" v-else-if="
!showOnlyToRegister && !showOnlyToRegister &&
(isSignedIn ? pushRegistrationInServer : pushSubscription) (isSignedIn(me) ? 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="isSignedIn && pushRegistrationInServer" v-else-if="isSignedIn(me) && pushRegistrationInServer"
disabled disabled
:rounded="rounded" :rounded="rounded"
:inline="inline" :inline="inline"
@ -142,7 +142,7 @@ async function unsubscribe() {
pushRegistrationInServer.value = undefined; pushRegistrationInServer.value = undefined;
if (isSignedIn && accounts.length >= 2) { if (isSignedIn(me) && accounts.length >= 2) {
apiWithDialog("sw/unregister", { apiWithDialog("sw/unregister", {
i: me.token, i: me.token,
endpoint, endpoint,
@ -189,7 +189,7 @@ if (navigator.serviceWorker == null) {
if ( if (
instance.swPublickey && instance.swPublickey &&
"PushManager" in window && "PushManager" in window &&
isSignedIn && isSignedIn(me) &&
me.token me.token
) { ) {
supported.value = true; supported.value = true;

View file

@ -23,12 +23,12 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from "vue"; import { computed, ref } from "vue";
import type { entitites } from "firefish-js"; import type { entities } from "firefish-js";
import XDetails from "@/components/MkReactionsViewer.details.vue"; 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 { isSignedIn } from "@/me"; import { isSignedIn, me } from "@/me";
const props = defineProps<{ const props = defineProps<{
reaction: string; reaction: string;
@ -43,7 +43,9 @@ const emit = defineEmits<{
const buttonRef = ref<HTMLElement>(); const buttonRef = ref<HTMLElement>();
const canToggle = computed(() => isSignedIn && !props.reaction.match(/@\w/)); const canToggle = computed(
() => isSignedIn(me) && !props.reaction.match(/@\w/),
);
const toggleReaction = () => { const toggleReaction = () => {
if (!canToggle.value) return; if (!canToggle.value) return;

View file

@ -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(() => isSignedIn && me.id === props.note.userId); const isMe = computed(() => isSignedIn(me) && me.id === props.note.userId);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View file

@ -74,7 +74,7 @@ useTooltip(buttonRef, async (showing) => {
const hasRenotedBefore = ref(false); const hasRenotedBefore = ref(false);
if (isSignedIn) { if (isSignedIn(me)) {
os.api("notes/renotes", { os.api("notes/renotes", {
noteId: props.note.id, noteId: props.note.id,
userId: me!.id, userId: me!.id,

View file

@ -1,6 +1,6 @@
<template> <template>
<MkInfo <MkInfo
v-if="tlHint && !tlHintClosed && isSignedIn" v-if="tlHint && !tlHintClosed && isSignedIn(me)"
:closeable="true" :closeable="true"
class="_gap" class="_gap"
@close="closeHint" @close="closeHint"
@ -120,7 +120,7 @@ const prepend = (note: entities.Note) => {
emit("note"); emit("note");
if (props.sound) { if (props.sound) {
sound.play(isSignedIn && note.userId === me?.id ? "noteMy" : "note"); sound.play(isSignedIn(me) && note.userId === me?.id ? "noteMy" : "note");
} }
}; };

View file

@ -8,7 +8,7 @@
:class="{ detailed }" :class="{ detailed }"
> >
<span <span
v-if="isSignedIn && me.id !== user.id && user.isFollowed" v-if="isSignedIn(me) && me.id !== user.id && user.isFollowed"
class="followed" class="followed"
>{{ i18n.ts.followsYou }}</span >{{ i18n.ts.followsYou }}</span
> >
@ -80,7 +80,7 @@
<div class="buttons"> <div class="buttons">
<slot> <slot>
<MkFollowButton <MkFollowButton
v-if="isSignedIn && user.id !== me.id" v-if="isSignedIn(me) && user.id !== me.id"
:user="user" :user="user"
/> />
</slot> </slot>

View file

@ -262,7 +262,7 @@ function checkForSplash() {
} }
if ( if (
isSignedIn && isSignedIn(me) &&
defaultStore.state.tutorial === -1 && defaultStore.state.tutorial === -1 &&
!["/announcements", "/announcements/"].includes(window.location.pathname) !["/announcements", "/announcements/"].includes(window.location.pathname)
) { ) {
@ -417,7 +417,7 @@ function checkForSplash() {
s: search, s: search,
}; };
if (isSignedIn) { if (isSignedIn(me)) {
// only add post shortcuts if logged in // only add post shortcuts if logged in
hotkeys["p|n"] = post; hotkeys["p|n"] = post;

View file

@ -8,7 +8,7 @@ export const me = accountData
? reactive(JSON.parse(accountData) as Account) ? reactive(JSON.parse(accountData) as Account)
: null; : null;
export const isSignedIn = me != null; export const isSignedIn = (i: typeof me): i is Account => i != null;
export const isModerator = me != null && (me.isModerator || me.isAdmin); export const isModerator = me != null && (me.isModerator || me.isAdmin);
export const isEmojiMod = isModerator || me?.emojiModPerm !== "unauthorized"; export const isEmojiMod = isModerator || me?.emojiModPerm !== "unauthorized";
export const isAdmin = me?.isAdmin; export const isAdmin = me?.isAdmin;

View file

@ -11,21 +11,21 @@ export const navbarItemDef = reactive({
notifications: { notifications: {
title: "notifications", title: "notifications",
icon: `${icon("ph-bell")}`, icon: `${icon("ph-bell")}`,
show: computed(() => isSignedIn), show: computed(() => isSignedIn(me)),
indicated: computed(() => me?.hasUnreadNotification), indicated: computed(() => me?.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(() => isSignedIn), show: computed(() => isSignedIn(me)),
indicated: computed(() => me?.hasUnreadMessagingMessage), indicated: computed(() => me?.hasUnreadMessagingMessage),
to: "/my/messaging", to: "/my/messaging",
}, },
drive: { drive: {
title: "drive", title: "drive",
icon: `${icon("ph-cloud")}`, icon: `${icon("ph-cloud")}`,
show: computed(() => isSignedIn), show: computed(() => isSignedIn(me)),
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(() => isSignedIn), show: computed(() => isSignedIn(me)),
to: "/my/lists", to: "/my/lists",
}, },
antennas: { antennas: {
title: "antennas", title: "antennas",
icon: `${icon("ph-flying-saucer")}`, icon: `${icon("ph-flying-saucer")}`,
show: computed(() => isSignedIn), show: computed(() => isSignedIn(me)),
to: "/my/antennas", to: "/my/antennas",
}, },
favorites: { favorites: {
title: "favorites", title: "favorites",
icon: `${icon("ph-bookmark-simple")}`, icon: `${icon("ph-bookmark-simple")}`,
show: computed(() => isSignedIn), show: computed(() => isSignedIn(me)),
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(() => isSignedIn), show: computed(() => isSignedIn(me)),
to: "/my/clips", to: "/my/clips",
}, },
channels: { channels: {

View file

@ -17,7 +17,7 @@
> >
<div class="_title"> <div class="_title">
<h3> <h3>
<span v-if="isSignedIn && !announcement.isRead"> <span v-if="isSignedIn(me) && !announcement.isRead">
🆕&nbsp; 🆕&nbsp;
</span> </span>
{{ announcement.title }} {{ announcement.title }}
@ -37,7 +37,7 @@
/> />
</div> </div>
<div <div
v-if="isSignedIn && !announcement.isRead" v-if="isSignedIn(me) && !announcement.isRead"
class="_footer" class="_footer"
> >
<MkButton primary @click="read(announcement.id)" <MkButton primary @click="read(announcement.id)"
@ -60,7 +60,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 "@/me"; import { isSignedIn, me } from "@/me";
const pagination = { const pagination = {
endpoint: "announcements" as const, endpoint: "announcements" as const,

View file

@ -1,8 +1,8 @@
<template> <template>
<div v-if="isSignedIn && fetching" class=""> <div v-if="isSignedIn(me) && fetching" class="">
<MkLoading /> <MkLoading />
</div> </div>
<div v-else-if="isSignedIn"> <div v-else-if="isSignedIn(me)">
<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 { signIn } from "@/account"; import { signIn } from "@/account";
import { isSignedIn } from "@/me"; import { isSignedIn, me } from "@/me";
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 (!isSignedIn) return; if (!isSignedIn(me)) 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

@ -51,7 +51,7 @@ const pagination = {
}; };
const isOwned: boolean | null = computed<boolean | null>( const isOwned: boolean | null = computed<boolean | null>(
() => isSignedIn && clip.value && me.id === clip.value.userId, () => isSignedIn(me) && clip.value && me.id === clip.value.userId,
); );
watch( watch(

View file

@ -17,7 +17,7 @@
<XUserList :pagination="pinnedUsers" /> <XUserList :pagination="pinnedUsers" />
</MkFolder> </MkFolder>
<MkFolder <MkFolder
v-if="isSignedIn" v-if="isSignedIn(me)"
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="isSignedIn" v-if="isSignedIn(me)"
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="isSignedIn" v-if="isSignedIn(me)"
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 && isSignedIn"> <template v-if="tag == null && isSignedIn(me)">
<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 { isSignedIn } from "@/me"; import { isSignedIn, me } from "@/me";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
const props = defineProps<{ const props = defineProps<{

View file

@ -59,7 +59,7 @@
<div class="other"> <div class="other">
<button <button
v-if=" v-if="
isSignedIn && me!.id === post.user.id isSignedIn(me) && me!.id === post.user.id
" "
v-tooltip="i18n.ts.toEdit" v-tooltip="i18n.ts.toEdit"
v-click-anime v-click-anime
@ -105,7 +105,7 @@
<MkAcct :user="post.user" /> <MkAcct :user="post.user" />
</div> </div>
<MkFollowButton <MkFollowButton
v-if="!isSignedIn || me!.id != post.user.id" v-if="!isSignedIn(me) || me!.id != post.user.id"
:user="post.user" :user="post.user"
:inline="true" :inline="true"
:transparent="false" :transparent="false"

View file

@ -51,7 +51,7 @@
/></MkA> /></MkA>
<template <template
v-if=" v-if="
isSignedIn && me.id === page.userId isSignedIn(me) && me.id === page.userId
" "
> >
<MkA <MkA
@ -159,7 +159,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="isSignedIn && me.id === page.userId"> <template v-if="isSignedIn(me) && me.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="me.pinnedPageId === page.id" class="link _textButton" @click="pin(false)">{{ i18n.ts.unpin }}</button> <button v-if="me.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>

View file

@ -64,7 +64,7 @@ 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>(isSignedIn && me.alwaysMarkNsfw); const alwaysMarkNsfw = ref<boolean>(isSignedIn(me) && me.alwaysMarkNsfw);
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 { useStream } from "@/stream"; import { useStream } from "@/stream";
import { isSignedIn } from "@/me"; import { isSignedIn, me } from "@/me";
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";
@ -170,7 +170,7 @@ interface Profile {
}; };
} }
const connection = isSignedIn && stream.useChannel("main"); const connection = isSignedIn(me) && stream.useChannel("main");
const profiles = ref<Record<string, Profile> | null>(null); const profiles = ref<Record<string, Profile> | null>(null);

View file

@ -75,28 +75,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 { isModerator, isSignedIn } from "@/me"; import { isModerator, isSignedIn, me } from "@/me";
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 (isSignedIn && defaultStore.reactiveState.tutorial.value !== -1) { if (isSignedIn(me) && defaultStore.reactiveState.tutorial.value !== -1) {
os.popup(XTutorial, {}, {}, "closed"); os.popup(XTutorial, {}, {}, "closed");
} }
const isHomeTimelineAvailable = isSignedIn; const isHomeTimelineAvailable = isSignedIn(me);
const isLocalTimelineAvailable = const isLocalTimelineAvailable =
(!instance.disableLocalTimeline && (!instance.disableLocalTimeline &&
(isSignedIn || instance.enableGuestTimeline)) || (isSignedIn(me) || instance.enableGuestTimeline)) ||
isModerator; isModerator;
const isSocialTimelineAvailable = isLocalTimelineAvailable && isSignedIn; const isSocialTimelineAvailable = isLocalTimelineAvailable && isSignedIn(me);
const isRecommendedTimelineAvailable = const isRecommendedTimelineAvailable =
!instance.disableRecommendedTimeline && isSignedIn; !instance.disableRecommendedTimeline && isSignedIn(me);
const isGlobalTimelineAvailable = const isGlobalTimelineAvailable =
(!instance.disableGlobalTimeline && (!instance.disableGlobalTimeline &&
(isSignedIn || instance.enableGuestTimeline)) || (isSignedIn(me) || instance.enableGuestTimeline)) ||
isModerator; isModerator;
const keymap = { const keymap = {
t: focus, t: focus,
@ -205,7 +205,7 @@ function focus(): void {
} }
const headerActions = computed(() => const headerActions = computed(() =>
isSignedIn isSignedIn(me)
? [ ? [
{ {
icon: `${icon("ph-list-bullets")}`, icon: `${icon("ph-list-bullets")}`,

View file

@ -67,7 +67,7 @@
</div> </div>
<span <span
v-if=" v-if="
isSignedIn && isSignedIn(me) &&
me.id !== user.id && me.id !== user.id &&
user.isFollowed user.isFollowed
" "
@ -120,7 +120,7 @@
/> />
<span <span
v-if=" v-if="
isSignedIn && isSignedIn(me) &&
me.id !== user.id && me.id !== user.id &&
user.isFollowed user.isFollowed
" "
@ -319,7 +319,7 @@
/> />
</div> </div>
<MkInfo <MkInfo
v-else-if="isSignedIn && me.id === user.id" v-else-if="isSignedIn(me) && me.id === user.id"
style="margin: 12px 0" style="margin: 12px 0"
>{{ i18n.ts.userPagePinTip }}</MkInfo >{{ i18n.ts.userPagePinTip }}</MkInfo
> >

View file

@ -93,7 +93,7 @@ const headerTabs = computed(() =>
title: i18n.ts.media, title: i18n.ts.media,
icon: `${icon("ph-grid-four")}`, icon: `${icon("ph-grid-four")}`,
}, },
...((isSignedIn && me.id === user.value.id) || ...((isSignedIn(me) && me.id === user.value.id) ||
user.value.publicReactions user.value.publicReactions
? [ ? [
{ {

View file

@ -17,7 +17,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 stream = useStream(); const stream = useStream();
const connection = isSignedIn && stream.useChannel("main"); const connection = isSignedIn(me) ? null : stream.useChannel("main");
export class Storage<T extends StateDef> { export class Storage<T extends StateDef> {
public readonly key: string; public readonly key: string;
@ -43,12 +43,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 = isSignedIn const deviceAccountState = isSignedIn(me)
? JSON.parse( ? JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::${me.id}`) || "{}", localStorage.getItem(`${this.keyForLocalStorage}::${me.id}`) || "{}",
) )
: {}; : {};
const registryCache = isSignedIn const registryCache = isSignedIn(me)
? JSON.parse( ? JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::cache::${me.id}`) || localStorage.getItem(`${this.keyForLocalStorage}::cache::${me.id}`) ||
"{}", "{}",
@ -65,7 +65,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" &&
isSignedIn && isSignedIn(me) &&
Object.prototype.hasOwnProperty.call(registryCache, k) Object.prototype.hasOwnProperty.call(registryCache, k)
) { ) {
state[k] = registryCache[k]; state[k] = registryCache[k];
@ -85,7 +85,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 (isSignedIn) { if (isSignedIn(me)) {
// なぜか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(
@ -169,7 +169,7 @@ export class Storage<T extends StateDef> {
break; break;
} }
case "deviceAccount": { case "deviceAccount": {
if (!isSignedIn) break; if (!isSignedIn(me)) break;
const deviceAccountState = JSON.parse( const deviceAccountState = JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::${me.id}`) || "{}", localStorage.getItem(`${this.keyForLocalStorage}::${me.id}`) || "{}",
); );
@ -181,7 +181,7 @@ export class Storage<T extends StateDef> {
break; break;
} }
case "account": { case "account": {
if (!isSignedIn) break; if (!isSignedIn(me)) break;
const cache = JSON.parse( const cache = JSON.parse(
localStorage.getItem(`${this.keyForLocalStorage}::cache::${me.id}`) || localStorage.getItem(`${this.keyForLocalStorage}::cache::${me.id}`) ||
"{}", "{}",

View file

@ -293,7 +293,7 @@ export function getNoteMenu(props: {
} }
let menu: MenuItem[]; let menu: MenuItem[];
if (isSignedIn) { if (isSignedIn(me)) {
const statePromise = os.api("notes/state", { const statePromise = os.api("notes/state", {
noteId: appearNote.id, noteId: appearNote.id,
}); });

View file

@ -335,7 +335,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
}, },
] as any; ] as any;
if (isSignedIn && me.id !== user.id) { if (isSignedIn(me) && me.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",
@ -386,7 +386,7 @@ export function getUserMenu(user, router: Router = mainRouter) {
} }
} }
if (isSignedIn && me.id === user.id) { if (isSignedIn(me) && me.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 { isSignedIn } from "@/me"; import { isSignedIn, me } from "@/me";
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 (isSignedIn) return; if (isSignedIn(me)) return;
vibrate(100); vibrate(100);
popup( popup(

View file

@ -11,7 +11,7 @@ export function useNoteCapture(props: {
isDeletedRef: Ref<boolean>; isDeletedRef: Ref<boolean>;
}) { }) {
const note = props.note; const note = props.note;
const connection = isSignedIn ? useStream() : null; const connection = isSignedIn(me) ? useStream() : 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 (isSignedIn && body.userId === me.id) { if (isSignedIn(me) && body.userId === me.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 (isSignedIn && body.userId === me.id) { if (isSignedIn(me) && body.userId === me.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,
...(isSignedIn && body.userId === me.id ...(isSignedIn(me) && body.userId === me.id
? { ? {
isVoted: true, isVoted: true,
} }

View file

@ -1,6 +1,6 @@
import { markRaw, ref } from "vue"; import { markRaw, ref } from "vue";
import type { ApiTypes, entities } from "firefish-js"; import type { ApiTypes, entities } from "firefish-js";
import { isSignedIn } from "./me"; import { isSignedIn, me } from "./me";
import { Storage } from "./pizzax"; import { Storage } from "./pizzax";
import type { NoteVisibility } from "@/types/note"; import type { NoteVisibility } from "@/types/note";
@ -167,7 +167,7 @@ export const defaultStore = markRaw(
tl: { tl: {
where: "deviceAccount", where: "deviceAccount",
default: { default: {
src: (isSignedIn ? "home" : "local") as src: (isSignedIn(me) ? "home" : "local") as
| "home" | "home"
| "local" | "local"
| "social" | "social"

View file

@ -2,14 +2,14 @@ import type { Theme } from "./scripts/theme";
import { isSignedIn, me } from "@/me"; import { isSignedIn, me } from "@/me";
import { api } from "@/os"; import { api } from "@/os";
const lsCacheKey = isSignedIn ? `themes:${me.id}` : ""; const lsCacheKey = isSignedIn(me) ? `themes:${me.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 (!isSignedIn) return; if (!isSignedIn(me)) return;
try { try {
const themes = await api("i/registry/get", { const themes = await api("i/registry/get", {

View file

@ -57,7 +57,7 @@ const onNotification = (notification) => {
sound.play("notification"); sound.play("notification");
}; };
if (isSignedIn) { if (isSignedIn(me)) {
const connection = stream.useChannel("main", null, "UI"); const connection = stream.useChannel("main", null, "UI");
connection.on("notification", onNotification); connection.on("notification", onNotification);

View file

@ -239,7 +239,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 (!isSignedIn) return false; if (!isSignedIn(me)) 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 { isModerator, isSignedIn } from "@/me"; import { isModerator, isSignedIn, me } from "@/me";
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,7 +72,7 @@ const columnActive = ref(true);
onMounted(() => { onMounted(() => {
if (props.column.tl == null) { if (props.column.tl == null) {
setType(); setType();
} else if (isSignedIn) { } else if (isSignedIn(me)) {
disabled.value = disabled.value =
!isModerator && !isModerator &&
((instance.disableLocalTimeline && ((instance.disableLocalTimeline &&