diff --git a/packages/frontend/src/boot/main-boot.ts b/packages/frontend/src/boot/main-boot.ts index 5cb19f388a..fcdb082b1b 100644 --- a/packages/frontend/src/boot/main-boot.ts +++ b/packages/frontend/src/boot/main-boot.ts @@ -21,6 +21,7 @@ import { initializeSw } from '@/scripts/initialize-sw.js'; import { deckStore } from '@/ui/deck/deck-store.js'; import { emojiPicker } from '@/scripts/emoji-picker.js'; import { mainRouter } from '@/router/main.js'; +import { postButtonHandler } from '@/scripts/post-button-handler.js'; export async function mainBoot() { const { isClientUpdated } = await common(() => createApp( @@ -104,7 +105,7 @@ export async function mainBoot() { if ($i) { // only add post shortcuts if logged in - hotkeys['p|n'] = post; + hotkeys['p|n'] = () => postButtonHandler(mainRouter.currentRef.value); defaultStore.loaded.then(() => { if (defaultStore.state.accountSetupWizard !== -1) { diff --git a/packages/frontend/src/local-storage.ts b/packages/frontend/src/local-storage.ts index 8029bca68d..f3b8380357 100644 --- a/packages/frontend/src/local-storage.ts +++ b/packages/frontend/src/local-storage.ts @@ -32,6 +32,7 @@ type Keys = 'message_drafts' | 'scratchpad' | 'debug' | + `channel:${string}` | `miux:${string}` | `ui:folder:${string}` | `themes:${string}` | diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index 7113e10388..f656a52371 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -24,7 +24,6 @@ import MkContextMenu from '@/components/MkContextMenu.vue'; import { MenuItem } from '@/types/menu.js'; import copyToClipboard from '@/scripts/copy-to-clipboard.js'; import { showMovedDialog } from '@/scripts/show-moved-dialog.js'; -import { mainRouter } from '@/router/main.js'; export const openingWindowsCount = ref(0); @@ -657,39 +656,15 @@ export function post(props: Record = {}): Promise { // Vueが渡されたコンポーネントに内部的に__propsというプロパティを生やす影響で、 // 複数のpost formを開いたときに場合によってはエラーになる // もちろん複数のpost formを開けること自体Misskeyサイドのバグなのだが - - const route = mainRouter.getCurrentPath().split('/'); - if (route[1] === 'channels' && !props.channel) { - misskeyApi('channels/show', { - channelId: route[2], - }).then(channel => { - props = { - ...props, - channel: { ...channel }, - }; - return makePostFormPopup(props); - }).catch(err => { - console.error(err); - alert({ - type: 'error', - text: err.message, - }); - }); - } else { - makePostFormPopup(props); - } - }); -} - -function makePostFormPopup(props) { - let dispose; - popup(MkPostFormDialog, props, { - closed: () => { - resolve(); - dispose(); - }, - }).then(res => { - dispose = res.dispose; + let dispose; + popup(MkPostFormDialog, props, { + closed: () => { + resolve(); + dispose(); + }, + }).then(res => { + dispose = res.dispose; + }); }); } diff --git a/packages/frontend/src/pages/channel.vue b/packages/frontend/src/pages/channel.vue index a895df76e8..75e3e4eaf9 100644 --- a/packages/frontend/src/pages/channel.vue +++ b/packages/frontend/src/pages/channel.vue @@ -122,6 +122,7 @@ watch(() => props.channelId, async () => { channel.value = await misskeyApi('channels/show', { channelId: props.channelId, }); + miLocalStorage.setItem(`channel:${props.channelId}`, JSON.stringify(channel.value)); favorited.value = channel.value.isFavorited ?? false; if (favorited.value || channel.value.isFollowing) { tab.value = 'timeline'; diff --git a/packages/frontend/src/router/definition.ts b/packages/frontend/src/router/definition.ts index c12ae0fa57..a050aafa72 100644 --- a/packages/frontend/src/router/definition.ts +++ b/packages/frontend/src/router/definition.ts @@ -317,6 +317,7 @@ const routes: RouteDef[] = [{ component: page(() => import('@/pages/channel-editor.vue')), loginRequired: true, }, { + name: 'channel', path: '/channels/:channelId', component: page(() => import('@/pages/channel.vue')), }, { diff --git a/packages/frontend/src/scripts/post-button-handler.ts b/packages/frontend/src/scripts/post-button-handler.ts new file mode 100644 index 0000000000..38ea222149 --- /dev/null +++ b/packages/frontend/src/scripts/post-button-handler.ts @@ -0,0 +1,34 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import type { Resolved } from '@/nirax.js'; +import { post } from '@/os.js'; +import { misskeyApi } from '@/scripts/misskey-api.js'; +import { miLocalStorage } from '@/local-storage.js'; + +/** 「ノート」というボタンを押させるときはこっちを呼ぶ */ +export async function postButtonHandler(currentRef: Resolved) { + if (currentRef.route.name === 'channel') { + const channelId = currentRef.props.get('channelId'); + if (typeof channelId === 'string') { + // NOTE: チャンネルを開いているならば、チャンネルの情報がキャッシュされていることを期待できるはずである + const channelJSON = miLocalStorage.getItem(`channel:${channelId}`); + if (channelJSON) { + const channel = JSON.parse(channelJSON); + if (channel) { + await post({ channel }); + return; + } + miLocalStorage.removeItem(`channel:${channelId}`); + } + const channel = await misskeyApi('channels/show', { channelId }); + await post({ channel }); + return; + } + } + + await post(); +} + diff --git a/packages/frontend/src/ui/_common_/navbar-for-mobile.vue b/packages/frontend/src/ui/_common_/navbar-for-mobile.vue index 5d0e065f09..dd2c64f752 100644 --- a/packages/frontend/src/ui/_common_/navbar-for-mobile.vue +++ b/packages/frontend/src/ui/_common_/navbar-for-mobile.vue @@ -38,7 +38,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-