Skip to content

Commit

Permalink
[#1913] fixed last message for image from google (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
AudreyKj authored Jun 4, 2021
1 parent 5c03526 commit a771fc0
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/typescript/render/SourceMessagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ const FormattedMessage = ({message}: FormattedMessageProps) => {
return <div />;
};

const isImageFromGoogleSource = (messageText: string) => {
if (!messageText) return false;

return (
messageText.includes('https://storage.googleapis.com') &&
messageText.toLowerCase().includes('x-goog-algorithm') &&
messageText.toLowerCase().includes('x-goog-credential')
);
};

export const SourceMessagePreview = (props: SourceMessagePreviewProps) => {
const {conversation} = props;

Expand All @@ -43,7 +53,11 @@ export const SourceMessagePreview = (props: SourceMessagePreviewProps) => {
return text;
}
}
if (lastMessageContent.text || lastMessageContent.message?.text) {

if (
(lastMessageContent.text || lastMessageContent.message?.text) &&
!isImageFromGoogleSource(lastMessageContent.message?.text)
) {
return <FormattedMessage message={conversation.lastMessage} />;
} else if (lastMessageContent.suggestionResponse) {
return <>{conversation.lastMessage.content.suggestionResponse.text}</>;
Expand All @@ -54,7 +68,10 @@ export const SourceMessagePreview = (props: SourceMessagePreviewProps) => {
const lastMessageContent = conversation.lastMessage.content;

if (!lastMessageContent.attachment) {
if (lastMessageContent.message?.attachments?.[0].type === 'image') {
if (
lastMessageContent.message?.attachments?.[0].type === 'image' ||
isImageFromGoogleSource(lastMessageContent.message?.text)
) {
return <AttachmentImage />;
} else if (lastMessageContent.message?.attachments?.[0].type === 'video') {
return <AttachmentVideo style={{height: '24px', width: '24px', margin: '0px'}} />;
Expand Down

0 comments on commit a771fc0

Please sign in to comment.