Browse Source

bug-fixes

imwald
Silberengel 1 month ago
parent
commit
a69f0da702
  1. 5
      src/lib/link.ts
  2. 7
      src/lib/profile-search-query.ts
  3. 3
      src/lib/pubkey.ts
  4. 18
      src/services/client-replaceable-events.service.ts

5
src/lib/link.ts

@ -87,8 +87,9 @@ export const toNoteList = ({
return `${path}?${query.toString()}` return `${path}?${query.toString()}`
} }
export const toProfile = (userId: string) => { export const toProfile = (userId: string) => {
if (userId.startsWith('npub') || userId.startsWith('nprofile')) return `/users/${userId}` const t = userId.trim().replace(/^nostr:/i, '').trim()
const npub = nip19.npubEncode(userId) if (t.startsWith('npub') || t.startsWith('nprofile')) return `/users/${t}`
const npub = nip19.npubEncode(t)
return `/users/${npub}` return `/users/${npub}`
} }
export const toProfileList = ({ search, domain }: { search?: string; domain?: string }) => { export const toProfileList = ({ search, domain }: { search?: string; domain?: string }) => {

7
src/lib/profile-search-query.ts

@ -7,13 +7,10 @@ const HEX_PUBKEY = /^[0-9a-f]{64}$/i
* profile fetch and IndexedDB kind-0 matching. NIP-50 text search does not match bech32 npubs. * profile fetch and IndexedDB kind-0 matching. NIP-50 text search does not match bech32 npubs.
*/ */
export function decodeProfileSearchQueryToPubkeyHex(raw: string): string | undefined { export function decodeProfileSearchQueryToPubkeyHex(raw: string): string | undefined {
const q = raw.trim() const q = raw.trim().replace(/^nostr:/i, '').trim()
if (!q) return undefined if (!q) return undefined
if (HEX_PUBKEY.test(q)) return q.toLowerCase() if (HEX_PUBKEY.test(q)) return q.toLowerCase()
let bech = q const bech = q
if (q.toLowerCase().startsWith('nostr:')) {
bech = q.slice(6).trim()
}
try { try {
const { type, data } = nip19.decode(bech) const { type, data } = nip19.decode(bech)
if (type === 'npub' && typeof data === 'string') return data.toLowerCase() if (type === 'npub' && typeof data === 'string') return data.toLowerCase()

3
src/lib/pubkey.ts

@ -49,7 +49,8 @@ export function pubkeyToNpub(pubkey: string) {
} }
export function userIdToPubkey(userId: string) { export function userIdToPubkey(userId: string) {
const trimmed = userId.trim() /** NIP-21 `nostr:` URI — must strip before bech32 / hex branches (otherwise we miss `npub1` / hex). */
const trimmed = userId.trim().replace(/^nostr:/i, '').trim()
if (!trimmed) return '' if (!trimmed) return ''
if (trimmed.startsWith('npub1') || trimmed.startsWith('nprofile1')) { if (trimmed.startsWith('npub1') || trimmed.startsWith('nprofile1')) {

18
src/services/client-replaceable-events.service.ts

@ -359,15 +359,21 @@ export class ReplaceableEventService {
'replaceableEventFromBigRelaysDataloader.loadMany' 'replaceableEventFromBigRelaysDataloader.loadMany'
) )
} catch (err) { } catch (err) {
// Never throw: a DataLoader/relay error would abort the whole feed profile batch and skip IDB
// hydration in {@link fetchProfilesForPubkeysBody}. Degrade like timeout — gaps fill from IDB/session below.
if (isPromiseTimeoutError(err)) { if (isPromiseTimeoutError(err)) {
logger.warn('[ReplaceableEventService] Profile batch network load timed out', { logger.warn('[ReplaceableEventService] Profile batch network load timed out', {
missingCount: stillMissing.length, missingCount: stillMissing.length,
kind kind
}) })
newEvents = stillMissing.map(() => undefined)
} else { } else {
throw err logger.warn('[ReplaceableEventService] Profile batch network load failed', {
missingCount: stillMissing.length,
kind,
error: err instanceof Error ? err.message : String(err)
})
} }
newEvents = stillMissing.map(() => undefined)
} }
newEvents.forEach((event, idx) => { newEvents.forEach((event, idx) => {
if (event && !(event instanceof Error)) { if (event && !(event instanceof Error)) {
@ -1060,10 +1066,16 @@ export class ReplaceableEventService {
'fetchProfilesForPubkeys' 'fetchProfilesForPubkeys'
) )
} catch (err) { } catch (err) {
if (!isPromiseTimeoutError(err)) throw err if (isPromiseTimeoutError(err)) {
logger.warn('[ReplaceableEventService] fetchProfilesForPubkeys exceeded wall timeout', { logger.warn('[ReplaceableEventService] fetchProfilesForPubkeys exceeded wall timeout', {
pubkeyCount: deduped.length pubkeyCount: deduped.length
}) })
} else {
logger.warn('[ReplaceableEventService] fetchProfilesForPubkeys failed; using session / IndexedDB only', {
pubkeyCount: deduped.length,
error: err instanceof Error ? err.message : String(err)
})
}
return this.fetchProfilesForPubkeysLocalFallback(deduped) return this.fetchProfilesForPubkeysLocalFallback(deduped)
} }
} }

Loading…
Cancel
Save