diff --git a/src/libs/isReportMessageAttachment.ts b/src/libs/isReportMessageAttachment.ts index 9ef4125ee8bf..dcb5aa97ee67 100644 --- a/src/libs/isReportMessageAttachment.ts +++ b/src/libs/isReportMessageAttachment.ts @@ -2,6 +2,8 @@ import {Str} from 'expensify-common'; import CONST from '@src/CONST'; import type {Message} from '@src/types/onyx/ReportAction'; +const attachmentRegex = new RegExp(` ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="(.*)"`, 'i'); + /** * Check whether a report action is Attachment or not. * Ignore messages containing [Attachment] as the main content. Attachments are actions with only text as [Attachment]. @@ -13,10 +15,21 @@ export default function isReportMessageAttachment(message: Message | undefined): return false; } - if (message.translationKey && message.text === CONST.ATTACHMENT_MESSAGE_TEXT) { - return message?.translationKey === CONST.TRANSLATION_KEYS.ATTACHMENT; + if (message.translationKey) { + return message.text === CONST.ATTACHMENT_MESSAGE_TEXT && message.translationKey === CONST.TRANSLATION_KEYS.ATTACHMENT; + } + + const hasAttachmentHtml = message.html === CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML || attachmentRegex.test(message.html); + + if (!hasAttachmentHtml) { + return false; + } + + const isAttachmentMessageText = message.text === CONST.ATTACHMENT_MESSAGE_TEXT; + + if (isAttachmentMessageText) { + return true; } - const regex = new RegExp(` ${CONST.ATTACHMENT_SOURCE_ATTRIBUTE}="(.*)"`, 'i'); - return (message.text === CONST.ATTACHMENT_MESSAGE_TEXT || !!Str.isVideo(message.text)) && (!!message.html.match(regex) || message.html === CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML); + return Str.isVideo(message.text); }