|
|
|
|
@ -238,13 +238,13 @@
@@ -238,13 +238,13 @@
|
|
|
|
|
|
|
|
|
|
const allRelays = relayManager.getProfileReadRelays(); |
|
|
|
|
const replyFilters: any[] = [ |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': [threadId] }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': [threadId] }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#a': [threadId] }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#A': [threadId] }, |
|
|
|
|
{ kinds: [KIND.SHORT_TEXT_NOTE], '#e': [threadId] }, |
|
|
|
|
{ kinds: [KIND.VOICE_REPLY], '#e': [threadId] }, |
|
|
|
|
{ kinds: [KIND.ZAP_RECEIPT], '#e': [threadId] } |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': [threadId], limit: 500 }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': [threadId], limit: 500 }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#a': [threadId], limit: 500 }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#A': [threadId], limit: 500 }, |
|
|
|
|
{ kinds: [KIND.SHORT_TEXT_NOTE], '#e': [threadId], limit: 500 }, |
|
|
|
|
{ kinds: [KIND.VOICE_REPLY], '#e': [threadId], limit: 500 }, |
|
|
|
|
{ kinds: [KIND.ZAP_RECEIPT], '#e': [threadId], limit: 500 } |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// fetchEvents with useCache:true returns cached data immediately if available, |
|
|
|
|
@ -319,13 +319,16 @@
@@ -319,13 +319,16 @@
|
|
|
|
|
|
|
|
|
|
nestedSubscriptionActive = true; |
|
|
|
|
|
|
|
|
|
// Limit reply IDs to prevent massive subscriptions |
|
|
|
|
const limitedReplyIds = Array.from(allReplyIds).slice(0, 100); |
|
|
|
|
|
|
|
|
|
// Use a single subscription that covers all reply IDs |
|
|
|
|
const nestedFilters: any[] = [ |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.SHORT_TEXT_NOTE], '#e': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.VOICE_REPLY], '#e': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.ZAP_RECEIPT], '#e': Array.from(allReplyIds) } |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': limitedReplyIds, limit: 200 }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': limitedReplyIds, limit: 200 }, |
|
|
|
|
{ kinds: [KIND.SHORT_TEXT_NOTE], '#e': limitedReplyIds, limit: 200 }, |
|
|
|
|
{ kinds: [KIND.VOICE_REPLY], '#e': limitedReplyIds, limit: 200 }, |
|
|
|
|
{ kinds: [KIND.ZAP_RECEIPT], '#e': limitedReplyIds, limit: 200 } |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
nostrClient.fetchEvents( |
|
|
|
|
@ -347,37 +350,41 @@
@@ -347,37 +350,41 @@
|
|
|
|
|
const allRelays = relayManager.getProfileReadRelays(); |
|
|
|
|
let hasNewReplies = true; |
|
|
|
|
let iterations = 0; |
|
|
|
|
const maxIterations = 10; |
|
|
|
|
const maxIterations = 3; // Reduced from 10 to prevent excessive fetching |
|
|
|
|
const maxReplyIdsPerIteration = 100; // Limit number of reply IDs to check per iteration |
|
|
|
|
|
|
|
|
|
while (hasNewReplies && iterations < maxIterations) { |
|
|
|
|
iterations++; |
|
|
|
|
hasNewReplies = false; |
|
|
|
|
const allReplyIds = new Set([ |
|
|
|
|
const allReplyIds = Array.from(new Set([ |
|
|
|
|
...comments.map(c => c.id), |
|
|
|
|
...kind1Replies.map(r => r.id), |
|
|
|
|
...yakBacks.map(y => y.id), |
|
|
|
|
...zapReceipts.map(z => z.id) |
|
|
|
|
]); |
|
|
|
|
])); |
|
|
|
|
|
|
|
|
|
// Limit the number of reply IDs to prevent massive queries |
|
|
|
|
const limitedReplyIds = allReplyIds.slice(0, maxReplyIdsPerIteration); |
|
|
|
|
|
|
|
|
|
if (allReplyIds.size > 0) { |
|
|
|
|
if (limitedReplyIds.length > 0) { |
|
|
|
|
const nestedFilters: any[] = [ |
|
|
|
|
// Fetch nested kind 1111 comments - check both e/E and a/A tags |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#a': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#A': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': limitedReplyIds, limit: 200 }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': limitedReplyIds, limit: 200 }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#a': limitedReplyIds, limit: 200 }, |
|
|
|
|
{ kinds: [KIND.COMMENT], '#A': limitedReplyIds, limit: 200 }, |
|
|
|
|
// Fetch nested kind 1 replies |
|
|
|
|
{ kinds: [KIND.SHORT_TEXT_NOTE], '#e': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.SHORT_TEXT_NOTE], '#e': limitedReplyIds, limit: 200 }, |
|
|
|
|
// Fetch nested yak backs |
|
|
|
|
{ kinds: [KIND.VOICE_REPLY], '#e': Array.from(allReplyIds) }, |
|
|
|
|
{ kinds: [KIND.VOICE_REPLY], '#e': limitedReplyIds, limit: 200 }, |
|
|
|
|
// Fetch nested zap receipts |
|
|
|
|
{ kinds: [KIND.ZAP_RECEIPT], '#e': Array.from(allReplyIds) } |
|
|
|
|
{ kinds: [KIND.ZAP_RECEIPT], '#e': limitedReplyIds, limit: 200 } |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
const nestedReplies = await nostrClient.fetchEvents( |
|
|
|
|
nestedFilters, |
|
|
|
|
allRelays, |
|
|
|
|
{ useCache: true, cacheResults: true } |
|
|
|
|
{ useCache: true, cacheResults: true, timeout: 5000 } |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Add new replies by type |
|
|
|
|
@ -537,21 +544,21 @@
@@ -537,21 +544,21 @@
|
|
|
|
|
|
|
|
|
|
// Always fetch kind 1111 comments - check both e and E tags, and a and A tags |
|
|
|
|
replyFilters.push( |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': [threadId] }, // Lowercase e tag |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': [threadId] }, // Uppercase E tag (NIP-22) |
|
|
|
|
{ kinds: [KIND.COMMENT], '#a': [threadId] }, // Lowercase a tag (some clients use wrong tags) |
|
|
|
|
{ kinds: [KIND.COMMENT], '#A': [threadId] } // Uppercase A tag (NIP-22 for addressable events) |
|
|
|
|
{ kinds: [KIND.COMMENT], '#e': [threadId], limit: 500 }, // Lowercase e tag |
|
|
|
|
{ kinds: [KIND.COMMENT], '#E': [threadId], limit: 500 }, // Uppercase E tag (NIP-22) |
|
|
|
|
{ kinds: [KIND.COMMENT], '#a': [threadId], limit: 500 }, // Lowercase a tag (some clients use wrong tags) |
|
|
|
|
{ kinds: [KIND.COMMENT], '#A': [threadId], limit: 500 } // Uppercase A tag (NIP-22 for addressable events) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// For kind 1 events, fetch kind 1 replies |
|
|
|
|
// Also fetch kind 1 replies for any event (some apps use kind 1 for everything) |
|
|
|
|
replyFilters.push({ kinds: [KIND.SHORT_TEXT_NOTE], '#e': [threadId] }); |
|
|
|
|
replyFilters.push({ kinds: [KIND.SHORT_TEXT_NOTE], '#e': [threadId], limit: 500 }); |
|
|
|
|
|
|
|
|
|
// Fetch yak backs (kind 1244) - voice replies |
|
|
|
|
replyFilters.push({ kinds: [KIND.VOICE_REPLY], '#e': [threadId] }); |
|
|
|
|
replyFilters.push({ kinds: [KIND.VOICE_REPLY], '#e': [threadId], limit: 500 }); |
|
|
|
|
|
|
|
|
|
// Fetch zap receipts (kind 9735) |
|
|
|
|
replyFilters.push({ kinds: [KIND.ZAP_RECEIPT], '#e': [threadId] }); |
|
|
|
|
replyFilters.push({ kinds: [KIND.ZAP_RECEIPT], '#e': [threadId], limit: 500 }); |
|
|
|
|
|
|
|
|
|
// Don't use cache when reloading after publishing - we want fresh data |
|
|
|
|
const allReplies = await nostrClient.fetchEvents( |
|
|
|
|
|