From 5eea754390153af66453c9afd1c1ee6b18770c4d Mon Sep 17 00:00:00 2001 From: Ian Macdonald Date: Mon, 13 Mar 2023 13:16:51 +0100 Subject: [PATCH 1/2] Don't use relative times for Conversations panel timestamps. Instead, we move to Telegram-style timestamping: * If the conversation last received a message today, just the time of the message is used, e.g. 12:03. * If the conversation last received a message in the last week, just the day of the message is used, e.g. Mon. * If the conversation last received a message more than a week ago, the date of the message is used, e.g. 13/03/2023. --- ts/components/conversation/Timestamp.tsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ts/components/conversation/Timestamp.tsx b/ts/components/conversation/Timestamp.tsx index c89d447adef..567f37565ba 100644 --- a/ts/components/conversation/Timestamp.tsx +++ b/ts/components/conversation/Timestamp.tsx @@ -4,6 +4,7 @@ import moment from 'moment'; // tslint:disable-next-line: no-submodule-imports import useInterval from 'react-use/lib/useInterval'; import styled from 'styled-components'; +import { sync as osLocaleSync } from 'os-locale'; type Props = { timestamp?: number; @@ -18,7 +19,6 @@ const TimestampContainerNotListItem = styled.div` font-size: var(--font-size-xs); line-height: 16px; letter-spacing: 0.3px; - text-transform: uppercase; user-select: none; `; @@ -48,14 +48,26 @@ export const Timestamp = (props: Props) => { const momentValue = moment(timestamp); let dateString: string = ''; + // Set the locale for the timestamps. + moment.locale(osLocaleSync().replace(/_/g, '-')); + if (momentFromNow) { - dateString = momentValue.fromNow(); + const now = moment(); + + if (momentValue.isSame(now, 'day')) { + // Today: Use the time only. + dateString = momentValue.format('LT'); + } else if (now.diff(momentValue, 'days') < 6) { + // Less than a week old: Use the day only. + dateString = momentValue.format('ddd'); + } else { + // More than a week old: Use the full date. + dateString = momentValue.format('L'); + } } else { dateString = momentValue.format('lll'); } - dateString = dateString.replace('minutes', 'mins').replace('minute', 'min'); - const title = moment(timestamp).format('llll'); if (props.isConversationListItem) { return {dateString}; From 7d16b7425cbb9c6305b8f766ae450597550bdc6e Mon Sep 17 00:00:00 2001 From: Ian Macdonald Date: Wed, 15 Mar 2023 10:25:12 +0100 Subject: [PATCH 2/2] Further refinements to the Conversations panel timestamps. See https://github.com/oxen-io/session-desktop/pull/2707#issuecomment-1469292835 for the discussion. * If the conversation last received a message today, just the time of the message is used, e.g. 12:03. * If the conversation last received a message in the last week, the day and time of the message are used, e.g. Mon 12:03. * If the conversation last received a message this calendar year, the month, day of month and time of the message are used, e.g. Mar 13 12:03. * If the conversation last received a message in a previous calendar year, the date of the message is used, e.g. 13/03/2023. --- ts/components/conversation/Timestamp.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ts/components/conversation/Timestamp.tsx b/ts/components/conversation/Timestamp.tsx index 567f37565ba..3a2046dd24d 100644 --- a/ts/components/conversation/Timestamp.tsx +++ b/ts/components/conversation/Timestamp.tsx @@ -58,10 +58,13 @@ export const Timestamp = (props: Props) => { // Today: Use the time only. dateString = momentValue.format('LT'); } else if (now.diff(momentValue, 'days') < 6) { - // Less than a week old: Use the day only. - dateString = momentValue.format('ddd'); + // Less than a week old: Use the day and time. + dateString = momentValue.format('ddd LT'); + } else if (momentValue.isSame(now, 'year')) { + // This year: Use the month, day of month and time. + dateString = momentValue.format('MMM D LT'); } else { - // More than a week old: Use the full date. + // Last year or older: Use the full date. dateString = momentValue.format('L'); } } else {