mirror of
https://github.com/dergigi/boris.git
synced 2025-12-23 09:34:19 +01:00
refactor: implement proper flight mode detection for highlights
- Always publish to all relays but track which ones are actually connected - isLocalOnly = true when only local relays are connected (flight mode) - Store event in EventStore first for immediate UI display - Track actually connected relays instead of guessing based on connection status - This should fix the airplane icon not showing in flight mode
This commit is contained in:
@@ -8,7 +8,6 @@ import { RELAYS } from '../config/relays'
|
|||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
import { UserSettings } from './settingsService'
|
import { UserSettings } from './settingsService'
|
||||||
import { isLocalRelay, areAllRelaysLocal } from '../utils/helpers'
|
import { isLocalRelay, areAllRelaysLocal } from '../utils/helpers'
|
||||||
import { publishEvent } from './writeService'
|
|
||||||
|
|
||||||
// Boris pubkey for zap splits
|
// Boris pubkey for zap splits
|
||||||
// npub19802see0gnk3vjlus0dnmfdagusqrtmsxpl5yfmkwn9uvnfnqylqduhr0x
|
// npub19802see0gnk3vjlus0dnmfdagusqrtmsxpl5yfmkwn9uvnfnqylqduhr0x
|
||||||
@@ -118,36 +117,53 @@ export async function createHighlight(
|
|||||||
// Sign the event
|
// Sign the event
|
||||||
const signedEvent = await factory.sign(highlightEvent)
|
const signedEvent = await factory.sign(highlightEvent)
|
||||||
|
|
||||||
// Check current connection status BEFORE publishing
|
// Store the event in EventStore first for immediate UI display
|
||||||
|
eventStore.add(signedEvent)
|
||||||
|
|
||||||
|
// Get all configured relays and determine which ones are connected
|
||||||
|
const allRelays = RELAYS
|
||||||
const connectedRelays = Array.from(relayPool.relays.values())
|
const connectedRelays = Array.from(relayPool.relays.values())
|
||||||
.filter(relay => relay.connected)
|
.filter(relay => relay.connected)
|
||||||
.map(relay => relay.url)
|
.map(relay => relay.url)
|
||||||
|
|
||||||
const hasRemoteConnection = connectedRelays.some(url => !isLocalRelay(url))
|
const connectedLocalRelays = connectedRelays.filter(url => isLocalRelay(url))
|
||||||
const hasLocalConnection = connectedRelays.some(url => isLocalRelay(url))
|
const connectedRemoteRelays = connectedRelays.filter(url => !isLocalRelay(url))
|
||||||
|
|
||||||
// Determine which relays we should publish to
|
// Always try to publish to ALL relays, but track which ones are actually connected
|
||||||
const targetRelays = hasRemoteConnection
|
const targetRelays = allRelays
|
||||||
? RELAYS // Publish to all relays (local + remote)
|
const actuallyConnectedRelays = connectedRelays
|
||||||
: RELAYS.filter(isLocalRelay) // Only publish to local relays
|
|
||||||
|
// isLocalOnly is true if we only have local relays connected (flight mode)
|
||||||
// isLocalOnly is true if we only have local connections (flight mode)
|
const isLocalOnly = connectedLocalRelays.length > 0 && connectedRemoteRelays.length === 0
|
||||||
const isLocalOnly = hasLocalConnection && !hasRemoteConnection
|
|
||||||
|
|
||||||
console.log('🔍 Highlight creation debug:', {
|
console.log('🔍 Highlight creation debug:', {
|
||||||
|
allRelays,
|
||||||
connectedRelays,
|
connectedRelays,
|
||||||
hasRemoteConnection,
|
connectedLocalRelays,
|
||||||
hasLocalConnection,
|
connectedRemoteRelays,
|
||||||
targetRelays,
|
targetRelays,
|
||||||
|
actuallyConnectedRelays,
|
||||||
isLocalOnly
|
isLocalOnly
|
||||||
})
|
})
|
||||||
|
|
||||||
// Use unified write service to store and publish
|
// Publish to all relays (fire-and-forget)
|
||||||
await publishEvent(relayPool, eventStore, signedEvent)
|
relayPool.publish(targetRelays, signedEvent)
|
||||||
|
.then(() => {
|
||||||
|
console.log('✅ Highlight published successfully to all relays')
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.warn('⚠️ Failed to publish highlight to some relays:', error)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Mark for offline sync if we're in local-only mode
|
||||||
|
if (isLocalOnly) {
|
||||||
|
const { markEventAsOfflineCreated } = await import('./offlineSyncService')
|
||||||
|
markEventAsOfflineCreated(signedEvent.id)
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to Highlight with relay tracking info and return IMMEDIATELY
|
// Convert to Highlight with relay tracking info and return IMMEDIATELY
|
||||||
const highlight = eventToHighlight(signedEvent)
|
const highlight = eventToHighlight(signedEvent)
|
||||||
highlight.publishedRelays = targetRelays
|
highlight.publishedRelays = actuallyConnectedRelays
|
||||||
highlight.isLocalOnly = isLocalOnly
|
highlight.isLocalOnly = isLocalOnly
|
||||||
|
|
||||||
return highlight
|
return highlight
|
||||||
|
|||||||
Reference in New Issue
Block a user