diff options
Diffstat (limited to 'src/features/messages.js')
| -rw-r--r-- | src/features/messages.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index 6875856..6b3ff4c 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -5420,6 +5420,7 @@ export function messagesFeature(ctx) { lastScrollAt = Date.now(); if (!ui.profilePk && (!(ui.chatOpen && ui.msgView === 'feed') || ui.noteThread)) return; windowScrolled(ui.profilePk ? notesCache.get(ui.profilePk) : feed); + scrollWhen(ui.profilePk ? notesCache.get(ui.profilePk) : feed); // Starting to scroll up dismisses the notice: the reader is already // heading toward the new posts. Keyed rows keep their positions. // Upward only: holding the page still as posts go in above scrolls it @@ -5442,6 +5443,63 @@ export function messagesFeature(ctx) { else loadOlderFeed().catch(() => {}); }, { passive: true }); } + // How far back you've scrolled: while the feed (or a profile's posts) + // moves, a small chip under the top bar says when the post at the top of + // the screen was written, and fades a moment after the scrolling stops + // ("some sort of little counter that shows the date and time of posts + // where I'm in the timeline", Adam, 2026-11-17). Painted straight into the + // DOM, outside render(): it changes every frame of a fling. + let whenEl = null, whenRaf = 0, whenHide = 0, whenIdx = { list: null, map: null }; + function whenLabel(sec) { + const d = new Date(sec * 1000), now = new Date(); + const time = d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }); + const date = d.toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric', ...(d.getFullYear() !== now.getFullYear() ? { year: 'numeric' } : {}) }); + const ago = Math.max(0, (now - d) / 1000); + let rel = ''; + try { + const rtf = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' }); + rel = ago < 3600 ? rtf.format(-Math.max(1, Math.round(ago / 60)), 'minute') + : ago < 86400 ? rtf.format(-Math.round(ago / 3600), 'hour') + : ago < 86400 * 60 ? rtf.format(-Math.round(ago / 86400), 'day') + : ago < 86400 * 730 ? rtf.format(-Math.round(ago / (86400 * 30.4)), 'month') + : rtf.format(-Math.round(ago / (86400 * 365)), 'year'); + } catch {} + const today = d.toDateString() === now.toDateString(); + return (today ? time : date + ' · ' + time) + (rel ? ' · ' + rel : ''); + } + function scrollWhen(c) { + if (whenRaf || typeof document === 'undefined') return; + whenRaf = requestAnimationFrame(() => { + whenRaf = 0; + const list = c?.winList ? c.winList() : null; + const rows = list ? document.querySelectorAll('.notes-feed > .row[data-key]') : []; + const head = document.querySelector('.brand-header'); + const top = head ? Math.max(0, head.getBoundingClientRect().bottom) : 0; + // the post at the top of the screen, below the bar + let key = null, box = null; + for (const r of rows) { + const b = r.getBoundingClientRect(); + if (b.bottom > top + 12) { key = r.getAttribute('data-key'); box = r.parentElement.getBoundingClientRect(); break; } + } + if (whenIdx.list !== list) whenIdx = { list, map: list ? new Map(list.map((e) => [e.id, e])) : null }; + const ev = key && whenIdx.map?.get(key); + // only once you're past the first screenful: at the top the posts' own times say it + if (!ev || (window.scrollY || 0) < window.innerHeight * 0.75) { if (whenEl) whenEl.classList.remove('on'); return; } + if (!whenEl) { + whenEl = document.createElement('div'); + whenEl.className = 'feed-when'; + whenEl.setAttribute('aria-hidden', 'true'); + document.body.appendChild(whenEl); + } + const label = whenLabel(ev.created_at); + if (whenEl.textContent !== label) whenEl.textContent = label; + whenEl.style.top = (top + 8) + 'px'; + whenEl.style.left = (box.left + box.width / 2) + 'px'; + whenEl.classList.add('on'); + clearTimeout(whenHide); + whenHide = setTimeout(() => whenEl && whenEl.classList.remove('on'), 1200); + }); + } async function loadOlderNotes(pk) { const c = notesCache.get(pk); if (!c || c.status !== 'ready' || c.loadingMore || c.end) return; |
