Skip to content

Commit 98b82b7

Browse files
authored
Merge pull request #2529 from GetStream/develop
Next Release
2 parents 447fcaa + e553d50 commit 98b82b7

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

package/src/components/Message/MessageSimple/MessageFooter.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type { MessageType } from '../../MessageList/hooks/useMessageList';
2828

2929
type MessageFooterComponentProps = {
3030
date?: string | Date;
31+
formattedDate?: string | Date;
3132
isDeleted?: boolean;
3233
};
3334

@@ -89,6 +90,7 @@ const MessageFooterWithContext = <
8990
alignment,
9091
date,
9192
deletedMessagesVisibilityType,
93+
formattedDate,
9294
isDeleted,
9395
isEditedMessageOpen,
9496
lastGroupMessage,
@@ -116,7 +118,7 @@ const MessageFooterWithContext = <
116118
{deletedMessagesVisibilityType === 'sender' && (
117119
<OnlyVisibleToYouComponent alignment={alignment} />
118120
)}
119-
<MessageTimestamp format='LT' timestamp={date} />
121+
<MessageTimestamp format='LT' formattedDate={formattedDate} timestamp={date} />
120122
</View>
121123
);
122124
}
@@ -135,7 +137,7 @@ const MessageFooterWithContext = <
135137
<Text style={[styles.text, { color: grey }, messageUser]}>{message.user.name}</Text>
136138
) : null}
137139
{showMessageStatus && <MessageStatus />}
138-
<MessageTimestamp format='LT' timestamp={date} />
140+
<MessageTimestamp format='LT' formattedDate={formattedDate} timestamp={date} />
139141

140142
{isEditedMessage(message) && !isEditedMessageOpen && (
141143
<>
@@ -157,7 +159,9 @@ const MessageFooterWithContext = <
157159
</>
158160
)}
159161
</View>
160-
{isEditedMessageOpen && <MessageEditedTimestamp format='LT' timestamp={date} />}
162+
{isEditedMessageOpen && (
163+
<MessageEditedTimestamp format='LT' formattedDate={formattedDate} timestamp={date} />
164+
)}
161165
</>
162166
);
163167
};
@@ -169,6 +173,7 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
169173
const {
170174
alignment: prevAlignment,
171175
date: prevDate,
176+
formattedDate: prevFormattedDate,
172177
isEditedMessageOpen: prevIsEditedMessageOpen,
173178
lastGroupMessage: prevLastGroupMessage,
174179
members: prevMembers,
@@ -179,6 +184,7 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
179184
const {
180185
alignment: nextAlignment,
181186
date: nextDate,
187+
formattedDate: nextFormattedDate,
182188
isEditedMessageOpen: nextIsEditedMessageOpen,
183189
lastGroupMessage: nextLastGroupMessage,
184190
members: nextMembers,
@@ -226,6 +232,9 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
226232
const dateEqual = prevDate === nextDate;
227233
if (!dateEqual) return false;
228234

235+
const formattedDateEqual = prevFormattedDate === nextFormattedDate;
236+
if (!formattedDateEqual) return false;
237+
229238
return true;
230239
};
231240

package/src/components/Message/MessageSimple/MessageTimestamp.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,26 @@ export type MessageTimestampProps = Partial<Pick<TranslationContextValue, 'tDate
2222
* A function to format the date.
2323
*/
2424
formatDate?: (date: TDateTimeParserInput) => string;
25+
/**
26+
* Already Formatted date
27+
*/
28+
formattedDate?: string | Date;
2529
/**
2630
* The timestamp of the message.
2731
*/
2832
timestamp?: string | Date;
2933
};
3034

3135
export const MessageTimestamp = (props: MessageTimestampProps) => {
32-
const { calendar, format, formatDate, tDateTimeParser: propsTDateTimeParser, timestamp } = props;
36+
const {
37+
calendar,
38+
format,
39+
formatDate,
40+
formattedDate,
41+
tDateTimeParser: propsTDateTimeParser,
42+
timestamp,
43+
} = props;
44+
3345
const {
3446
theme: {
3547
colors: { grey },
@@ -40,21 +52,25 @@ export const MessageTimestamp = (props: MessageTimestampProps) => {
4052
} = useTheme();
4153
const { tDateTimeParser: contextTDateTimeParser } = useTranslationContext();
4254

55+
if (formattedDate) {
56+
return (
57+
<Text style={[styles.text, { color: grey }, timestampText]}>{formattedDate.toString()}</Text>
58+
);
59+
}
60+
4361
if (!timestamp) return null;
4462

45-
const formattedDate = getDateString({
63+
const dateString = getDateString({
4664
calendar,
4765
date: timestamp,
4866
format,
4967
formatDate,
5068
tDateTimeParser: propsTDateTimeParser || contextTDateTimeParser,
5169
});
5270

53-
if (!formattedDate) return null;
71+
if (!dateString) return null;
5472

55-
return (
56-
<Text style={[styles.text, { color: grey }, timestampText]}>{formattedDate.toString()}</Text>
57-
);
73+
return <Text style={[styles.text, { color: grey }, timestampText]}>{dateString.toString()}</Text>;
5874
};
5975

6076
const styles = StyleSheet.create({

package/src/utils/getDateString.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export function getDateString({
3939
format,
4040
formatDate,
4141
tDateTimeParser,
42-
}: DateFormatterOptions): string | number | null {
42+
}: DateFormatterOptions): string | number | undefined {
4343
if (!date || (typeof date === 'string' && !Date.parse(date))) {
44-
return null;
44+
return;
4545
}
4646

4747
if (typeof formatDate === 'function') {
@@ -50,7 +50,7 @@ export function getDateString({
5050

5151
if (!tDateTimeParser) {
5252
console.log(noParsingFunctionWarning);
53-
return null;
53+
return;
5454
}
5555

5656
const parsedTime = tDateTimeParser(date);

0 commit comments

Comments
 (0)