mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-22 10:33:24 +00:00
8ee81c2d64
feat: Add HTTP utility functions for trusted origin checks feat: Implement typing status broadcasting for live chat clients and agents. feat: Add support for signed URLs in media manager fix: Update database migration to handle duplicate visitors with same email address. feat: Add conversation subscription and typing message models for WebSocket communication feat: Implement conversation subscription management in WebSocket hub this is used for broadcasting typing indicator. feat: Revamp widget JavaScript to improve mobile responsiveness and show unread messages if any.
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
import { format, differenceInMinutes, differenceInHours, differenceInDays } from 'date-fns'
|
|
|
|
export function getRelativeTime (timestamp, now = new Date()) {
|
|
try {
|
|
const mins = differenceInMinutes(now, timestamp)
|
|
const hours = differenceInHours(now, timestamp)
|
|
const days = differenceInDays(now, timestamp)
|
|
|
|
if (mins === 0) return 'Just now'
|
|
if (mins < 60) return `${mins}m ago`
|
|
if (hours < 24) return `${hours}h ago`
|
|
if (days < 7) return `${days}d ago`
|
|
return format(timestamp, 'MMMM d, yyyy h:mm a')
|
|
} catch (error) {
|
|
console.error('Error parsing time', error, 'timestamp', timestamp)
|
|
return ''
|
|
}
|
|
}
|
|
|
|
export const formatDuration = (seconds, showSeconds = true) => {
|
|
const totalSeconds = Math.floor(seconds)
|
|
if (totalSeconds < 60) return `${totalSeconds}s`
|
|
if (totalSeconds < 3600) return `${Math.floor(totalSeconds / 60)}m ${totalSeconds % 60}s`
|
|
const hours = Math.floor(totalSeconds / 3600)
|
|
const mins = Math.floor((totalSeconds % 3600) / 60)
|
|
const secs = totalSeconds % 60
|
|
return `${hours}h ${mins}m ${showSeconds ? `${secs}s` : ''}`
|
|
} |