Skip to content

Commit afd84a9

Browse files
Merge pull request #840 from GetStream/vishal/image-attachment-fix
fix: allow images attached through file picker to display in gallery view fix: sticky date header flashing wrong date on first render
2 parents b8365ca + 2cf629c commit afd84a9

File tree

4 files changed

+34
-98
lines changed

4 files changed

+34
-98
lines changed

package/src/components/MessageList/MessageList.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ const MessageListWithContext = <
349349
const [lastReceivedId, setLastReceivedId] = useState(getLastReceivedMessage(messageList)?.id);
350350
const [scrollToBottomButtonVisible, setScrollToBottomButtonVisible] = useState(false);
351351

352-
const [stickyHeaderDate, setStickyHeaderDate] = useState<Date>(new Date());
353-
const stickyHeaderDateRef = useRef(new Date());
352+
const [stickyHeaderDate, setStickyHeaderDate] = useState<Date | undefined>();
353+
const stickyHeaderDateRef = useRef<Date | undefined>();
354354
/**
355355
* channel.lastRead throws error if the channel is not initialized.
356356
*/
@@ -396,7 +396,7 @@ const MessageListWithContext = <
396396
lastItem?.item?.created_at &&
397397
!lastItem.item.deleted_at &&
398398
typeof lastItem.item.created_at !== 'string' &&
399-
lastItem.item.created_at.toDateString() !== stickyHeaderDateRef.current.toDateString()
399+
lastItem.item.created_at.toDateString() !== stickyHeaderDateRef.current?.toDateString()
400400
) {
401401
stickyHeaderDateRef.current = lastItem.item.created_at;
402402
setStickyHeaderDate(lastItem.item.created_at);
@@ -819,11 +819,14 @@ const MessageListWithContext = <
819819
}, [imageString, numberOfMessagesWithImages, threadExists, threadList]);
820820

821821
const stickyHeaderFormatDate =
822-
stickyHeaderDate.getFullYear() === new Date().getFullYear() ? 'MMM D' : 'MMM D, YYYY';
823-
const tStickyHeaderDate = tDateTimeParser(stickyHeaderDate);
824-
const stickyHeaderDateToRender = isDayOrMoment(tStickyHeaderDate)
825-
? tStickyHeaderDate.format(stickyHeaderFormatDate)
826-
: new Date(tStickyHeaderDate).toDateString();
822+
stickyHeaderDate?.getFullYear() === new Date().getFullYear() ? 'MMM D' : 'MMM D, YYYY';
823+
const tStickyHeaderDate = stickyHeaderDate ? tDateTimeParser(stickyHeaderDate) : null;
824+
const stickyHeaderDateToRender =
825+
tStickyHeaderDate === null
826+
? null
827+
: isDayOrMoment(tStickyHeaderDate)
828+
? tStickyHeaderDate.format(stickyHeaderFormatDate)
829+
: new Date(tStickyHeaderDate).toDateString();
827830

828831
const dismissImagePicker = () => {
829832
if (!hasMoved && selectedPicker) {
@@ -890,11 +893,12 @@ const MessageListWithContext = <
890893
{!loading && (
891894
<>
892895
<View style={styles.stickyHeader}>
893-
{StickyHeader ? (
894-
<StickyHeader dateString={stickyHeaderDateToRender} />
895-
) : messageListLengthAfterUpdate ? (
896-
<DateHeader dateString={stickyHeaderDateToRender} />
897-
) : null}
896+
{stickyHeaderDateToRender &&
897+
(StickyHeader ? (
898+
<StickyHeader dateString={stickyHeaderDateToRender} />
899+
) : messageListLengthAfterUpdate ? (
900+
<DateHeader dateString={stickyHeaderDateToRender} />
901+
) : null)}
898902
</View>
899903
{!disableTypingIndicator && TypingIndicator && typingEventsEnabled !== false && (
900904
<TypingIndicatorContainer>

package/src/components/MessageList/__tests__/__snapshots__/MessageList.test.js.snap

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -896,45 +896,7 @@ exports[`MessageList should render the message list and match snapshot 1`] = `
896896
"top": 0,
897897
}
898898
}
899-
>
900-
<View
901-
style={
902-
Array [
903-
Object {
904-
"alignItems": "center",
905-
"alignSelf": "center",
906-
"borderRadius": 8,
907-
"height": 16,
908-
"justifyContent": "center",
909-
"marginTop": 8,
910-
"paddingHorizontal": 8,
911-
},
912-
Object {
913-
"backgroundColor": "#00000099",
914-
},
915-
Object {},
916-
]
917-
}
918-
>
919-
<Text
920-
style={
921-
Array [
922-
Object {
923-
"fontSize": 12,
924-
"textAlign": "center",
925-
"textAlignVertical": "center",
926-
},
927-
Object {
928-
"color": "#FFFFFF",
929-
},
930-
Object {},
931-
]
932-
}
933-
>
934-
Sep 3
935-
</Text>
936-
</View>
937-
</View>
899+
/>
938900
<View
939901
style={
940902
Array [

package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -858,45 +858,7 @@ exports[`Thread should match thread snapshot 1`] = `
858858
"top": 0,
859859
}
860860
}
861-
>
862-
<View
863-
style={
864-
Array [
865-
Object {
866-
"alignItems": "center",
867-
"alignSelf": "center",
868-
"borderRadius": 8,
869-
"height": 16,
870-
"justifyContent": "center",
871-
"marginTop": 8,
872-
"paddingHorizontal": 8,
873-
},
874-
Object {
875-
"backgroundColor": "#00000099",
876-
},
877-
Object {},
878-
]
879-
}
880-
>
881-
<Text
882-
style={
883-
Array [
884-
Object {
885-
"fontSize": 12,
886-
"textAlign": "center",
887-
"textAlignVertical": "center",
888-
},
889-
Object {
890-
"color": "#FFFFFF",
891-
},
892-
Object {},
893-
]
894-
}
895-
>
896-
Sep 3
897-
</Text>
898-
</View>
899-
</View>
861+
/>
900862
<View
901863
style={
902864
Array [

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,21 @@ export const MessageInputProvider = <
664664
return;
665665
}
666666
if (file.state === FileState.UPLOADED || file.state === FileState.FINISHED) {
667-
attachments.push({
668-
asset_url: file.url,
669-
file_size: file.file.size,
670-
mime_type: file.file.type,
671-
title: file.file.name,
672-
type: 'file',
673-
} as Attachment<At>);
667+
if (file.file.type?.startsWith('image/')) {
668+
attachments.push({
669+
fallback: file.file.name,
670+
image_url: file.url,
671+
type: 'image',
672+
} as Attachment<At>);
673+
} else {
674+
attachments.push({
675+
asset_url: file.url,
676+
file_size: file.file.size,
677+
mime_type: file.file.type,
678+
title: file.file.name,
679+
type: 'file',
680+
} as Attachment<At>);
681+
}
674682
}
675683
}
676684

0 commit comments

Comments
 (0)