Skip to content

Commit 9a8d9a3

Browse files
CRNS-59: Add support for custom date format in ChannelPreviewMessanger
Resolves #121
1 parent ef5b887 commit 9a8d9a3

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/components/ChannelPreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class ChannelPreview extends PureComponent {
6060
const latestMessage = {
6161
text: '',
6262
created_at: '',
63-
originalMessageObject: { ...message },
63+
messageObject: { ...message },
6464
};
6565

6666
if (!message) {

src/components/ChannelPreviewMessenger.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ export const ChannelPreviewMessenger = themed(
7777
unread: PropTypes.number,
7878
/** Length at which latest message should be truncated */
7979
latestMessageLength: PropTypes.number,
80+
/**
81+
* Formatter function for date of latest message.
82+
* @param date Message date
83+
* @returns Formatted date string
84+
*
85+
* By default today's date is shown in 'HH:mm A' format and other dates
86+
* are displayed in 'DD/MM/YY' format. props.latestMessage.created_at is the
87+
* default formated date. This default logic is part of ChannelPreview component.
88+
*/
89+
formatLatestMessageDate: PropTypes.func,
8090
};
8191

8292
static defaultProps = {
@@ -115,7 +125,7 @@ export const ChannelPreviewMessenger = themed(
115125
.map((member) => member.user.name || member.user.id || 'Unnamed User')
116126
.join(', ');
117127
}
118-
128+
const formatLatestMessageDate = this.props.formatLatestMessageDate;
119129
return (
120130
<Container onPress={this.onSelectChannel}>
121131
{this.renderAvatar(otherMembers)}
@@ -124,7 +134,13 @@ export const ChannelPreviewMessenger = themed(
124134
<Title ellipsizeMode="tail" numberOfLines={1}>
125135
{name}
126136
</Title>
127-
<Date>{this.props.latestMessage.created_at}</Date>
137+
<Date>
138+
{formatLatestMessageDate
139+
? formatLatestMessageDate(
140+
this.props.latestMessage.messageObject.created_at,
141+
)
142+
: this.props.latestMessage.created_at}
143+
</Date>
128144
</DetailsTop>
129145
<Message
130146
unread={this.props.unread > 0 ? this.props.unread : undefined}

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export interface ChannelPreviewUIComponentProps
324324
latestMessage: {
325325
text: string;
326326
created_at: string;
327-
originalMessageObject: Client.MessageResponse;
327+
messageObject: Client.MessageResponse;
328328
};
329329
/** Length at which latest message should be truncated */
330330
latestMessageLength: number;

0 commit comments

Comments
 (0)