added date on chat
This commit is contained in:
@@ -31,6 +31,33 @@ export function getLastMessageText(chat) {
|
||||
return lm?.content || "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Красиво форматирует время сообщения из createdAt (ISO-строка без таймзоны):
|
||||
* сегодня — только время ("14:05"), раньше — дата + время ("12 авг, 14:05").
|
||||
*/
|
||||
export function formatMessageTime(createdAt, locale) {
|
||||
const ms = toTimeMs(createdAt);
|
||||
if (!ms) return "";
|
||||
const date = new Date(ms);
|
||||
const now = new Date();
|
||||
const isSameDay =
|
||||
date.getFullYear() === now.getFullYear() &&
|
||||
date.getMonth() === now.getMonth() &&
|
||||
date.getDate() === now.getDate();
|
||||
const isSameYear = date.getFullYear() === now.getFullYear();
|
||||
|
||||
const time = new Intl.DateTimeFormat(locale, { hour: "2-digit", minute: "2-digit" }).format(date);
|
||||
if (isSameDay) return time;
|
||||
|
||||
const datePart = new Intl.DateTimeFormat(locale, {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: isSameYear ? undefined : "numeric",
|
||||
}).format(date);
|
||||
|
||||
return `${datePart}, ${time}`;
|
||||
}
|
||||
|
||||
export function getChatDisplayInfo(chat, post, unreadMap, t) {
|
||||
const title = post?.title || chat.otherUserName || chat.otherUser?.name || t('chat.user');
|
||||
const imgSrc = getImageUrl(post?.images?.[0]);
|
||||
|
||||
Reference in New Issue
Block a user