Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/react/src/views/AttachmentHandler/Attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const Attachment = ({ attachment, host, type, variantStyles = {}, msg }) => {
/>
);
}
if (attachment && attachment.image_url) {
if (
attachment &&
(attachment.image_url ||
(attachment.image_type?.startsWith('image/') && attachment.title_link))
) {
return (
<ImageAttachment
attachment={attachment}
Expand Down
48 changes: 38 additions & 10 deletions packages/react/src/views/AttachmentHandler/ImageAttachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ const ImageAttachment = ({
setIsExpanded((prevState) => !prevState);
};

const getImageUrl = (url) => {
if (!url) {
return;
}
if (url.startsWith('http') || url.startsWith('//')) {
return url;
}
return `${host}${url}`;
};

return (
<Box css={variantStyles.imageAttachmentContainer}>
<Box
Expand Down Expand Up @@ -86,17 +96,28 @@ const ImageAttachment = ({
>
<AttachmentMetadata
attachment={attachment}
url={host + (attachment.title_link || attachment.image_url)}
url={getImageUrl(attachment.title_link || attachment.image_url)}
variantStyles={variantStyles}
msg={msg}
onExpandCollapseClick={toggleExpanded}
isExpanded={isExpanded}
/>
</Box>
{isExpanded && (
<Box onClick={() => setShowGallery(true)}>
<Box
onClick={() =>
extractIdFromUrl(attachment.title_link)
? setShowGallery(true)
: null
}
style={{
cursor: extractIdFromUrl(attachment.title_link)
? 'pointer'
: 'default',
}}
>
<img
src={host + attachment.image_url}
src={getImageUrl(attachment.image_url || attachment.title_link)}
style={{
maxWidth: '100%',
objectFit: 'contain',
Expand All @@ -110,10 +131,16 @@ const ImageAttachment = ({
attachment.attachments.map((nestedAttachment, index) => (
<Box css={variantStyles.imageAttachmentContainer} key={index}>
<Box
onClick={() => setShowGallery(true)}
onClick={() =>
extractIdFromUrl(nestedAttachment.title_link)
? setShowGallery(true)
: null
}
css={[
css`
cursor: pointer;
cursor: ${extractIdFromUrl(nestedAttachment.title_link)
? 'pointer'
: 'default'};
border-radius: inherit;
line-height: 0;
padding: 0.5rem;
Expand Down Expand Up @@ -153,14 +180,15 @@ const ImageAttachment = ({
)}
<AttachmentMetadata
attachment={nestedAttachment}
url={
host +
(nestedAttachment.title_link || nestedAttachment.image_url)
}
url={getImageUrl(
nestedAttachment.title_link || nestedAttachment.image_url
)}
variantStyles={variantStyles}
/>
<img
src={host + nestedAttachment.image_url}
src={getImageUrl(
nestedAttachment.image_url || nestedAttachment.title_link
)}
style={{
maxWidth: '100%',
objectFit: 'contain',
Expand Down