From 98c636dd09c987ebb705ade3e4b35ecd16ab210d Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Mon, 12 Dec 2022 21:20:27 +0800 Subject: [PATCH] fix: file path error after sending media message --- src/app/services/handlers.ts | 7 ++++--- src/app/slices/message.ts | 12 +++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/services/handlers.ts b/src/app/services/handlers.ts index 6f5e45d9..bc6de18b 100644 --- a/src/app/services/handlers.ts +++ b/src/app/services/handlers.ts @@ -14,7 +14,7 @@ export const onMessageSendStarted = async ( type = "text", from_uid, reply_mid = null, - properties = { local_id: +new Date() } + properties = { local_id: +new Date(), content_type: "" } }, { dispatch, queryFulfilled }, from = "channel" @@ -23,10 +23,11 @@ export const onMessageSendStarted = async ( if (type == "archive") return; // id: who send to ,from_uid: who sent // console.log("handlers data", content, type, properties, ignoreLocal, id); - const isImage = properties.content_type?.startsWith("image"); + const isMedia = ["image", "video", "audio"].includes(properties.content_type.split('/')[0]); + // const isImage = properties.content_type?.startsWith("image"); const ts = properties.local_id || +new Date(); const tmpMsg = { - content: isImage ? content.path : content, + content: isMedia ? content.path : content, content_type: ContentTypes[type], created_at: ts, properties, diff --git a/src/app/slices/message.ts b/src/app/slices/message.ts index f70fa877..296c7fa9 100644 --- a/src/app/slices/message.ts +++ b/src/app/slices/message.ts @@ -42,13 +42,15 @@ const messageSlice = createSlice({ fillMessage(state, action) { return Object.assign({ ...initialState }, action.payload); }, - updateMessage(state, action: PayloadAction<{ mid: number; [key: string | number]: any }>) { + updateMessage(state, action: PayloadAction<{ mid: number;[key: string | number]: any }>) { const { mid, ...rest } = action.payload; state[mid] = { ...state[mid], ...rest }; }, addMessage(state, action: PayloadAction) { const data = action.payload; const { mid, sending, content_type, content, properties } = data; + // console.log("tfile", sending, content, content_type); + // 如果是正发送,并且已存在,则不覆盖 if (sending && state[mid]) return; const isFile = content_type == ContentTypes.file; @@ -59,15 +61,15 @@ const messageSlice = createSlice({ if (!sending) { data.file_path = content; data.content = `${BASE_URL}/resource/file?file_path=${encodeURIComponent( - data.file_path + content )}`; data.download = `${BASE_URL}/resource/file?file_path=${encodeURIComponent( - data.file_path + content )}&download=true`; data.thumbnail = isPic ? `${BASE_URL}/resource/file?file_path=${encodeURIComponent( - data.file_path - )}&thumbnail=true` + content + )}&thumbnail=true` : ""; } else if (isPic) { data.thumbnail = content;