From 059cf58eaa0966826c32457309de6bdbb1b43cdf Mon Sep 17 00:00:00 2001 From: Nagarei Date: Fri, 3 Jan 2025 12:27:02 +0900 Subject: [PATCH 1/2] =?UTF-8?q?VirtualChannelId=E3=81=AB=E5=AF=BE=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=AFmessageInputStateStore=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E3=82=8F=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/ui/messageInputStateStore.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/store/ui/messageInputStateStore.ts b/src/store/ui/messageInputStateStore.ts index 2d474d641..5f83b5204 100644 --- a/src/store/ui/messageInputStateStore.ts +++ b/src/store/ui/messageInputStateStore.ts @@ -1,6 +1,6 @@ import { defineStore, acceptHMRUpdate } from 'pinia' import type { Ref } from 'vue' -import { computed, unref, toRef } from 'vue' +import { computed, unref, toRef, ref } from 'vue' import type { AttachmentType } from '/@/lib/basic/file' import { convertToRefsStore } from '/@/store/utils/convertToRefsStore' import type { ChannelId } from '/@/types/entity-ids' @@ -40,7 +40,7 @@ const useMessageInputStateStorePinia = defineStore( () => { const initialValue = { messageInputState: new Map< - ChannelId | VirtualChannelId, + ChannelId, MessageInputState >() } @@ -59,20 +59,27 @@ const useMessageInputStateStorePinia = defineStore( ) const states = toRef(() => state.messageInputState) - const inputChannels = computed(() => - [...states.value].filter(([id]) => !virtualIds.has(id)) - ) + const inputChannels = computed(() => [...states.value]) const hasInputChannel = computed(() => inputChannels.value.length > 0) + const virtualChannelStates = ref( + new Map() + ) - const getStore = (cId: MessageInputStateKey) => states.value.get(unref(cId)) + const getStore = (cId: MessageInputStateKey) => { + const cId_ = unref(cId) + const st = (virtualIds.has(cId_) ? virtualChannelStates : states) + return st.value.get(cId_) + } const setStore = (cId: MessageInputStateKey, v: MessageInputState) => { + const cId_ = unref(cId) + const st = (virtualIds.has(cId_) ? virtualChannelStates : states) // 空のときは削除、空でないときはセット if (v && (v.text !== '' || v.attachments.length > 0)) { // コピーしないと参照が変わらないから上書きされる // toRawしちゃうとreactiveで包めなくなるので、そうはしない - states.value.set(unref(cId), { ...v }) + st.value.set(cId_, { ...v }) } else { - states.value.delete(unref(cId)) + st.value.delete(cId_) } } From 5369b3b9185e0ab1c133254d59fafc3dacbd62e8 Mon Sep 17 00:00:00 2001 From: Nagarei Date: Fri, 3 Jan 2025 12:36:59 +0900 Subject: [PATCH 2/2] fix format --- src/store/ui/messageInputStateStore.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/store/ui/messageInputStateStore.ts b/src/store/ui/messageInputStateStore.ts index 5f83b5204..b2260a608 100644 --- a/src/store/ui/messageInputStateStore.ts +++ b/src/store/ui/messageInputStateStore.ts @@ -39,10 +39,7 @@ const useMessageInputStateStorePinia = defineStore( 'ui/messageInputStateStore', () => { const initialValue = { - messageInputState: new Map< - ChannelId, - MessageInputState - >() + messageInputState: new Map() } const [state, restoring, restoringPromise] = useIndexedDbValue( @@ -67,12 +64,12 @@ const useMessageInputStateStorePinia = defineStore( const getStore = (cId: MessageInputStateKey) => { const cId_ = unref(cId) - const st = (virtualIds.has(cId_) ? virtualChannelStates : states) + const st = virtualIds.has(cId_) ? virtualChannelStates : states return st.value.get(cId_) } const setStore = (cId: MessageInputStateKey, v: MessageInputState) => { const cId_ = unref(cId) - const st = (virtualIds.has(cId_) ? virtualChannelStates : states) + const st = virtualIds.has(cId_) ? virtualChannelStates : states // 空のときは削除、空でないときはセット if (v && (v.text !== '' || v.attachments.length > 0)) { // コピーしないと参照が変わらないから上書きされる