From c5a344c2a035bc06ee6637491f3a11747a5958b4 Mon Sep 17 00:00:00 2001 From: Lhcfl <Lhcfl@outlook.com> Date: Mon, 22 Apr 2024 10:32:41 +0800 Subject: [PATCH 1/4] refactor: make isSignedIn a function --- .../client/src/components/MkFollowButton.vue | 2 +- packages/client/src/components/MkMention.vue | 2 +- packages/client/src/components/MkNote.vue | 4 ++-- packages/client/src/components/MkNoteSub.vue | 2 +- .../components/MkPushNotificationAllowButton.vue | 8 ++++---- .../components/MkReactionsViewer.reaction.vue | 8 +++++--- .../client/src/components/MkReactionsViewer.vue | 2 +- .../client/src/components/MkRenoteButton.vue | 2 +- packages/client/src/components/MkTimeline.vue | 4 ++-- packages/client/src/components/MkUserInfo.vue | 4 ++-- packages/client/src/init.ts | 4 ++-- packages/client/src/me.ts | 2 +- packages/client/src/navbar.ts | 14 +++++++------- packages/client/src/pages/announcements.vue | 6 +++--- packages/client/src/pages/auth.vue | 8 ++++---- packages/client/src/pages/clip.vue | 2 +- packages/client/src/pages/explore.users.vue | 10 +++++----- packages/client/src/pages/gallery/post.vue | 4 ++-- packages/client/src/pages/page.vue | 4 ++-- packages/client/src/pages/settings/drive.vue | 2 +- .../src/pages/settings/preferences-backups.vue | 4 ++-- packages/client/src/pages/timeline.vue | 16 ++++++++-------- packages/client/src/pages/user/home.vue | 6 +++--- packages/client/src/pages/user/index.vue | 2 +- packages/client/src/pizzax.ts | 14 +++++++------- packages/client/src/scripts/get-note-menu.ts | 2 +- packages/client/src/scripts/get-user-menu.ts | 4 ++-- packages/client/src/scripts/please-login.ts | 4 ++-- packages/client/src/scripts/use-note-capture.ts | 8 ++++---- packages/client/src/store.ts | 4 ++-- packages/client/src/theme-store.ts | 4 ++-- packages/client/src/ui/_common_/common.vue | 2 +- packages/client/src/ui/deck.vue | 2 +- packages/client/src/ui/deck/tl-column.vue | 4 ++-- 34 files changed, 86 insertions(+), 84 deletions(-) diff --git a/packages/client/src/components/MkFollowButton.vue b/packages/client/src/components/MkFollowButton.vue index 0920001c7b..a018c47b55 100644 --- a/packages/client/src/components/MkFollowButton.vue +++ b/packages/client/src/components/MkFollowButton.vue @@ -8,7 +8,7 @@ <i :class="icon('ph-dots-three-outline')"></i> </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}`" class="kpoogebi _button follow-button" :class="{ diff --git a/packages/client/src/components/MkMention.vue b/packages/client/src/components/MkMention.vue index f943997459..6c9fb4797a 100644 --- a/packages/client/src/components/MkMention.vue +++ b/packages/client/src/components/MkMention.vue @@ -51,7 +51,7 @@ const canonical = const url = `/${canonical}`; const isMe = - isSignedIn && + isSignedIn(me) && `@${props.username}@${toUnicode(props.host)}`.toLowerCase() === `@${me!.username}@${toUnicode(localHost)}`.toLowerCase(); </script> diff --git a/packages/client/src/components/MkNote.vue b/packages/client/src/components/MkNote.vue index 6a22652f60..05cad22e77 100644 --- a/packages/client/src/components/MkNote.vue +++ b/packages/client/src/components/MkNote.vue @@ -235,7 +235,7 @@ <XQuoteButton class="button" :note="appearNote" /> <button v-if=" - isSignedIn && + isSignedIn(me) && isForeignLanguage && translation == null " @@ -370,7 +370,7 @@ const reactButton = ref<HTMLElement | null>(null); const appearNote = computed(() => 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 isDeleted = ref(false); const muted = ref( diff --git a/packages/client/src/components/MkNoteSub.vue b/packages/client/src/components/MkNoteSub.vue index c7cf06d2e5..aed6de486d 100644 --- a/packages/client/src/components/MkNoteSub.vue +++ b/packages/client/src/components/MkNoteSub.vue @@ -127,7 +127,7 @@ <XQuoteButton class="button" :note="appearNote" /> <button v-if=" - isSignedIn && + isSignedIn(me) && isForeignLanguage && translation == null " diff --git a/packages/client/src/components/MkPushNotificationAllowButton.vue b/packages/client/src/components/MkPushNotificationAllowButton.vue index 788c9a3264..1d1be0fb05 100644 --- a/packages/client/src/components/MkPushNotificationAllowButton.vue +++ b/packages/client/src/components/MkPushNotificationAllowButton.vue @@ -16,7 +16,7 @@ <MkButton v-else-if=" !showOnlyToRegister && - (isSignedIn ? pushRegistrationInServer : pushSubscription) + (isSignedIn(me) ? pushRegistrationInServer : pushSubscription) " type="button" :primary="false" @@ -31,7 +31,7 @@ {{ i18n.ts.unsubscribePushNotification }} </MkButton> <MkButton - v-else-if="isSignedIn && pushRegistrationInServer" + v-else-if="isSignedIn(me) && pushRegistrationInServer" disabled :rounded="rounded" :inline="inline" @@ -142,7 +142,7 @@ async function unsubscribe() { pushRegistrationInServer.value = undefined; - if (isSignedIn && accounts.length >= 2) { + if (isSignedIn(me) && accounts.length >= 2) { apiWithDialog("sw/unregister", { i: me.token, endpoint, @@ -189,7 +189,7 @@ if (navigator.serviceWorker == null) { if ( instance.swPublickey && "PushManager" in window && - isSignedIn && + isSignedIn(me) && me.token ) { supported.value = true; diff --git a/packages/client/src/components/MkReactionsViewer.reaction.vue b/packages/client/src/components/MkReactionsViewer.reaction.vue index 89f51797ab..0baa9d2eed 100644 --- a/packages/client/src/components/MkReactionsViewer.reaction.vue +++ b/packages/client/src/components/MkReactionsViewer.reaction.vue @@ -23,12 +23,12 @@ <script lang="ts" setup> 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 XReactionIcon from "@/components/MkReactionIcon.vue"; import * as os from "@/os"; import { useTooltip } from "@/scripts/use-tooltip"; -import { isSignedIn } from "@/me"; +import { isSignedIn, me } from "@/me"; const props = defineProps<{ reaction: string; @@ -43,7 +43,9 @@ const emit = defineEmits<{ const buttonRef = ref<HTMLElement>(); -const canToggle = computed(() => isSignedIn && !props.reaction.match(/@\w/)); +const canToggle = computed( + () => isSignedIn(me) && !props.reaction.match(/@\w/), +); const toggleReaction = () => { if (!canToggle.value) return; diff --git a/packages/client/src/components/MkReactionsViewer.vue b/packages/client/src/components/MkReactionsViewer.vue index 9977faf15f..27f1b9d435 100644 --- a/packages/client/src/components/MkReactionsViewer.vue +++ b/packages/client/src/components/MkReactionsViewer.vue @@ -30,7 +30,7 @@ const reactionsEl = ref<HTMLElement>(); 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> <style lang="scss" scoped> diff --git a/packages/client/src/components/MkRenoteButton.vue b/packages/client/src/components/MkRenoteButton.vue index 7250757da4..93ab89a151 100644 --- a/packages/client/src/components/MkRenoteButton.vue +++ b/packages/client/src/components/MkRenoteButton.vue @@ -74,7 +74,7 @@ useTooltip(buttonRef, async (showing) => { const hasRenotedBefore = ref(false); -if (isSignedIn) { +if (isSignedIn(me)) { os.api("notes/renotes", { noteId: props.note.id, userId: me!.id, diff --git a/packages/client/src/components/MkTimeline.vue b/packages/client/src/components/MkTimeline.vue index f3fe6c7872..d9056c3b25 100644 --- a/packages/client/src/components/MkTimeline.vue +++ b/packages/client/src/components/MkTimeline.vue @@ -1,6 +1,6 @@ <template> <MkInfo - v-if="tlHint && !tlHintClosed && isSignedIn" + v-if="tlHint && !tlHintClosed && isSignedIn(me)" :closeable="true" class="_gap" @close="closeHint" @@ -120,7 +120,7 @@ const prepend = (note: entities.Note) => { emit("note"); if (props.sound) { - sound.play(isSignedIn && note.userId === me?.id ? "noteMy" : "note"); + sound.play(isSignedIn(me) && note.userId === me?.id ? "noteMy" : "note"); } }; diff --git a/packages/client/src/components/MkUserInfo.vue b/packages/client/src/components/MkUserInfo.vue index eb4940858a..137886b4ef 100644 --- a/packages/client/src/components/MkUserInfo.vue +++ b/packages/client/src/components/MkUserInfo.vue @@ -8,7 +8,7 @@ :class="{ detailed }" > <span - v-if="isSignedIn && me.id !== user.id && user.isFollowed" + v-if="isSignedIn(me) && me.id !== user.id && user.isFollowed" class="followed" >{{ i18n.ts.followsYou }}</span > @@ -80,7 +80,7 @@ <div class="buttons"> <slot> <MkFollowButton - v-if="isSignedIn && user.id !== me.id" + v-if="isSignedIn(me) && user.id !== me.id" :user="user" /> </slot> diff --git a/packages/client/src/init.ts b/packages/client/src/init.ts index 17b44bb9f8..08d424cffc 100644 --- a/packages/client/src/init.ts +++ b/packages/client/src/init.ts @@ -262,7 +262,7 @@ function checkForSplash() { } if ( - isSignedIn && + isSignedIn(me) && defaultStore.state.tutorial === -1 && !["/announcements", "/announcements/"].includes(window.location.pathname) ) { @@ -417,7 +417,7 @@ function checkForSplash() { s: search, }; - if (isSignedIn) { + if (isSignedIn(me)) { // only add post shortcuts if logged in hotkeys["p|n"] = post; diff --git a/packages/client/src/me.ts b/packages/client/src/me.ts index 0add04975b..e0c3cb58cf 100644 --- a/packages/client/src/me.ts +++ b/packages/client/src/me.ts @@ -8,7 +8,7 @@ export const me = accountData ? reactive(JSON.parse(accountData) as Account) : 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 isEmojiMod = isModerator || me?.emojiModPerm !== "unauthorized"; export const isAdmin = me?.isAdmin; diff --git a/packages/client/src/navbar.ts b/packages/client/src/navbar.ts index d06c8cf18e..771e55d60a 100644 --- a/packages/client/src/navbar.ts +++ b/packages/client/src/navbar.ts @@ -11,21 +11,21 @@ export const navbarItemDef = reactive({ notifications: { title: "notifications", icon: `${icon("ph-bell")}`, - show: computed(() => isSignedIn), + show: computed(() => isSignedIn(me)), indicated: computed(() => me?.hasUnreadNotification), to: "/my/notifications", }, messaging: { title: "messaging", icon: `${icon("ph-chats-teardrop")}`, - show: computed(() => isSignedIn), + show: computed(() => isSignedIn(me)), indicated: computed(() => me?.hasUnreadMessagingMessage), to: "/my/messaging", }, drive: { title: "drive", icon: `${icon("ph-cloud")}`, - show: computed(() => isSignedIn), + show: computed(() => isSignedIn(me)), to: "/my/drive", }, followRequests: { @@ -54,19 +54,19 @@ export const navbarItemDef = reactive({ lists: { title: "lists", icon: `${icon("ph-list-bullets")}`, - show: computed(() => isSignedIn), + show: computed(() => isSignedIn(me)), to: "/my/lists", }, antennas: { title: "antennas", icon: `${icon("ph-flying-saucer")}`, - show: computed(() => isSignedIn), + show: computed(() => isSignedIn(me)), to: "/my/antennas", }, favorites: { title: "favorites", icon: `${icon("ph-bookmark-simple")}`, - show: computed(() => isSignedIn), + show: computed(() => isSignedIn(me)), to: "/my/favorites", }, pages: { @@ -82,7 +82,7 @@ export const navbarItemDef = reactive({ clips: { title: "clips", icon: `${icon("ph-paperclip")}`, - show: computed(() => isSignedIn), + show: computed(() => isSignedIn(me)), to: "/my/clips", }, channels: { diff --git a/packages/client/src/pages/announcements.vue b/packages/client/src/pages/announcements.vue index 59b703a35e..bd861e226a 100644 --- a/packages/client/src/pages/announcements.vue +++ b/packages/client/src/pages/announcements.vue @@ -17,7 +17,7 @@ > <div class="_title"> <h3> - <span v-if="isSignedIn && !announcement.isRead"> + <span v-if="isSignedIn(me) && !announcement.isRead"> π </span> {{ announcement.title }} @@ -37,7 +37,7 @@ /> </div> <div - v-if="isSignedIn && !announcement.isRead" + v-if="isSignedIn(me) && !announcement.isRead" class="_footer" > <MkButton primary @click="read(announcement.id)" @@ -60,7 +60,7 @@ import * as os from "@/os"; import { i18n } from "@/i18n"; import { definePageMetadata } from "@/scripts/page-metadata"; import icon from "@/scripts/icon"; -import { isSignedIn } from "@/me"; +import { isSignedIn, me } from "@/me"; const pagination = { endpoint: "announcements" as const, diff --git a/packages/client/src/pages/auth.vue b/packages/client/src/pages/auth.vue index a874d0fd26..504343405f 100644 --- a/packages/client/src/pages/auth.vue +++ b/packages/client/src/pages/auth.vue @@ -1,8 +1,8 @@ <template> - <div v-if="isSignedIn && fetching" class=""> + <div v-if="isSignedIn(me) && fetching" class=""> <MkLoading /> </div> - <div v-else-if="isSignedIn"> + <div v-else-if="isSignedIn(me)"> <XForm v-if="state == 'waiting'" ref="form" @@ -52,7 +52,7 @@ import MkSignin from "@/components/MkSignin.vue"; import MkKeyValue from "@/components/MkKeyValue.vue"; import * as os from "@/os"; import { signIn } from "@/account"; -import { isSignedIn } from "@/me"; +import { isSignedIn, me } from "@/me"; import { i18n } from "@/i18n"; const props = defineProps<{ @@ -64,7 +64,7 @@ const fetching = ref(true); const auth_code = ref(""); onMounted(() => { - if (!isSignedIn) return; + if (!isSignedIn(me)) return; os.api("auth/session/show", { token: props.token }) .then((sess: any) => { diff --git a/packages/client/src/pages/clip.vue b/packages/client/src/pages/clip.vue index 8507721519..6f99f66062 100644 --- a/packages/client/src/pages/clip.vue +++ b/packages/client/src/pages/clip.vue @@ -51,7 +51,7 @@ const pagination = { }; 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( diff --git a/packages/client/src/pages/explore.users.vue b/packages/client/src/pages/explore.users.vue index ac68bb8d2d..369399e8db 100644 --- a/packages/client/src/pages/explore.users.vue +++ b/packages/client/src/pages/explore.users.vue @@ -17,7 +17,7 @@ <XUserList :pagination="pinnedUsers" /> </MkFolder> <MkFolder - v-if="isSignedIn" + v-if="isSignedIn(me)" class="_gap" persist-key="explore-popular-users" > @@ -31,7 +31,7 @@ <XUserList :pagination="popularUsers" /> </MkFolder> <MkFolder - v-if="isSignedIn" + v-if="isSignedIn(me)" class="_gap" persist-key="explore-recently-updated-users" > @@ -45,7 +45,7 @@ <XUserList :pagination="recentlyUpdatedUsers" /> </MkFolder> <MkFolder - v-if="isSignedIn" + v-if="isSignedIn(me)" class="_gap" persist-key="explore-recently-registered-users" > @@ -103,7 +103,7 @@ <XUserList :pagination="tagUsers" /> </MkFolder> - <template v-if="tag == null && isSignedIn"> + <template v-if="tag == null && isSignedIn(me)"> <MkFolder class="_gap"> <template #header ><i @@ -146,7 +146,7 @@ import MkFolder from "@/components/MkFolder.vue"; import MkTab from "@/components/MkTab.vue"; import * as os from "@/os"; import { i18n } from "@/i18n"; -import { isSignedIn } from "@/me"; +import { isSignedIn, me } from "@/me"; import icon from "@/scripts/icon"; const props = defineProps<{ diff --git a/packages/client/src/pages/gallery/post.vue b/packages/client/src/pages/gallery/post.vue index 91b6b764c5..c1f23bc123 100644 --- a/packages/client/src/pages/gallery/post.vue +++ b/packages/client/src/pages/gallery/post.vue @@ -59,7 +59,7 @@ <div class="other"> <button v-if=" - isSignedIn && me!.id === post.user.id + isSignedIn(me) && me!.id === post.user.id " v-tooltip="i18n.ts.toEdit" v-click-anime @@ -105,7 +105,7 @@ <MkAcct :user="post.user" /> </div> <MkFollowButton - v-if="!isSignedIn || me!.id != post.user.id" + v-if="!isSignedIn(me) || me!.id != post.user.id" :user="post.user" :inline="true" :transparent="false" diff --git a/packages/client/src/pages/page.vue b/packages/client/src/pages/page.vue index 9ccfed4271..15987d3fb0 100644 --- a/packages/client/src/pages/page.vue +++ b/packages/client/src/pages/page.vue @@ -51,7 +51,7 @@ /></MkA> <template v-if=" - isSignedIn && me.id === page.userId + isSignedIn(me) && me.id === page.userId " > <MkA @@ -159,7 +159,7 @@ </div> <!-- <div class="links"> <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> <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> diff --git a/packages/client/src/pages/settings/drive.vue b/packages/client/src/pages/settings/drive.vue index eb279cc372..b4586d986e 100644 --- a/packages/client/src/pages/settings/drive.vue +++ b/packages/client/src/pages/settings/drive.vue @@ -64,7 +64,7 @@ const fetching = ref(true); const usage = ref<any>(null); const capacity = 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(() => { return { diff --git a/packages/client/src/pages/settings/preferences-backups.vue b/packages/client/src/pages/settings/preferences-backups.vue index 15ff5de402..d0361d39f9 100644 --- a/packages/client/src/pages/settings/preferences-backups.vue +++ b/packages/client/src/pages/settings/preferences-backups.vue @@ -65,7 +65,7 @@ import * as os from "@/os"; import { ColdDeviceStorage, defaultStore } from "@/store"; import { unisonReload } from "@/scripts/unison-reload"; import { useStream } from "@/stream"; -import { isSignedIn } from "@/me"; +import { isSignedIn, me } from "@/me"; import { i18n } from "@/i18n"; import { host, version } from "@/config"; 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); diff --git a/packages/client/src/pages/timeline.vue b/packages/client/src/pages/timeline.vue index 8a577e78ce..31434338b2 100644 --- a/packages/client/src/pages/timeline.vue +++ b/packages/client/src/pages/timeline.vue @@ -75,28 +75,28 @@ import * as os from "@/os"; import { defaultStore } from "@/store"; import { i18n } from "@/i18n"; import { instance } from "@/instance"; -import { isModerator, isSignedIn } from "@/me"; +import { isModerator, isSignedIn, me } from "@/me"; import { definePageMetadata } from "@/scripts/page-metadata"; import { deviceKind } from "@/scripts/device-kind"; import icon from "@/scripts/icon"; import "swiper/scss"; import "swiper/scss/virtual"; -if (isSignedIn && defaultStore.reactiveState.tutorial.value !== -1) { +if (isSignedIn(me) && defaultStore.reactiveState.tutorial.value !== -1) { os.popup(XTutorial, {}, {}, "closed"); } -const isHomeTimelineAvailable = isSignedIn; +const isHomeTimelineAvailable = isSignedIn(me); const isLocalTimelineAvailable = (!instance.disableLocalTimeline && - (isSignedIn || instance.enableGuestTimeline)) || + (isSignedIn(me) || instance.enableGuestTimeline)) || isModerator; -const isSocialTimelineAvailable = isLocalTimelineAvailable && isSignedIn; +const isSocialTimelineAvailable = isLocalTimelineAvailable && isSignedIn(me); const isRecommendedTimelineAvailable = - !instance.disableRecommendedTimeline && isSignedIn; + !instance.disableRecommendedTimeline && isSignedIn(me); const isGlobalTimelineAvailable = (!instance.disableGlobalTimeline && - (isSignedIn || instance.enableGuestTimeline)) || + (isSignedIn(me) || instance.enableGuestTimeline)) || isModerator; const keymap = { t: focus, @@ -205,7 +205,7 @@ function focus(): void { } const headerActions = computed(() => - isSignedIn + isSignedIn(me) ? [ { icon: `${icon("ph-list-bullets")}`, diff --git a/packages/client/src/pages/user/home.vue b/packages/client/src/pages/user/home.vue index 463e5cb4a2..a92bbb3b70 100644 --- a/packages/client/src/pages/user/home.vue +++ b/packages/client/src/pages/user/home.vue @@ -67,7 +67,7 @@ </div> <span v-if=" - isSignedIn && + isSignedIn(me) && me.id !== user.id && user.isFollowed " @@ -120,7 +120,7 @@ /> <span v-if=" - isSignedIn && + isSignedIn(me) && me.id !== user.id && user.isFollowed " @@ -319,7 +319,7 @@ /> </div> <MkInfo - v-else-if="isSignedIn && me.id === user.id" + v-else-if="isSignedIn(me) && me.id === user.id" style="margin: 12px 0" >{{ i18n.ts.userPagePinTip }}</MkInfo > diff --git a/packages/client/src/pages/user/index.vue b/packages/client/src/pages/user/index.vue index 3e079f95cb..6450524687 100644 --- a/packages/client/src/pages/user/index.vue +++ b/packages/client/src/pages/user/index.vue @@ -93,7 +93,7 @@ const headerTabs = computed(() => title: i18n.ts.media, icon: `${icon("ph-grid-four")}`, }, - ...((isSignedIn && me.id === user.value.id) || + ...((isSignedIn(me) && me.id === user.value.id) || user.value.publicReactions ? [ { diff --git a/packages/client/src/pizzax.ts b/packages/client/src/pizzax.ts index 6974df94dc..77b3e53934 100644 --- a/packages/client/src/pizzax.ts +++ b/packages/client/src/pizzax.ts @@ -17,7 +17,7 @@ type StateDef = Record< type ArrayElement<A> = A extends readonly (infer T)[] ? T : never; const stream = useStream(); -const connection = isSignedIn && stream.useChannel("main"); +const connection = isSignedIn(me) ? null : stream.useChannel("main"); export class Storage<T extends StateDef> { public readonly key: string; @@ -43,12 +43,12 @@ export class Storage<T extends StateDef> { const deviceState = JSON.parse( localStorage.getItem(this.keyForLocalStorage) || "{}", ); - const deviceAccountState = isSignedIn + const deviceAccountState = isSignedIn(me) ? JSON.parse( localStorage.getItem(`${this.keyForLocalStorage}::${me.id}`) || "{}", ) : {}; - const registryCache = isSignedIn + const registryCache = isSignedIn(me) ? JSON.parse( localStorage.getItem(`${this.keyForLocalStorage}::cache::${me.id}`) || "{}", @@ -65,7 +65,7 @@ export class Storage<T extends StateDef> { state[k] = deviceState[k]; } else if ( v.where === "account" && - isSignedIn && + isSignedIn(me) && Object.prototype.hasOwnProperty.call(registryCache, k) ) { state[k] = registryCache[k]; @@ -85,7 +85,7 @@ export class Storage<T extends StateDef> { this.state = state as any; this.reactiveState = reactiveState as any; - if (isSignedIn) { + if (isSignedIn(me)) { // γͺγγsetTimeoutγγͺγγ¨apiι’ζ°ε γ§γ¨γ©γΌγ«γͺγ(γγγγεΎͺη°εη §γγ¦γγγ¨γ«εε γγγγγ) window.setTimeout(() => { api("i/registry/get-all", { scope: ["client", this.key] }).then( @@ -169,7 +169,7 @@ export class Storage<T extends StateDef> { break; } case "deviceAccount": { - if (!isSignedIn) break; + if (!isSignedIn(me)) break; const deviceAccountState = JSON.parse( localStorage.getItem(`${this.keyForLocalStorage}::${me.id}`) || "{}", ); @@ -181,7 +181,7 @@ export class Storage<T extends StateDef> { break; } case "account": { - if (!isSignedIn) break; + if (!isSignedIn(me)) break; const cache = JSON.parse( localStorage.getItem(`${this.keyForLocalStorage}::cache::${me.id}`) || "{}", diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts index 25091f2da2..1bc2941acc 100644 --- a/packages/client/src/scripts/get-note-menu.ts +++ b/packages/client/src/scripts/get-note-menu.ts @@ -293,7 +293,7 @@ export function getNoteMenu(props: { } let menu: MenuItem[]; - if (isSignedIn) { + if (isSignedIn(me)) { const statePromise = os.api("notes/state", { noteId: appearNote.id, }); diff --git a/packages/client/src/scripts/get-user-menu.ts b/packages/client/src/scripts/get-user-menu.ts index aac687d207..3ccb6c62a2 100644 --- a/packages/client/src/scripts/get-user-menu.ts +++ b/packages/client/src/scripts/get-user-menu.ts @@ -335,7 +335,7 @@ export function getUserMenu(user, router: Router = mainRouter) { }, ] as any; - if (isSignedIn && me.id !== user.id) { + if (isSignedIn(me) && me.id !== user.id) { menu = menu.concat([ { 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([ null, { diff --git a/packages/client/src/scripts/please-login.ts b/packages/client/src/scripts/please-login.ts index b66802b816..80c6e5b645 100644 --- a/packages/client/src/scripts/please-login.ts +++ b/packages/client/src/scripts/please-login.ts @@ -1,11 +1,11 @@ import { defineAsyncComponent } from "vue"; -import { isSignedIn } from "@/me"; +import { isSignedIn, me } from "@/me"; import { i18n } from "@/i18n"; import { popup } from "@/os"; import { vibrate } from "@/scripts/vibrate"; export function pleaseLogin(path?: string) { - if (isSignedIn) return; + if (isSignedIn(me)) return; vibrate(100); popup( diff --git a/packages/client/src/scripts/use-note-capture.ts b/packages/client/src/scripts/use-note-capture.ts index 1bc32d5246..09043044cd 100644 --- a/packages/client/src/scripts/use-note-capture.ts +++ b/packages/client/src/scripts/use-note-capture.ts @@ -11,7 +11,7 @@ export function useNoteCapture(props: { isDeletedRef: Ref<boolean>; }) { const note = props.note; - const connection = isSignedIn ? useStream() : null; + const connection = isSignedIn(me) ? useStream() : null; async function onStreamNoteUpdated(noteData): Promise<void> { const { type, id, body } = noteData; @@ -34,7 +34,7 @@ export function useNoteCapture(props: { note.value.reactions[reaction] = currentCount + 1; - if (isSignedIn && body.userId === me.id) { + if (isSignedIn(me) && body.userId === me.id) { note.value.myReaction = reaction; } break; @@ -48,7 +48,7 @@ export function useNoteCapture(props: { 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; } break; @@ -62,7 +62,7 @@ export function useNoteCapture(props: { choices[choice] = { ...choices[choice], votes: choices[choice].votes + 1, - ...(isSignedIn && body.userId === me.id + ...(isSignedIn(me) && body.userId === me.id ? { isVoted: true, } diff --git a/packages/client/src/store.ts b/packages/client/src/store.ts index 0adc4e76db..fed9acc035 100644 --- a/packages/client/src/store.ts +++ b/packages/client/src/store.ts @@ -1,6 +1,6 @@ import { markRaw, ref } from "vue"; import type { ApiTypes, entities } from "firefish-js"; -import { isSignedIn } from "./me"; +import { isSignedIn, me } from "./me"; import { Storage } from "./pizzax"; import type { NoteVisibility } from "@/types/note"; @@ -167,7 +167,7 @@ export const defaultStore = markRaw( tl: { where: "deviceAccount", default: { - src: (isSignedIn ? "home" : "local") as + src: (isSignedIn(me) ? "home" : "local") as | "home" | "local" | "social" diff --git a/packages/client/src/theme-store.ts b/packages/client/src/theme-store.ts index a5957dea8f..bc344b339d 100644 --- a/packages/client/src/theme-store.ts +++ b/packages/client/src/theme-store.ts @@ -2,14 +2,14 @@ import type { Theme } from "./scripts/theme"; import { isSignedIn, me } from "@/me"; import { api } from "@/os"; -const lsCacheKey = isSignedIn ? `themes:${me.id}` : ""; +const lsCacheKey = isSignedIn(me) ? `themes:${me.id}` : ""; export function getThemes(): Theme[] { return JSON.parse(localStorage.getItem(lsCacheKey) || "[]"); } export async function fetchThemes(): Promise<void> { - if (!isSignedIn) return; + if (!isSignedIn(me)) return; try { const themes = await api("i/registry/get", { diff --git a/packages/client/src/ui/_common_/common.vue b/packages/client/src/ui/_common_/common.vue index b4f20869b8..c90533581f 100644 --- a/packages/client/src/ui/_common_/common.vue +++ b/packages/client/src/ui/_common_/common.vue @@ -57,7 +57,7 @@ const onNotification = (notification) => { sound.play("notification"); }; -if (isSignedIn) { +if (isSignedIn(me)) { const connection = stream.useChannel("main", null, "UI"); connection.on("notification", onNotification); diff --git a/packages/client/src/ui/deck.vue b/packages/client/src/ui/deck.vue index cab107809d..3337841c0a 100644 --- a/packages/client/src/ui/deck.vue +++ b/packages/client/src/ui/deck.vue @@ -239,7 +239,7 @@ watch(route, () => { const columns = deckStore.reactiveState.columns; const layout = deckStore.reactiveState.layout; const menuIndicated = computed(() => { - if (!isSignedIn) return false; + if (!isSignedIn(me)) return false; for (const def in navbarItemDef) { if (navbarItemDef[def].indicated) return true; } diff --git a/packages/client/src/ui/deck/tl-column.vue b/packages/client/src/ui/deck/tl-column.vue index ae26489b2a..1a4707988b 100644 --- a/packages/client/src/ui/deck/tl-column.vue +++ b/packages/client/src/ui/deck/tl-column.vue @@ -50,7 +50,7 @@ import type { Column } from "./deck-store"; import { removeColumn, updateColumn } from "./deck-store"; import XTimeline from "@/components/MkTimeline.vue"; import * as os from "@/os"; -import { isModerator, isSignedIn } from "@/me"; +import { isModerator, isSignedIn, me } from "@/me"; import { instance } from "@/instance"; import { i18n } from "@/i18n"; import icon from "@/scripts/icon"; @@ -72,7 +72,7 @@ const columnActive = ref(true); onMounted(() => { if (props.column.tl == null) { setType(); - } else if (isSignedIn) { + } else if (isSignedIn(me)) { disabled.value = !isModerator && ((instance.disableLocalTimeline && From 29da81317032f71ebdf9beeeb282fb5e590fe11f Mon Sep 17 00:00:00 2001 From: Lhcfl <Lhcfl@outlook.com> Date: Mon, 22 Apr 2024 10:54:16 +0800 Subject: [PATCH 2/4] fix typo --- packages/client/src/pizzax.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/pizzax.ts b/packages/client/src/pizzax.ts index 77b3e53934..7c952978a1 100644 --- a/packages/client/src/pizzax.ts +++ b/packages/client/src/pizzax.ts @@ -17,7 +17,7 @@ type StateDef = Record< type ArrayElement<A> = A extends readonly (infer T)[] ? T : never; const stream = useStream(); -const connection = isSignedIn(me) ? null : stream.useChannel("main"); +const connection = isSignedIn(me) ? stream.useChannel("main") : null; export class Storage<T extends StateDef> { public readonly key: string; From a49f9c33efcb8a8b3f534f853bf356ba9d7814cd Mon Sep 17 00:00:00 2001 From: Lhcfl <Lhcfl@outlook.com> Date: Mon, 22 Apr 2024 11:02:35 +0800 Subject: [PATCH 3/4] chore: format --- packages/client/src/pizzax.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/pizzax.ts b/packages/client/src/pizzax.ts index 7c952978a1..ce35dbeb24 100644 --- a/packages/client/src/pizzax.ts +++ b/packages/client/src/pizzax.ts @@ -17,7 +17,7 @@ type StateDef = Record< type ArrayElement<A> = A extends readonly (infer T)[] ? T : never; const stream = useStream(); -const connection = isSignedIn(me) ? stream.useChannel("main") : null; +const connection = isSignedIn(me) ? stream.useChannel("main") : null; export class Storage<T extends StateDef> { public readonly key: string; From c6d0fe52d21966c060ee7bc8723a65682411ee05 Mon Sep 17 00:00:00 2001 From: naskya <m@naskya.net> Date: Mon, 22 Apr 2024 22:44:43 +0900 Subject: [PATCH 4/4] chore (client): remove unnecessary non-null assertions --- packages/client/src/components/MkFollowButton.vue | 2 +- packages/client/src/components/MkMention.vue | 2 +- packages/client/src/components/MkNote.vue | 2 +- packages/client/src/components/MkRenoteButton.vue | 2 +- packages/client/src/pages/gallery/post.vue | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/client/src/components/MkFollowButton.vue b/packages/client/src/components/MkFollowButton.vue index a018c47b55..4e2d884749 100644 --- a/packages/client/src/components/MkFollowButton.vue +++ b/packages/client/src/components/MkFollowButton.vue @@ -8,7 +8,7 @@ <i :class="icon('ph-dots-three-outline')"></i> </button> <button - v-if="!hideFollowButton && isSignedIn(me) && me!.id != user.id" + v-if="!hideFollowButton && isSignedIn(me) && me.id != user.id" v-tooltip="full ? null : `${state} ${user.name || user.username}`" class="kpoogebi _button follow-button" :class="{ diff --git a/packages/client/src/components/MkMention.vue b/packages/client/src/components/MkMention.vue index 6c9fb4797a..62626f8373 100644 --- a/packages/client/src/components/MkMention.vue +++ b/packages/client/src/components/MkMention.vue @@ -53,7 +53,7 @@ const url = `/${canonical}`; const isMe = isSignedIn(me) && `@${props.username}@${toUnicode(props.host)}`.toLowerCase() === - `@${me!.username}@${toUnicode(localHost)}`.toLowerCase(); + `@${me.username}@${toUnicode(localHost)}`.toLowerCase(); </script> <style lang="scss" scoped> diff --git a/packages/client/src/components/MkNote.vue b/packages/client/src/components/MkNote.vue index 05cad22e77..41b396c173 100644 --- a/packages/client/src/components/MkNote.vue +++ b/packages/client/src/components/MkNote.vue @@ -370,7 +370,7 @@ const reactButton = ref<HTMLElement | null>(null); const appearNote = computed(() => isRenote ? (note.value.renote as NoteType) : note.value, ); -const isMyRenote = isSignedIn(me) && me!.id === note.value.userId; +const isMyRenote = isSignedIn(me) && me.id === note.value.userId; // const showContent = ref(false); const isDeleted = ref(false); const muted = ref( diff --git a/packages/client/src/components/MkRenoteButton.vue b/packages/client/src/components/MkRenoteButton.vue index 93ab89a151..4f0a669c11 100644 --- a/packages/client/src/components/MkRenoteButton.vue +++ b/packages/client/src/components/MkRenoteButton.vue @@ -77,7 +77,7 @@ const hasRenotedBefore = ref(false); if (isSignedIn(me)) { os.api("notes/renotes", { noteId: props.note.id, - userId: me!.id, + userId: me.id, limit: 1, }).then((res) => { hasRenotedBefore.value = res.length > 0; diff --git a/packages/client/src/pages/gallery/post.vue b/packages/client/src/pages/gallery/post.vue index c1f23bc123..a26006ae6a 100644 --- a/packages/client/src/pages/gallery/post.vue +++ b/packages/client/src/pages/gallery/post.vue @@ -59,7 +59,7 @@ <div class="other"> <button v-if=" - isSignedIn(me) && me!.id === post.user.id + isSignedIn(me) && me.id === post.user.id " v-tooltip="i18n.ts.toEdit" v-click-anime @@ -105,7 +105,7 @@ <MkAcct :user="post.user" /> </div> <MkFollowButton - v-if="!isSignedIn(me) || me!.id != post.user.id" + v-if="!isSignedIn(me) || me.id != post.user.id" :user="post.user" :inline="true" :transparent="false"