From 9d8e5355650a0c98ae99074ba7c04f1acb49a0b8 Mon Sep 17 00:00:00 2001 From: Hassan Riaz <43652534+Hassan-Riaz@users.noreply.github.com> Date: Wed, 29 Jun 2022 12:52:40 +0500 Subject: [PATCH] Update Message.tsx Render Day functionality should be generic as when we renderDay handler is provided from front end then this logic is duplicated --- src/Message.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Message.tsx b/src/Message.tsx index 7139c52db..401cb124a 100644 --- a/src/Message.tsx +++ b/src/Message.tsx @@ -7,7 +7,7 @@ import Bubble from './Bubble' import { SystemMessage, SystemMessageProps } from './SystemMessage' import { Day, DayProps } from './Day' -import { StylePropType, isSameUser } from './utils' +import { StylePropType, isSameUser, isSameDay } from './utils' import { IMessage, User, LeftRightStyle } from './Models' const styles = { @@ -121,7 +121,10 @@ export default class Message< renderDay() { if (this.props.currentMessage && this.props.currentMessage.createdAt) { - const { containerStyle, onMessageLayout, ...props } = this.props + const { containerStyle, onMessageLayout, ...props } = this.props; + if (this.props.currentMessage == null || this.props.previousMessage != null && isSameDay(this.props.currentMessage, this.props.previousMessage)) { + return null; + } if (this.props.renderDay) { return this.props.renderDay(props) }