Show year for older chat messages
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
acdc781bc2
commit
702d8a843e
1 changed files with 12 additions and 1 deletions
|
@ -109,9 +109,13 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat }) => {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentYear = new Date().getFullYear();
|
||||||
|
|
||||||
return chatMessages.reduce((acc: any, curr: any, idx: number) => {
|
return chatMessages.reduce((acc: any, curr: any, idx: number) => {
|
||||||
const lastMessage = formattedChatMessages[idx - 1];
|
const lastMessage = formattedChatMessages[idx - 1];
|
||||||
|
|
||||||
|
const messageDate = new Date(curr.created_at);
|
||||||
|
|
||||||
if (lastMessage) {
|
if (lastMessage) {
|
||||||
switch (timeChange(lastMessage, curr)) {
|
switch (timeChange(lastMessage, curr)) {
|
||||||
case 'today':
|
case 'today':
|
||||||
|
@ -123,7 +127,14 @@ const ChatMessageList: React.FC<IChatMessageList> = ({ chat }) => {
|
||||||
case 'date':
|
case 'date':
|
||||||
acc.push({
|
acc.push({
|
||||||
type: 'divider',
|
type: 'divider',
|
||||||
text: intl.formatDate(new Date(curr.created_at), { weekday: 'short', hour: 'numeric', minute: '2-digit', month: 'short', day: 'numeric' }),
|
text: intl.formatDate(messageDate, {
|
||||||
|
weekday: 'short',
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: '2-digit',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
year: messageDate.getFullYear() !== currentYear ? '2-digit' : undefined,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue