Display usernames instead of pubkeys in discovered relays Follows column — query Dexie profiles table for displayName/name, fall back to truncated pubkey if no profile cached

This commit is contained in:
Laan Tungir
2026-06-26 20:20:37 -04:00
parent 6ad2d37a23
commit e734f33542
3 changed files with 41 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
{
"VERSION": "v0.7.52",
"VERSION_NUMBER": "0.7.52",
"BUILD_DATE": "2026-06-26T17:43:40.739Z"
"VERSION": "v0.7.53",
"VERSION_NUMBER": "0.7.53",
"BUILD_DATE": "2026-06-27T00:20:37.017Z"
}

View File

@@ -6443,6 +6443,11 @@ async function handleSetRelayEventLogging(requestId, enabled, port) {
// from followed authors who write to relays the user does not subscribe to.
// For each discovered relay we also report which followed pubkeys it serves,
// by inverting ndk.outboxTracker.data (pubkey -> OutboxItem{writeRelays}).
function shortHexPubkey(hex) {
if (!hex || hex.length < 16) return hex || '-';
return `${hex.slice(0, 8)}${hex.slice(-4)}`;
}
// Cache for discovered relays — rebuilt only when the contact list changes.
let discoveredRelaysCache = null;
let discoveredRelaysCacheKey = '';
@@ -6527,6 +6532,29 @@ async function handleGetDiscoveredRelays(requestId, port) {
} catch (_) {}
}
// Look up profile names for all serving pubkeys from the Dexie
// profiles table so we can display usernames instead of pubkeys.
const pubkeyToName = new Map();
try {
const adapter = ndk?.cacheAdapter?.adapter;
if (adapter?.db?.profiles) {
const allServingPubkeys = new Set();
for (const servingSet of relayServesPubkeys.values()) {
for (const pk of servingSet) allServingPubkeys.add(pk);
}
// Query profiles table for all serving pubkeys.
for (const pk of allServingPubkeys) {
try {
const row = await adapter.db.profiles.get(pk);
if (row) {
const name = row.displayName || row.name || '';
if (name) pubkeyToName.set(pk, name);
}
} catch (_) {}
}
}
} catch (_) {}
// Build the discovered relays list: relays that are NOT in the
// user's own kind 10002 but ARE in follows' kind 10002.
const relays = [];
@@ -6534,11 +6562,17 @@ async function handleGetDiscoveredRelays(requestId, port) {
if (ownRelays.has(relayUrl)) continue; // skip user's own relays
// Check live connection status from the pool.
const poolRelay = ndk.pool?.relays?.get(relayUrl);
const pubkeys = Array.from(servingSet);
// Map pubkeys to names, falling back to truncated pubkey.
const names = pubkeys.map(pk =>
pubkeyToName.get(pk) || shortHexPubkey(pk)
);
relays.push({
url: relayUrl,
status: poolRelay?.status || 0,
connected: poolRelay ? poolRelay.status >= 5 : false,
servingPubkeys: Array.from(servingSet)
servingPubkeys: pubkeys,
servingNames: names
});
}
// Sort by serving count (most follows first), then by URL.

View File

@@ -1383,9 +1383,9 @@ const versionInfo = await getVersion();
for (const relay of relaysWithFollows) {
const connected = relay.connected ? SVG_CHECKED : SVG_UNCHECKED;
const servingCount = Array.isArray(relay.servingPubkeys) ? relay.servingPubkeys.length : 0;
const followsList = Array.isArray(relay.servingPubkeys)
? relay.servingPubkeys.map(shortNpub).join(', ')
: '-';
const followsList = Array.isArray(relay.servingNames) && relay.servingNames.length > 0
? relay.servingNames.join(', ')
: (Array.isArray(relay.servingPubkeys) ? relay.servingPubkeys.map(shortNpub).join(', ') : '-');
const rowClass = relay.connected ? 'tblRowConnected' : '';
html += `<tr class="${rowClass}">`;