Skip to content

Commit

Permalink
Show just first image if we receive mixed multi-attachment msg
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jan 15, 2019
1 parent 52d3138 commit ba711d8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
32 changes: 32 additions & 0 deletions ts/components/conversation/ImageGrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,35 @@ const attachments = [
</div>
</div>;
```

### Mixing attachment types

```
const attachments = [
{
url: util.pngObjectUrl,
contentType: 'image/png',
width: 320,
height: 240,
},
{
contentType: 'text/plain',
},
{
url: util.pngObjectUrl,
contentType: 'image/png',
width: 320,
height: 240,
},
];
<div>
<div>
<ImageGrid attachments={attachments} i18n={util.i18n} />
</div>
<hr />
<div>
<ImageGrid withContentAbove withContentBelow attachments={attachments} i18n={util.i18n} />
</div>
</div>;
```
25 changes: 24 additions & 1 deletion ts/components/conversation/ImageGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ImageGrid extends React.Component<Props> {
return null;
}

if (attachments.length === 1) {
if (attachments.length === 1 || !areAllAttachmentsVisual(attachments)) {
const { height, width } = getImageDimensions(attachments[0]);

return (
Expand Down Expand Up @@ -324,6 +324,13 @@ export function isImage(attachments?: Array<AttachmentType>) {
);
}

export function isImageAttachment(attachment: AttachmentType) {
return (
attachment &&
attachment.contentType &&
isImageTypeSupported(attachment.contentType)
);
}
export function hasImage(attachments?: Array<AttachmentType>) {
return attachments && attachments[0] && attachments[0].url;
}
Expand Down Expand Up @@ -374,6 +381,22 @@ function getImageDimensions(attachment: AttachmentType): DimensionsType {
};
}

function areAllAttachmentsVisual(attachments?: Array<AttachmentType>): boolean {
if (!attachments) {
return false;
}

const max = attachments.length;
for (let i = 0; i < max; i += 1) {
const attachment = attachments[i];
if (!isImageAttachment(attachment) || !isVideoAttachment(attachment)) {
return false;
}
}

return true;
}

export function getGridDimensions(
attachments?: Array<AttachmentType>
): null | DimensionsType {
Expand Down

0 comments on commit ba711d8

Please sign in to comment.