Compare commits

..
2 Commits
3 changed files with 73 additions and 11 deletions
+50 -8
View File
@@ -915,16 +915,56 @@ export function formatTimeAgo(timestamp) {
}
// Store timestamps for real-time updates
const timeAgoElements = new Map(); // element -> timestamp
const timeAgoElements = new Map(); // element -> { timestamp, eventId }
// Track relay publish counts per event ID from broadcastProgress events.
// Keyed by event ID → number of successful relay publishes.
const relayCountByEventId = new Map();
// Listen for broadcast progress events to capture final relay counts.
// The worker emits ndkBroadcastProgress with phase 'done' containing the
// total successful count. We store it so post cards can show "21r - 1h".
if (typeof window !== 'undefined') {
window.addEventListener('ndkBroadcastProgress', (event) => {
const d = event.detail;
if (!d || d.phase !== 'done') return;
const eventId = d.eventId;
if (!eventId) return;
relayCountByEventId.set(eventId, d.successful || 0);
// Update any already-rendered time elements for this event.
timeAgoElements.forEach((info, element) => {
if (info.eventId === eventId && element.isConnected) {
element.textContent = formatTimeAgoWithRelays(info.timestamp, info.eventId);
}
});
});
}
/**
* Format time ago with optional relay count prefix.
* Shows "21r - 1h" when a relay count is available, else just "1h".
* @param {number} timestamp - Unix timestamp in seconds
* @param {string} [eventId] - Optional event ID to look up relay count
* @returns {string}
*/
function formatTimeAgoWithRelays(timestamp, eventId) {
const timeStr = formatTimeAgo(timestamp);
if (eventId && relayCountByEventId.has(eventId)) {
const count = relayCountByEventId.get(eventId);
return `${count}r - ${timeStr}`;
}
return timeStr;
}
/**
* Register an element for time updates
* @param {HTMLElement} element - The element to update
* @param {number} timestamp - Unix timestamp in seconds
* @param {string} [eventId] - Optional event ID for relay count display
*/
export function registerTimeAgo(element, timestamp) {
timeAgoElements.set(element, timestamp);
element.textContent = formatTimeAgo(timestamp);
export function registerTimeAgo(element, timestamp, eventId) {
timeAgoElements.set(element, { timestamp, eventId });
element.textContent = formatTimeAgoWithRelays(timestamp, eventId);
}
/**
@@ -932,9 +972,9 @@ export function registerTimeAgo(element, timestamp) {
* Call this periodically (e.g., every 30 seconds)
*/
export function updateTimeAgos() {
timeAgoElements.forEach((timestamp, element) => {
timeAgoElements.forEach((info, element) => {
if (element.isConnected) {
element.textContent = formatTimeAgo(timestamp);
element.textContent = formatTimeAgoWithRelays(info.timestamp, info.eventId);
} else {
// Clean up detached elements
timeAgoElements.delete(element);
@@ -1085,10 +1125,12 @@ export function renderFooterRow(eventId, eventData, options = {}) {
container.appendChild(nutzapItem);
container.appendChild(midControls);
// Time as the final item in the same row
// Time as the final item in the same row.
// Pass eventId so registerTimeAgo can prepend the relay count
// (e.g., "21r - 1h") when a broadcastProgress 'done' event arrives.
const timeEl = document.createElement('span');
timeEl.className = 'divPostTime';
registerTimeAgo(timeEl, eventData.created_at);
registerTimeAgo(timeEl, eventData.created_at, eventId);
container.appendChild(timeEl);
footerRow.appendChild(container);
+3 -3
View File
@@ -1,5 +1,5 @@
{
"VERSION": "v0.7.69",
"VERSION_NUMBER": "0.7.69",
"BUILD_DATE": "2026-06-30T13:19:30.001Z"
"VERSION": "v0.7.71",
"VERSION_NUMBER": "0.7.71",
"BUILD_DATE": "2026-06-30T13:33:08.793Z"
}
+20
View File
@@ -6308,6 +6308,8 @@ async function handlePublish(requestId, event, port) {
broadcast({
type: 'broadcastProgress',
sessionId: publishSessionId,
eventId: ndkEvent.id || null,
eventKind: event.kind,
phase: 'done',
total: totalTarget,
successful: publishedSoFar.size,
@@ -6323,6 +6325,24 @@ async function handlePublish(requestId, event, port) {
}
}
// For non-broadcast publishes, emit a simplified broadcastProgress 'done'
// event so post cards can still show the relay count (e.g., "3r - 1h").
// We use the relaySet result to count successful relays.
if (!isBroadcast) {
const successCount = relaySet ? relaySet.size : 0;
broadcast({
type: 'broadcastProgress',
sessionId: publishSessionId,
eventId: ndkEvent.id || null,
eventKind: event.kind,
phase: 'done',
total: successCount,
successful: successCount,
failed: 0,
latestRelay: null,
});
}
// Get detailed relay results
const relayResults = {
successful: [],