diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js index 7106650..f46c65f 100644 --- a/src/lib/msgUtils.js +++ b/src/lib/msgUtils.js @@ -255,14 +255,15 @@ export const whatsappMsgTypeMapped = { }, }), }, - unsupported: { type: 'system', data: (msg) => ({ text: 'Message type is currently not supported.' }) }, + // unsupported: { type: 'system', data: (msg) => ({ text: 'Message type is currently not supported.' }) }, + unsupported: { type: 'text', data: (msg) => ({ text: '[暂不支持此消息类型]' }) }, reaction: { type: 'text', data: (msg) => ({ id: msg.wamid, text: msg.reaction?.emoji || '', }), }, document: { type: 'file', - data: (msg) => ({ id: msg.wamid, text: msg.document.filename, data: { uri: msg.document.link, extension: 'PDF', status: { click: false, loading: 0, } } }), + data: (msg) => ({ id: msg.wamid, title: msg.document?.filename || '', text: msg.document?.caption || msg.document?.filename || '', data: { uri: msg.document.link, extension: 'PDF', status: { click: false, download: true, loading: 0, } } }), }, // location: 'location', // contact: 'contact', diff --git a/src/views/Conversations/Components/Messages.jsx b/src/views/Conversations/Components/Messages.jsx index 2e64da0..d57bf27 100644 --- a/src/views/Conversations/Components/Messages.jsx +++ b/src/views/Conversations/Components/Messages.jsx @@ -37,11 +37,19 @@ const Messages = () => { setPreviewVisible(false); }; const handlePreview = (msg) => { - if (msg.type !== 'photo') { - return false; + switch (msg.type) { + case 'photo': + setPreviewVisible(true); + setPreviewSrc(msg.data.uri); + return false; + + case 'file': + window.open(msg.data.uri, "_blank", "noopener,noreferrer") + return false; + + default: + return false; } - setPreviewVisible(true); - setPreviewSrc(msg.data.uri); }; const RenderText = memo(function renderText({str}) { @@ -105,6 +113,7 @@ const Messages = () => { onReplyClick={() => setReferenceMsg(message)} onReplyMessageClick={() => scrollToMessage(message.reply.id)} onOpen={() => handlePreview(message)} + onTitleClick={() => handlePreview(message)} text={} {...(message.sender === 'me' ? {