/
fegerV
/
Stogram
Обзор
Документация
Войти
/
fegerV
/
Stogram
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
client/src/utils/helpers.ts
54 строки
2 KB
engine-labs-app[bot]
feat(app): initial full-stack implementation of Stogram PWA messenger with real-time chat, VoIP, and Docker support
31 окт 2025, 17:21
31 окт 2025, 17:21
f58efe2
Код
Авторство
О чём код?
import { format, formatDistanceToNow, isToday, isYesterday } from 'date-fns'; export const formatMessageTime = (date: string | Date): string => { const messageDate = new Date(date); if (isToday(messageDate)) { return format(messageDate, 'HH:mm'); } if (isYesterday(messageDate)) { return 'Yesterday'; } return format(messageDate, 'MMM d, HH:mm'); }; export const formatLastSeen = (date: string | Date): string => { return formatDistanceToNow(new Date(date), { addSuffix: true }); }; export const getInitials = (name: string): string => { return name .split(' ') .map(word => word[0]) .join('') .toUpperCase() .slice(0, 2); }; export const formatFileSize = (bytes: number): string => { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]; }; export const getChatName = (chat: any, currentUserId: string): string => { if (chat.type === 'PRIVATE') { const otherMember = chat.members.find((m: any) => m.userId !== currentUserId); return otherMember?.user?.displayName || otherMember?.user?.username || 'Unknown'; } return chat.name || 'Group Chat'; }; export const getChatAvatar = (chat: any, currentUserId: string): string | null => { if (chat.type === 'PRIVATE') { const otherMember = chat.members.find((m: any) => m.userId !== currentUserId); return otherMember?.user?.avatar || null; } return chat.avatar; };