Skip to content

Commit 3ba3cd1

Browse files
authored
Merge pull request #1548 from GetStream/khushal87-issue-1545
2 parents b39d151 + 5d7cf30 commit 3ba3cd1

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

package/src/components/ImageGallery/ImageGallery.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,25 @@ export const ImageGallery = <
273273

274274
const attachmentPhotos = attachmentImages.map((a) => {
275275
const imageUrl = getUrlOfImageAttachment(a) as string;
276+
const giphyURL = a.giphy?.[giphyVersion]?.url || a.thumb_url || a.image_url;
276277

277278
return {
278279
channelId: cur.cid,
279280
created_at: cur.created_at,
280281
id: `photoId-${cur.id}-${imageUrl}`,
281282
messageId: cur.id,
282-
mime_type: a.mime_type,
283+
mime_type: a.type === 'giphy' ? 'image/gif' : a.mime_type,
283284
original_height: a.original_height,
284285
original_width: a.original_width,
285286
type: a.type,
286-
uri: getResizedImageUrl({
287-
height: screenHeight,
288-
url: imageUrl,
289-
width: screenWidth,
290-
}),
287+
uri:
288+
a.type === 'giphy'
289+
? giphyURL
290+
: getResizedImageUrl({
291+
height: screenHeight,
292+
url: imageUrl,
293+
width: screenWidth,
294+
}),
291295
user: cur.user,
292296
user_id: cur.user_id,
293297
};

package/src/components/ImageGallery/components/ImageGalleryFooter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ export const ImageGalleryFooterWithContext = <
171171
}-${selectedIndex}.${extension}`,
172172
fromUrl: photo.uri,
173173
});
174-
await shareImage({ type: photo.mime_type, url: localFile });
174+
// `image/jpeg` is added for the case where the mime_type isn't available for a file/image
175+
await shareImage({ type: photo.mime_type ?? 'image/jpeg', url: localFile });
175176
await deleteFile({ uri: localFile });
176177
} catch (error) {
177178
console.log(error);

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,14 @@ export const MessageInputProvider = <
669669
}
670670
}
671671

672+
// To get the mime type of the image from the file name and send it as an response for an image
673+
const mime_type: string | boolean = lookup(image.file.filename as string);
674+
672675
if (image.state === FileState.UPLOADED || image.state === FileState.FINISHED) {
673676
attachments.push({
674677
fallback: image.file.name,
675678
image_url: image.url,
679+
mime_type,
676680
original_height: image.height,
677681
original_width: image.width,
678682
type: 'image',
@@ -689,11 +693,14 @@ export const MessageInputProvider = <
689693
sending.current = false;
690694
return;
691695
}
696+
const mime_type: string | boolean = lookup(file.file.name as string);
697+
692698
if (file.state === FileState.UPLOADED || file.state === FileState.FINISHED) {
693699
if (file.file.type?.startsWith('image/')) {
694700
attachments.push({
695701
fallback: file.file.name,
696702
image_url: file.url,
703+
mime_type,
697704
type: 'image',
698705
} as Attachment<StreamChatGenerics>);
699706
} else if (file.file.type?.startsWith('audio/')) {

package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Object {
66
Object {
77
"fallback": undefined,
88
"image_url": undefined,
9+
"mime_type": false,
910
"original_height": undefined,
1011
"original_width": undefined,
1112
"type": "image",
@@ -65,6 +66,7 @@ Object {
6566
Object {
6667
"fallback": "dummy.pdf",
6768
"image_url": undefined,
69+
"mime_type": "application/pdf",
6870
"type": "image",
6971
},
7072
],
@@ -85,13 +87,15 @@ Object {
8587
Object {
8688
"fallback": undefined,
8789
"image_url": undefined,
90+
"mime_type": false,
8891
"original_height": undefined,
8992
"original_width": undefined,
9093
"type": "image",
9194
},
9295
Object {
9396
"fallback": undefined,
9497
"image_url": undefined,
98+
"mime_type": false,
9599
"original_height": undefined,
96100
"original_width": undefined,
97101
"type": "image",

0 commit comments

Comments
 (0)