added date on chat

This commit is contained in:
SlimusMinus
2026-08-13 00:52:56 +03:00
parent 7b87dbe5c5
commit 053b7b52ad
4 changed files with 45 additions and 2 deletions

View File

@@ -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]);