From 702d8a843e16150c20647f85b89dcc4646a4b170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 2 Jul 2023 22:21:05 +0200 Subject: [PATCH] Show year for older chat messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../features/chats/components/chat-message-list.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/soapbox/features/chats/components/chat-message-list.tsx b/app/soapbox/features/chats/components/chat-message-list.tsx index b06c34664..69ad7690b 100644 --- a/app/soapbox/features/chats/components/chat-message-list.tsx +++ b/app/soapbox/features/chats/components/chat-message-list.tsx @@ -109,9 +109,13 @@ const ChatMessageList: React.FC = ({ chat }) => { return []; } + const currentYear = new Date().getFullYear(); + return chatMessages.reduce((acc: any, curr: any, idx: number) => { const lastMessage = formattedChatMessages[idx - 1]; + const messageDate = new Date(curr.created_at); + if (lastMessage) { switch (timeChange(lastMessage, curr)) { case 'today': @@ -123,7 +127,14 @@ const ChatMessageList: React.FC = ({ chat }) => { case 'date': acc.push({ 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; }