@@ -91,6 +91,30 @@ window.__ModuleLoader__.load({
9191 return message
9292 }
9393
94+ // A poll exists to refresh what the person can see: it does not run while the tab is hidden, it
95+ // reads once as the tab comes back, and the cadence restarts from that read rather than from the
96+ // hidden phase (#3315).
97+ function pollWhileVisible ( fn , ms ) {
98+ if ( typeof setInterval !== 'function' ) return undefined
99+ const doc = typeof document !== 'undefined' && typeof document . addEventListener === 'function' ? document : null
100+ const visible = ( ) => ! doc || ! doc . hidden
101+ let timer = null
102+ const stop = ( ) => { if ( timer !== null ) { clearInterval ( timer ) ; timer = null } }
103+ // The first read and the interval start together, so a mount that is already visible refreshes
104+ // at once and a hidden one refreshes when it is shown — one read, then a full period later.
105+ const start = ( ) => {
106+ stop ( )
107+ if ( ! visible ( ) ) return
108+ fn ( )
109+ timer = setInterval ( fn , ms )
110+ timer ?. unref ?. ( )
111+ }
112+ const onShow = ( ) => start ( )
113+ doc ?. addEventListener ( 'visibilitychange' , onShow )
114+ start ( )
115+ return ( ) => { stop ( ) ; doc ?. removeEventListener ( 'visibilitychange' , onShow ) }
116+ }
117+
94118 // Styles reuse ds-bot's sidebar tokens (--bt-ink, --bt-ink-2, --bt-ink-3, --bt-hover, --bt-line,
95119 // --bt-line-2, --bt-card, --bt-accent, --bt-tag-bg/-ink), like @flybot/tree, so both themes follow the app.
96120 const CSS = `
@@ -2556,8 +2580,6 @@ window.__ModuleLoader__.load({
25562580 useEffect ( ( ) => onDockRecords ( ( ) => bumpRecord ( value => value + 1 ) ) , [ sessionId ] )
25572581 const failures = dockFailuresOf ( sessionId )
25582582 const load = ( ) => {
2559- // #3080: a tab that is not on screen has nobody reading these cards; showing it catches up below.
2560- if ( typeof document !== 'undefined' && document . hidden ) return
25612583 call ( 'social/status' , { } ) . then ( value => {
25622584 setItems ( Array . isArray ( value ?. approvals ) ? value . approvals : [ ] )
25632585 setStatusLoaded ( true )
@@ -2567,18 +2589,9 @@ window.__ModuleLoader__.load({
25672589 setListLoaded ( true )
25682590 } , ( ) => { } )
25692591 }
2570- useEffect ( ( ) => {
2571- load ( )
2572- if ( typeof setInterval !== 'function' ) return undefined
2573- const timer = setInterval ( load , 5000 )
2574- timer ?. unref ?. ( )
2575- // #3080: a tab that sat in the background catches up the moment it is shown, not one beat later
2576- // (the same shape `everySecond` uses above).
2577- const onShow = ( ) => { if ( typeof document === 'undefined' || ! document . hidden ) load ( ) }
2578- const doc = typeof document !== 'undefined' && typeof document . addEventListener === 'function' ? document : null
2579- doc ?. addEventListener ( 'visibilitychange' , onShow )
2580- return ( ) => { clearInterval ( timer ) ; doc ?. removeEventListener ( 'visibilitychange' , onShow ) }
2581- } , [ ] )
2592+ // #3080: a tab nobody is reading keeps no timer; coming back reads once at once and restarts the
2593+ // cadence from that read (`pollWhileVisible`).
2594+ useEffect ( ( ) => pollWhileVisible ( load , 5000 ) , [ ] )
25822595 const session = { sessionId, roster, room, bot, handle : bot ?. remote ?. handle }
25832596 // The person who gets it (#418, #498), not the friend's Bot: a local hold already names the person.
25842597 const named = list => list . map ( ( item ) => {
@@ -3254,17 +3267,9 @@ window.__ModuleLoader__.load({
32543267 const dismissShareRequest = item => call ( 'social/share-request-dismiss' , { id : item . id } ) . then ( applyStatus , e => setError ( errorText ( e ) ) )
32553268 const dismissAccept = item => call ( 'social/accept-notice-dismiss' , { id : item . id } ) . then ( applyStatus , e => setError ( errorText ( e ) ) )
32563269 const askShareBack = item => call ( 'social/ask-share-back' , { botId : item . botId , to : item . from , noticeId : item . id } ) . then ( applyStatus , e => setError ( errorText ( e ) ) )
3257- useEffect ( ( ) => {
3258- loadApprovals ( )
3259- if ( typeof setInterval !== 'function' ) return undefined
3260- const tick = ( ) => {
3261- if ( typeof document !== 'undefined' && document . hidden ) return
3262- loadApprovals ( )
3263- }
3264- const timer = setInterval ( tick , 15_000 )
3265- timer ?. unref ?. ( )
3266- return ( ) => clearInterval ( timer )
3267- } , [ ] )
3270+ // A hidden tab is not looking at these requests either, so the 15 s poll runs only while the page
3271+ // is on screen and a tab that comes back reads once at once (`pollWhileVisible`).
3272+ useEffect ( ( ) => pollWhileVisible ( loadApprovals , 15_000 ) , [ ] )
32683273 useEffect ( ( ) => facePanel . bind ( mode => { setFaceMode ( mode === 'start' ? 'start' : 'join' ) ; setFaceOpen ( true ) } ) , [ ] )
32693274 useEffect ( ( ) => addFriendPanel . bind ( ( ) => setAdding ( true ) ) , [ ] )
32703275 const unavailable = String ( error ) . startsWith ( 'Social is not running:' )
@@ -3705,14 +3710,25 @@ window.__ModuleLoader__.load({
37053710 const remote = bot ?. remote
37063711 const home = remote ?. home
37073712 const handle = remote ?. handle
3708- const [ auto , setAuto ] = useState ( false )
3713+ // #3366: `null` is "nobody read it yet". A read that failed used to leave `false` here, which is
3714+ // drawn exactly like a setting that is off — and the switch stayed live, so the person could read
3715+ // the setting as one they chose. The failure is the card's answer while it lasts, and the value
3716+ // stays unknown until a read answers (#3323/#3325/#3359 for the same shape elsewhere).
3717+ const [ auto , setAuto ] = useState ( null )
37093718 const [ saving , setSaving ] = useState ( false )
37103719 const [ busy , setBusy ] = useState ( false )
37113720 const [ asking , setAsking ] = useState ( false )
37123721 const [ error , setError ] = useState ( '' )
3722+ const [ readError , setReadError ] = useState ( '' )
37133723 useEffect ( ( ) => {
37143724 if ( ! home ) return undefined
3715- call ( 'social/settings' , { } ) . then ( value => setAuto ( value ?. autoAccept ?. [ home ] === true ) , ( ) => { } )
3725+ let live = true
3726+ call ( 'social/settings' , { } ) . then ( value => {
3727+ if ( ! live ) return
3728+ setAuto ( value ?. autoAccept ?. [ home ] === true )
3729+ setReadError ( '' )
3730+ } , e => { if ( live ) setReadError ( errorText ( e ) ) } )
3731+ return ( ) => { live = false }
37163732 } , [ home ] )
37173733 if ( ! handle ) return null
37183734 const toggleAuto = async ( on ) => {
@@ -3759,9 +3775,10 @@ window.__ModuleLoader__.load({
37593775 // The box holds the setting only; the destructive link sits apart, below it (#274).
37603776 h ( 'div' , { className : 'fs-card fs-friend-auto' , 'data-flybot' : 'friend-auto-box' } ,
37613777 h ( 'label' , { className : 'fs-auto' , title : AUTO_SEND_NOTE , 'data-flybot' : 'friend-auto-send' } ,
3762- h ( 'input' , { type : 'checkbox' , checked : auto === true , disabled : saving || ! home , onChange : e => toggleAuto ( e . target . checked ) } ) ,
3778+ h ( 'input' , { type : 'checkbox' , checked : auto === true , disabled : saving || ! home || auto === null , onChange : e => toggleAuto ( e . target . checked ) } ) ,
37633779 `Auto-send my Bots' replies to ${ who } ` ) ,
3764- h ( 'div' , { className : 'fs-hint' , 'data-flybot' : 'friend-auto-hint' } , `Your Bots' replies to ${ who } go out without asking you first. What you type is not affected.` ) ) ,
3780+ h ( 'div' , { className : 'fs-hint' , 'data-flybot' : 'friend-auto-hint' } , `Your Bots' replies to ${ who } go out without asking you first. What you type is not affected.` ) ,
3781+ readError ? h ( 'div' , { className : 'fs-status' , 'data-tone' : 'error' , role : 'status' , 'data-flybot' : 'friend-auto-read-error' } , readError ) : null ) ,
37653782 h ( 'div' , { className : 'fs-friend-remove' , 'data-flybot' : 'friend-remove-row' } , asking
37663783 ? h ( 'span' , { className : 'fs-leave-ask' , 'data-flybot' : 'remove-friend-bot-confirm' } ,
37673784 h ( 'span' , { className : 'fs-hint' } , `Remove ${ botWithOwner ( bot . name , named ) } from your list? ${ keepLine } ` ) ,
@@ -3953,21 +3970,29 @@ window.__ModuleLoader__.load({
39533970 useStyles ( )
39543971 const handle = typeof bot ?. remote ?. handle === 'string' ? bot . remote . handle : ''
39553972 const [ paused , setPaused ] = useState ( null )
3973+ // #3359: a read that failed is not a chat that is not paused. The failure is the card's answer
3974+ // while it lasts (the friends list draws it the same way, #3323), so it gets its own state and is
3975+ // drawn before the card; a later success replaces it.
3976+ const [ error , setError ] = useState ( '' )
39563977 useEffect ( ( ) => {
39573978 setPaused ( null )
3979+ setError ( '' )
39583980 if ( ! handle ) return undefined
39593981 let live = true
39603982 const load = ( ) => {
3961- if ( typeof document !== 'undefined' && document . hidden ) return
3962- call ( 'social/paused' , { handle } ) . then ( value => { if ( live ) setPaused ( value ?. paused ?? null ) } , ( ) => { } )
3983+ call ( 'social/paused' , { handle } ) . then ( value => {
3984+ if ( ! live ) return
3985+ setPaused ( value ?. paused ?? null )
3986+ setError ( '' )
3987+ } , e => { if ( live ) setError ( errorText ( e ) ) } )
39633988 }
3964- load ( )
3965- if ( typeof setInterval !== 'function' ) return ( ) => { live = false }
3966- const timer = setInterval ( load , 5000 )
3967- timer ?. unref ?. ( )
3968- return ( ) => { live = false ; clearInterval ( timer ) }
3989+ const stop = pollWhileVisible ( load , 5000 )
3990+ return ( ) => { live = false ; stop ?. ( ) }
39693991 } , [ handle ] )
3970- if ( ! handle || ! paused ) return null
3992+ if ( ! handle ) return null
3993+ // The 5 s read is the retry: no button, no Extend, no turn count (owner 2026-10-19).
3994+ if ( error ) return h ( 'div' , { className : 'fs-hold' , 'data-flybot' : 'social-paused-error' , role : 'status' } , error )
3995+ if ( ! paused ) return null
39713996 return h ( 'div' , { className : 'fs-hold fs-chat-approval' , 'data-flybot' : 'chat-paused' , role : 'status' } ,
39723997 h ( 'div' , { className : 'fs-label' } , 'Chat paused' ) ,
39733998 h ( 'div' , { className : 'fs-draft' } , `${ paused . reason ? `Bot Social paused the last chat with this Bot (${ paused . reason } ).` : 'Bot Social paused the last chat with this Bot.' } Send your message again: it starts a new chat.` ) )
0 commit comments