mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-12 08:27:27 +02:00
fix: Use persistent subscription instead of request for real-time DMs
CRITICAL FIX: Changed from pool.request() to pool.subscription() to keep the relay connection open after EOSE. This was the root cause of why received messages didn't appear automatically. **Root Cause:** 1. pool.request() fetches historical events and CLOSES after EOSE 2. After EOSE, relay subscription is terminated 3. New gift wraps sent after that aren't received from relay 4. EventStore timeline subscription only fires when events are added 5. Result: Only locally-sent messages appeared (added to EventStore), but remotely-received messages were invisible until manual sync **Solution:** Use pool.subscription() which keeps the WebSocket connection OPEN after EOSE, allowing real-time message delivery. **Changes:** src/services/gift-wrap.ts: * Changed pool.request() to pool.subscription() * Added detailed logging for EVENT and EOSE responses * Properly stores relay subscription in subscriptions array for cleanup * Connection stays open indefinitely for real-time updates **Expected Behavior:** After EOSE: - ✅ Relay connection stays open (WebSocket active) - ✅ New gift wraps received in real-time from relay - ✅ EventStore.add() called automatically (via eventStore option) - ✅ Timeline subscription fires - ✅ Message appears in UI within 500ms Console logs should show: 1. 'Opening subscription to X relays for real-time gift wraps' 2. '✓ EOSE from wss://relay... (subscription stays open)' 3. '📨 Received gift wrap xxxxxx from relay' (when message arrives) 4. '📬 Timeline subscription fired with X gift wraps' 5. '💬 Updated conversations: X conversations, X total rumors' **Testing:** 1. Login and open self-chat 2. Send message from another client/device 3. Message should appear automatically within 500ms 4. No manual sync needed 5. Works for both self-chat and regular DMs Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -431,18 +431,32 @@ class GiftWrapService {
|
||||
|
||||
this.relaySubscription = sub;
|
||||
|
||||
// Request gift wraps from relays (always have relays - inbox or aggregator fallback)
|
||||
// Open a persistent subscription to relays for real-time updates
|
||||
// Use subscription() instead of request() to keep connection open after EOSE
|
||||
console.log(
|
||||
`[GiftWrap] Requesting gift wraps from ${relays.length} relays`,
|
||||
`[GiftWrap] Opening subscription to ${relays.length} relays for real-time gift wraps`,
|
||||
);
|
||||
pool.request(relays, [reqFilter], { eventStore }).subscribe({
|
||||
next: () => {
|
||||
// Events are automatically added to eventStore via the options
|
||||
},
|
||||
error: (err) => {
|
||||
console.warn(`[GiftWrap] Error fetching from relays:`, err);
|
||||
},
|
||||
});
|
||||
const relaySubscription = pool
|
||||
.subscription(relays, [reqFilter], { eventStore })
|
||||
.subscribe({
|
||||
next: (response) => {
|
||||
if (response.type === "EVENT") {
|
||||
console.log(
|
||||
`[GiftWrap] 📨 Received gift wrap ${response.event.id.slice(0, 8)} from relay`,
|
||||
);
|
||||
} else if (response.type === "EOSE") {
|
||||
console.log(
|
||||
`[GiftWrap] ✓ EOSE from ${response.relayUrl} (subscription stays open)`,
|
||||
);
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
console.warn(`[GiftWrap] Error in relay subscription:`, err);
|
||||
},
|
||||
});
|
||||
|
||||
// Store relay subscription for cleanup
|
||||
this.subscriptions.push(relaySubscription);
|
||||
}
|
||||
|
||||
/** Update pending count for UI display */
|
||||
|
||||
Reference in New Issue
Block a user