Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3327.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The **paused-chat card** and the **connecting** state of **Settings → Bot Social** no longer keep reading while the tab is hidden: both 5 s / 2 s polls now go through `pollWhileVisible`, so a hidden tab makes no call, coming back reads once at once and restarts the cadence from that read, and unmount removes the listener. Nothing on screen changes; only when the reads happen while hidden ([#3327](https://github.com/ThinkFlowLab/FlyBot/issues/3327)).
1 change: 1 addition & 0 deletions docs/subsystems/social.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Creating a group opens its Session with zero turns, and the host draws no sessio
### Face-room human turns and UI polish (#166, #167)

- Refresh only what the person can see (#3315): the waiting room's 2 s and the room overview's 3 s `social/face-rooms` polls go through `pollWhileVisible`, so a hidden tab makes no call, coming back reads once at once, and the cadence restarts from that read (clear and rebuild) rather than from the hidden phase's remainder; unmount removes the `visibilitychange` listener.
- The paused-chat card's 5 s `social/paused` read and the connecting page's 2 s `social/server` read are the same rule (#3327): both go through `pollWhileVisible`, so a hidden tab makes no call, coming back reads once at once and restarts the cadence from that read, and unmount removes the listener. Nothing on screen changes; only when the reads happen while hidden.
- A plain human line in an open face-to-face room is logged and fanned out once, and starts a single pass of every local Bot (admin first, capped at 6, no @ needed; #287, #295; core `openingSpeakers`, see [core-host](core-host.md)). Since #299 the Bots pick the responder from a plain line (they may `[PASS]`; the first Bot that answers ends the round unless the line is to everyone; the first Bot answers if all pass on the owner's own line), and a line to everyone or `@all` is unchanged. A friend's attested plain line (or `@all`) starts the same pass on this home, routed and single like the owner's own line (#462) (the plugin passes `attested: true` to `postHuman` only for a stamped line); an attested line that names Bots starts only the Bot(s) it names by the label the picker shows (`Friend's Chief`) or by handle; `plugins/social/test` has the two-home case. **Explicit mention list (#293):** the sender's host resolves the picker's labels against the room (`faceMentions().handles`; core `onFaceLine(fn)` passes `{ mentions }` for the owner's typed line) and `faceApi.send` puts the handles in `mentions` next to `typed_by_owner` only when `GET /v1/platform` `features` lists `mentions` (the one feature probe, `serverMentions()`); never on the legacy envelope, Bot lines or an older server. The receiver reads `mentions` (`cleanMentions`, at most 8 handles) only from a line the server attests `typed_by_owner` (`renderFaceEvent`), and `postHuman` resolves the handles against the room first (`mentionedByHandle`): only my own Bots in the list answer; a list naming nobody the room knows, or no list, falls back to the label/name reading above. The composer's `@` picker inserts the label text, so the handles are derived from it at send, not tracked in the composer.
- The encoded human line is bounded at 18 000 **code points**, not UTF-16 units (#2641): `encodeFaceHuman` cuts with the file's own `cutCodePoints`, the same 18 000-code-point budget `coSeatEnvelope` applies to an outgoing room-share line, so a person's line whose bound falls inside an emoji ends on a code-point boundary instead of storing a lone surrogate that the next UTF-8 write turns into `U+FFFD`.
- A peer string that arrives from the far side of Bot Social is capped on **code points** too (#2693): `cleanText` (60, so a friend's Bot or owner display name), `safeName` (120, an attached file's name), `draftText` (800), the person label `grantPersonView` builds in `mcp-client.js` (60), and the error and invite lines the host caps. All of them cut with one `cutCodePoints` in `src/code-points.js`, which `social.js` still re-exports (#2581), so a value whose bound falls inside an emoji keeps the emoji whole instead of ending on a lone high surrogate that a stored setting, a remote session name or a cross-home payload would show as `U+FFFD`; a value already stored that way is left unchanged rather than migrated.
Expand Down
17 changes: 8 additions & 9 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4028,14 +4028,12 @@ window.__ModuleLoader__.load({
if (!handle) return undefined
let live = true
const load = () => {
if (typeof document !== 'undefined' && document.hidden) return
call('social/paused', { handle }).then(value => { if (live) setPaused(value?.paused ?? null) }, () => {})
}
load()
if (typeof setInterval !== 'function') return () => { live = false }
const timer = setInterval(load, 5000)
timer?.unref?.()
return () => { live = false; clearInterval(timer) }
// #3315 ③: a hidden tab holds no timer and reads nothing; coming back reads once at once and
// restarts the 5 s cadence from that read instead of waiting out the hidden period.
const stop = pollWhileVisible(load, 5000)
return () => { live = false; stop?.() }
}, [handle])
if (!handle || !paused) return null
const note = paused.reason
Expand Down Expand Up @@ -4147,9 +4145,10 @@ window.__ModuleLoader__.load({
useEffect(() => { void refresh() }, [])
// A server that is still connecting is read again until it settles.
useEffect(() => {
if (view?.state !== 'connecting' || typeof setInterval !== 'function') return undefined
const timer = setInterval(() => { void refresh() }, 2000)
return () => clearInterval(timer)
if (view?.state !== 'connecting') return undefined
// #3315 ④: the connecting state polls the same way as every other panel: no timer while the
// tab is hidden, one read as it comes back, and the 2 s cadence restarts from that read.
return pollWhileVisible(() => { void refresh() }, 2000)
}, [view?.state])
// What the current server lists, read once the page shows it.
useEffect(() => {
Expand Down
56 changes: 56 additions & 0 deletions plugins/social/test/poll-visibility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,59 @@ test('#3315: the waiting room stops while hidden and reads once when the tab ret
unmount(cleanups)
} finally { s.restore() }
})

// ③ follow-up to #3315: the paused-chat card reloaded on a bare 5 s `setInterval`. Its read returned
// early while `document.hidden`, so a hidden tab kept the timer ticking for nothing and a tab that
// came back waited out the rest of the period instead of reading once at once.
const pausedChat = app => mount(app, 'PausedChat', { bot: { id: 'b1', name: 'Chief', remote: { handle: '@chief.home' } } })

test('#3315: the paused-chat card stops while hidden and reads once when the tab returns', () => {
const s = scene({ hidden: true })
try {
const pausedCalls = () => s.calls.filter(([endpoint]) => endpoint === 'social/paused').length
const { cleanups } = pausedChat(s.app)
assert.equal(pausedCalls(), 0, 'a hidden card makes no read')
assert.deepEqual(s.timers.periods(), [], 'a hidden card holds no poll timer')
s.doc.hidden = false
s.doc.emit('visibilitychange')
assert.equal(pausedCalls(), 1, `coming back made ${pausedCalls()} read(s), not one`)
assert.deepEqual(s.timers.periods(), [5000], 'the 5 s cadence restarts from that read')
s.doc.hidden = true
s.doc.emit('visibilitychange')
s.timers.tick()
assert.equal(pausedCalls(), 1, 'going hidden again stops it')
unmount(cleanups)
} finally { s.restore() }
})

// ④ follow-up to #3315: the connecting state of Settings → Bot Social read `social/server` again on a
// bare 2 s `setInterval` with no visibility check at all, so a hidden tab polled at full rate and a
// tab that came back did not read before the next tick.
const SETTINGS_VIEW = {
state: 'connecting', server: 'https://social.example', source: 'settings', displayName: 'Home',
defaultServer: null, known: [], platform: null,
}
const settingsOpen = app => mount(app, 'SocialServerSettings', { t: undefined, Section: undefined, Row: undefined, actions: {}, roster }, [
SETTINGS_VIEW, null, null, false, '', '', null, false, null, null, '', null,
])

test('#3315: the connecting settings page stops while hidden and reads once when the tab returns', () => {
const s = scene({ hidden: true })
try {
const serverCalls = () => s.calls.filter(([endpoint]) => endpoint === 'social/server').length
const { cleanups } = settingsOpen(s.app)
const afterMount = serverCalls()
assert.deepEqual(s.timers.periods(), [], 'a hidden settings page holds no poll timer')
s.doc.hidden = false
s.doc.emit('visibilitychange')
assert.equal(serverCalls(), afterMount + 1, `coming back made ${serverCalls() - afterMount} read(s), not one`)
assert.deepEqual(s.timers.periods(), [2000], 'the 2 s cadence restarts from that read')
s.timers.tick()
assert.equal(serverCalls(), afterMount + 2, 'and one period later reads again, once')
s.doc.hidden = true
s.doc.emit('visibilitychange')
s.timers.tick()
assert.equal(serverCalls(), afterMount + 2, 'going hidden again stops it')
unmount(cleanups)
} finally { s.restore() }
})
Loading