fix: file path error after sending media message
This commit is contained in:
@@ -14,7 +14,7 @@ export const onMessageSendStarted = async (
|
|||||||
type = "text",
|
type = "text",
|
||||||
from_uid,
|
from_uid,
|
||||||
reply_mid = null,
|
reply_mid = null,
|
||||||
properties = { local_id: +new Date() }
|
properties = { local_id: +new Date(), content_type: "" }
|
||||||
},
|
},
|
||||||
{ dispatch, queryFulfilled },
|
{ dispatch, queryFulfilled },
|
||||||
from = "channel"
|
from = "channel"
|
||||||
@@ -23,10 +23,11 @@ export const onMessageSendStarted = async (
|
|||||||
if (type == "archive") return;
|
if (type == "archive") return;
|
||||||
// id: who send to ,from_uid: who sent
|
// id: who send to ,from_uid: who sent
|
||||||
// console.log("handlers data", content, type, properties, ignoreLocal, id);
|
// 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 ts = properties.local_id || +new Date();
|
||||||
const tmpMsg = {
|
const tmpMsg = {
|
||||||
content: isImage ? content.path : content,
|
content: isMedia ? content.path : content,
|
||||||
content_type: ContentTypes[type],
|
content_type: ContentTypes[type],
|
||||||
created_at: ts,
|
created_at: ts,
|
||||||
properties,
|
properties,
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ const messageSlice = createSlice({
|
|||||||
addMessage(state, action: PayloadAction<MessagePayload>) {
|
addMessage(state, action: PayloadAction<MessagePayload>) {
|
||||||
const data = action.payload;
|
const data = action.payload;
|
||||||
const { mid, sending, content_type, content, properties } = data;
|
const { mid, sending, content_type, content, properties } = data;
|
||||||
|
// console.log("tfile", sending, content, content_type);
|
||||||
|
|
||||||
// 如果是正发送,并且已存在,则不覆盖
|
// 如果是正发送,并且已存在,则不覆盖
|
||||||
if (sending && state[mid]) return;
|
if (sending && state[mid]) return;
|
||||||
const isFile = content_type == ContentTypes.file;
|
const isFile = content_type == ContentTypes.file;
|
||||||
@@ -59,14 +61,14 @@ const messageSlice = createSlice({
|
|||||||
if (!sending) {
|
if (!sending) {
|
||||||
data.file_path = content;
|
data.file_path = content;
|
||||||
data.content = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
data.content = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||||
data.file_path
|
content
|
||||||
)}`;
|
)}`;
|
||||||
data.download = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
data.download = `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||||
data.file_path
|
content
|
||||||
)}&download=true`;
|
)}&download=true`;
|
||||||
data.thumbnail = isPic
|
data.thumbnail = isPic
|
||||||
? `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
? `${BASE_URL}/resource/file?file_path=${encodeURIComponent(
|
||||||
data.file_path
|
content
|
||||||
)}&thumbnail=true`
|
)}&thumbnail=true`
|
||||||
: "";
|
: "";
|
||||||
} else if (isPic) {
|
} else if (isPic) {
|
||||||
|
|||||||
Reference in New Issue
Block a user