fix: use server-side time_ago for notification timestamps
This commit is contained in:
@@ -295,7 +295,7 @@ function renderNotifications(items, unreadCount) {
|
||||
+ '<div class="notif-content">'
|
||||
+ '<div class="notif-title">' + escapeHtml(n.title) + '</div>'
|
||||
+ '<div class="notif-message">' + escapeHtml(n.message) + '</div>'
|
||||
+ '<div class="notif-time">' + timeAgo(n.created_at) + '</div>'
|
||||
+ '<div class="notif-time">' + (n.time_ago || '') + '</div>'
|
||||
+ '</div>'
|
||||
+ (n.is_read ? '' : '<div class="notif-dot"></div>')
|
||||
+ '</div>';
|
||||
@@ -374,18 +374,6 @@ function escapeHtml(str) {
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
function timeAgo(dateStr) {
|
||||
const now = new Date();
|
||||
const d = new Date(dateStr.replace(' ', 'T') + (dateStr.includes('Z') ? '' : 'Z'));
|
||||
const diff = Math.floor((now - d) / 1000);
|
||||
if (diff < 60) return 'just now';
|
||||
if (diff < 3600) return Math.floor(diff / 60) + 'm ago';
|
||||
if (diff < 86400) return Math.floor(diff / 3600) + 'h ago';
|
||||
const days = Math.floor(diff / 86400);
|
||||
if (days < 7) return days + 'd ago';
|
||||
return d.toLocaleDateString();
|
||||
}
|
||||
|
||||
// Poll unread count every 60s
|
||||
setInterval(updateUnreadCount, 60000);
|
||||
// Initial fetch
|
||||
|
||||
Reference in New Issue
Block a user