消息类型: 文件: 点击打开; 不支持的消息类型

dev/chat
Lei OT 2 years ago
parent 9725320aa6
commit 403194c3a0

@ -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',

@ -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={<RenderText str={message?.text || ''} />}
{...(message.sender === 'me'
? {

Loading…
Cancel
Save