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/3318.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The join dialog no longer shows **Loading your Bots…** for ever on a home that has not connected Bot Social: `social/status` succeeds with `connected: false` and an empty Bot list, so the dialog now says Bot Social is not connected and offers **Open Bot Social settings** instead of an empty picker that looked like a read still on its way ([#3318](https://github.com/ThinkFlowLab/FlyBot/issues/3318)).
2 changes: 2 additions & 0 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ var ZH = {
"Scanned {code}.": "已扫描到 {code}。",
"Scanned {code}. Pick a Bot to join.": "已扫描到 {code}。选一个 Bot 加入。",
"Loading your Bots…": "正在加载你的 Bot…",
"Bot Social is not connected yet. Open Settings → Bot Social to connect it.": "Bot Social 还没连接。请到 设置 → Bot Social 连接。",
"Open Bot Social settings": "打开 Bot Social 设置",
"Waiting for {who} to let you in. If the group does not appear, press Join group to ask again.": "正在等 {who} 放你进去。如果群没有出现,再按一次「加入群」重新申请。",
"Asked to join {name}. It opens in your sidebar as soon as their FlyBot seats your Bots.": "已申请加入 {name}。对方的 FlyBot 放好你的 Bot 后,群会出现在你的侧边栏。",
"the group": "那个群",
Expand Down
2 changes: 2 additions & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ const ZH = {
'Scanned {code}.': '已扫描到 {code}。',
'Scanned {code}. Pick a Bot to join.': '已扫描到 {code}。选一个 Bot 加入。',
'Loading your Bots…': '正在加载你的 Bot…',
'Bot Social is not connected yet. Open Settings → Bot Social to connect it.': 'Bot Social 还没连接。请到 设置 → Bot Social 连接。',
'Open Bot Social settings': '打开 Bot Social 设置',
'Waiting for {who} to let you in. If the group does not appear, press Join group to ask again.': '正在等 {who} 放你进去。如果群没有出现,再按一次「加入群」重新申请。',
'Asked to join {name}. It opens in your sidebar as soon as their FlyBot seats your Bots.': '已申请加入 {name}。对方的 FlyBot 放好你的 Bot 后,群会出现在你的侧边栏。',
'the group': '那个群',
Expand Down
2 changes: 1 addition & 1 deletion docs/subsystems/social.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion patches/ds-bot/0001-core-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
Content: '内容',
'Referenced {labels}': '引用了 {labels}',
', ': '、',
@@ -41,22 +41,207 @@ const ZH = {
@@ -41,22 +41,209 @@ const ZH = {
' and ': '、',
and: '和',
'{count} members': '{count} 位成员',
Expand Down Expand Up @@ -1015,6 +1015,8 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
+ 'Scanned {code}.': '已扫描到 {code}。',
+ 'Scanned {code}. Pick a Bot to join.': '已扫描到 {code}。选一个 Bot 加入。',
+ 'Loading your Bots…': '正在加载你的 Bot…',
+ 'Bot Social is not connected yet. Open Settings → Bot Social to connect it.': 'Bot Social 还没连接。请到 设置 → Bot Social 连接。',
+ 'Open Bot Social settings': '打开 Bot Social 设置',
+ 'Waiting for {who} to let you in. If the group does not appear, press Join group to ask again.': '正在等 {who} 放你进去。如果群没有出现,再按一次「加入群」重新申请。',
+ 'Asked to join {name}. It opens in your sidebar as soon as their FlyBot seats your Bots.': '已申请加入 {name}。对方的 FlyBot 放好你的 Bot 后,群会出现在你的侧边栏。',
+ 'the group': '那个群',
Expand Down
4 changes: 3 additions & 1 deletion patches/ds-bot/0008-client-bundle.patch
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ diff --git a/client.js b/client.js
Content: "内容",
"Referenced {labels}": "引用了 {labels}",
", ": "、",
@@ -78,21 +78,206 @@ var ZH = {
@@ -78,21 +78,208 @@ var ZH = {
" and ": "、",
and: "和",
"{count} members": "{count} 位成员",
Expand Down Expand Up @@ -274,6 +274,8 @@ diff --git a/client.js b/client.js
+ "Scanned {code}.": "已扫描到 {code}。",
+ "Scanned {code}. Pick a Bot to join.": "已扫描到 {code}。选一个 Bot 加入。",
+ "Loading your Bots…": "正在加载你的 Bot…",
+ "Bot Social is not connected yet. Open Settings → Bot Social to connect it.": "Bot Social 还没连接。请到 设置 → Bot Social 连接。",
+ "Open Bot Social settings": "打开 Bot Social 设置",
+ "Waiting for {who} to let you in. If the group does not appear, press Join group to ask again.": "正在等 {who} 放你进去。如果群没有出现,再按一次「加入群」重新申请。",
+ "Asked to join {name}. It opens in your sidebar as soon as their FlyBot seats your Bots.": "已申请加入 {name}。对方的 FlyBot 放好你的 Bot 后,群会出现在你的侧边栏。",
+ "the group": "那个群",
Expand Down
20 changes: 19 additions & 1 deletion plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,11 @@ window.__ModuleLoader__.load({
const [scan, setScan] = useState(null)
const [invite, setInvite] = useState({ link: '', status: null })
const opened = useRef(false)
// `social/status` answers `connected: false` for a home with no Bot Social identity (#3318), and an
// empty `bots` then means "no Bot Social", not "still loading". It is kept beside the list rather
// than in a state of its own: the same answer sets `bots`, so that render already carries it, and
// the dialog's hook slots (seeded by role in the tests) stay where they were.
const connected = useRef(null)
useEffect(() => {
faceDialog.show(step === 'waiting' ? room?.roomId : null)
return () => faceDialog.show(null)
Expand All @@ -1479,6 +1484,7 @@ window.__ModuleLoader__.load({
useEffect(() => () => stopFaceScan(), [])
useEffect(() => {
call('social/status', {}).then(value => {
connected.current = typeof value?.connected === 'boolean' ? value.connected : null
const list = value?.bots ?? []
setBots(list)
setSelected(current => {
Expand Down Expand Up @@ -1898,7 +1904,19 @@ window.__ModuleLoader__.load({
selected: selected.includes(bot.id),
onToggle: () => toggle(bot.id),
}))),
bots.length === 0 ? h('div', { className: 'fs-hint' }, tr('Loading your Bots…')) : null,
// A home without Bot Social answers `connected: false` and an empty `bots` (#3318): that is
// not a read still on its way, so the dialog says what is missing and where to fix it
// instead of drawing a loading hint nobody can end.
connected.current === false ? h('div', {
className: 'fs-hint', 'data-flybot': 'face-join-offline', role: 'status',
}, tr('Bot Social is not connected yet. Open Settings → Bot Social to connect it.')) : null,
connected.current === false ? h('div', { className: 'fs-line' },
h('button', {
type: 'button', className: 'fs-btn', 'data-flybot': 'face-join-settings',
disabled: typeof actions?.openSettings !== 'function',
onClick: () => { onClose?.(); actions?.openSettings?.('social') },
}, tr('Open Bot Social settings'))) : null,
connected.current === false ? null : bots.length === 0 ? h('div', { className: 'fs-hint' }, tr('Loading your Bots…')) : null,
h('div', { className: 'fs-hint', 'data-flybot': 'face-join-room' },
tr('Room-only: friends do not see these Bots unless you invite them.')),
h('div', { className: 'fs-line' },
Expand Down
139 changes: 139 additions & 0 deletions plugins/social/test/face-join-not-connected.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// #3318: a home that has not connected Bot Social still sees "+" → Join by number or link, and that
// dialog drew "Loading your Bots…" for ever. The empty list was never a loading state: `social/status`
// answers `connected: false` on purpose (`social.js` `connected: Boolean(home)`, `bots: home ? … : []`),
// and the dialog's read took only `bots`. This pins the two halves of the answer — the sentence that
// says Bot Social is not connected with a way into Settings → Bot Social, and the absence of the
// loading hint — and keeps the connected window drawing the picker it always drew.
//
// React is not loaded (no jsdom in this repo): a small hook runtime below gives every component in the
// tree its own frame keyed by its position, so a state the status read sets redraws the dialog exactly
// as the browser would. The component source is the shipped `plugins/social/client.js`.
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'

const BOT = { id: 'b1', name: 'Chief', handle: '@chief.home', isMain: true }

// The dialog reads `document` for its Escape listener and `useStyles` for its sheet; no jsdom here,
// the other client tests stub the same three calls.
globalThis.document ??= { createElement: () => ({ setAttribute() {} }), head: { appendChild() {} }, getElementById: () => null, addEventListener() {}, removeEventListener() {} }

// One node of the drawn tree: a host element with its props, or a run of text.
function draw({ props, onCall } = {}) {
const modules = new Map()
const window = { __ModuleLoader__: { load: ({ id, factory }) => modules.set(id, factory) } }
new Function('window', readFileSync(new URL('../client.js', import.meta.url), 'utf8'))(window)

let current = null
let dirty = false
const frames = new Map()
const calls = []
const frameFor = key => {
if (!frames.has(key)) frames.set(key, { hooks: {}, effects: [], idx: 0 })
return frames.get(key)
}
const react = {
createElement: (type, attrs, ...children) => ({ type, props: attrs ?? {}, children: children.flat(Infinity) }),
Fragment: 'F',
useState(init) {
const frame = current
const at = frame.idx++
if (!(at in frame.hooks)) frame.hooks[at] = { value: typeof init === 'function' ? init() : init }
const slot = frame.hooks[at]
return [slot.value, next => {
const value = typeof next === 'function' ? next(slot.value) : next
if (value === slot.value) return
slot.value = value
dirty = true
}]
},
useEffect(fn, deps) {
const frame = current
frame.effects.push([frame.idx++, fn, deps])
},
useRef(value) {
const frame = current
const at = frame.idx++
if (!(at in frame.hooks)) frame.hooks[at] = { current: value }
return frame.hooks[at]
},
useMemo: (fn) => fn(),
useCallback: fn => fn,
}
globalThis.__flybot__ = {
call: (endpoint, payload) => {
calls.push([endpoint, payload])
return onCall ? onCall(endpoint, payload) : Promise.resolve({})
},
canRetry: () => true,
}
const social = modules.get('@flybot/social')(name => (name === 'react' ? react : {}))

const nodes = []
const walk = (node, key) => {
if (node === null || node === undefined || node === false || node === true) return
if (typeof node === 'string' || typeof node === 'number') { nodes.push({ text: String(node) }); return }
if (Array.isArray(node)) { node.forEach((child, at) => walk(child, `${key}.${at}`)); return }
if (typeof node.type === 'function') {
const frame = frameFor(key)
frame.idx = 0
frame.effects = []
const outer = current
current = frame
let drawn
try { drawn = node.type(node.props ?? {}) } finally { current = outer }
walk(drawn, `${key}(`)
return
}
nodes.push({ type: node.type, props: node.props ?? {} })
node.children.forEach((child, at) => walk(child, `${key}.${at}`))
}
const paint = () => {
nodes.length = 0
dirty = false
walk(react.createElement(social.FaceToFaceGroup, props), 'root')
for (const [, frame] of frames) {
for (const [at, fn, deps] of frame.effects) {
const slot = (frame.hooks[at] ??= {})
const same = Array.isArray(deps) && Array.isArray(slot.deps) && deps.length === slot.deps.length && deps.every((value, i) => value === slot.deps[i])
if (same) continue
slot.deps = deps ? [...deps] : undefined
fn()
}
}
}
return { nodes, calls, paint, settle: async () => { for (let round = 0; round < 6 && (dirty || round < 3); round++) { paint(); await new Promise(done => setTimeout(done, 0)) } } }
}

const byId = (nodes, id) => nodes.find(node => node.props?.['data-flybot'] === id)
const textsOf = nodes => nodes.filter(node => typeof node.text === 'string').map(node => node.text)
const props = () => ({ actions: { openSettings: () => {} }, roster: { byId: {}, readOnly: '' }, remoteChats: [], mode: 'join', onClose: () => {} })

// The status read succeeds and says this home has no Bot Social identity: that is the state the user
// is stuck in, not a read still on its way.
const disconnected = () => Promise.resolve({ connected: false, home: undefined, bots: [] })

test('#3318: a home without Bot Social is told so, not shown a loading hint', async () => {
const opened = []
const ui = draw({ props: { ...props(), actions: { openSettings: (...args) => opened.push(args) } }, onCall: disconnected })
await ui.settle()
const texts = textsOf(ui.nodes).join(' | ')
assert.ok(!texts.includes('Loading your Bots…'), `the dialog still claims the list is loading: ${texts}`)
assert.match(texts, /Bot Social is not connected/, `nothing says Bot Social is not connected: ${texts}`)
assert.match(texts, /Settings → Bot Social/, `the sentence does not name where to connect it: ${texts}`)
const go = byId(ui.nodes, 'face-join-settings')
assert.ok(go, 'no control leads to Settings → Bot Social')
assert.equal(go.props.disabled, false, 'the way into Settings is drawn disabled')
go.props.onClick({})
assert.deepEqual(opened, [['social']], 'the control does not open Settings → Bot Social')
})

test('#3318: a connected home still draws the Bot picker', async () => {
const ui = draw({ props: props(), onCall: () => Promise.resolve({ connected: true, home: 'self.home', bots: [BOT] }) })
await ui.settle()
const texts = textsOf(ui.nodes).join(' | ')
assert.ok(!texts.includes('Bot Social is not connected'), `a connected home is told it is not connected: ${texts}`)
assert.equal(byId(ui.nodes, 'face-pick')?.props['aria-label'], 'Your Bots', 'the Bot picker is gone from a connected dialog')
assert.ok(texts.includes('Chief'), 'the Bot list is not drawn')
assert.equal(byId(ui.nodes, 'face-join-settings'), undefined, 'a connected home is offered the Settings way out')
})
Loading