From 8285f5df15ae7414685c6029e7fa05c5fc4ddd33 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Sat, 27 Mar 2021 13:29:04 +0530 Subject: [PATCH] fix: Handle rendering HTML only email in UI (#1987) --- .../widgets/conversation/ConversationCard.vue | 4 ++- .../widgets/conversation/Message.vue | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue index 43cf1817d..bfea8c86c 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue @@ -143,7 +143,9 @@ export default { }, parsedLastMessage() { - return this.getPlainText(this.lastMessageInChat.content); + const { content_attributes: contentAttributes } = this.lastMessageInChat; + const { email: { subject } = {} } = contentAttributes || {}; + return this.getPlainText(subject || this.lastMessageInChat.content); }, chatInbox() { diff --git a/app/javascript/dashboard/components/widgets/conversation/Message.vue b/app/javascript/dashboard/components/widgets/conversation/Message.vue index 41d770cf6..63f7dd155 100644 --- a/app/javascript/dashboard/components/widgets/conversation/Message.vue +++ b/app/javascript/dashboard/components/widgets/conversation/Message.vue @@ -107,11 +107,23 @@ export default { this.contentAttributes, this.$t('CONVERSATION.NO_RESPONSE') ); - let messageContent = - this.formatMessage(this.data.content, this.isATweet) + - botMessageContent; - return messageContent; + const { + email: { html_content: { full: fullHTMLContent } = {} } = {}, + } = this.contentAttributes; + + if (fullHTMLContent && this.isIncoming) { + let parsedContent = new DOMParser().parseFromString( + fullHTMLContent || '', + 'text/html' + ); + if (!parsedContent.getElementsByTagName('parsererror').length) { + return parsedContent.body.innerHTML; + } + } + return ( + this.formatMessage(this.data.content, this.isATweet) + botMessageContent + ); }, contentAttributes() { return this.data.content_attributes || {}; @@ -261,4 +273,10 @@ export default { margin-left: var(--space-smaller); } } + +// This is a hack to hide quoted content from GMAIL +// Replace this with actual content parser +.gmail_quote { + display: none; +}