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/3061-approve-all-english.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The **Approve all** button in a chat's approval dock and the count in its tooltip now follow the window's language: a Chinese window reads 全部批准(3) and 共 3 条 · 发给 Eve, Bob instead of English, and an English window no longer reads 条 in its tooltip ([#3061](https://github.com/ThinkFlowLab/FlyBot/issues/3061)).
7 changes: 7 additions & 0 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ var ZH = {
"Not sent": "未发出",
"{name} · Not sent": "{name} · 未发出",
"Sent to {to}": "已发给 {to}",
// #3061: the approve-all button and its title, which used to draw english (and a chinese count) in
// every window.
"Approve all ({n})": "全部批准({n})",
"1 hold": "共 1 条",
"{n} holds": "共 {n} 条",
"1 hold · to {to}": "共 1 条 · 发给 {to}",
"{n} holds · to {to}": "共 {n} 条 · 发给 {to}",
"Auto-sent to {to}": "已自动发给 {to}",
"Not sent: delivery failed": "未发出:发送失败",
"{from} → {to}": "{from} → {to}",
Expand Down
7 changes: 7 additions & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ const ZH = {
'Not sent': '未发出',
'{name} · Not sent': '{name} · 未发出',
'Sent to {to}': '已发给 {to}',
// #3061: the approve-all button and its title, which used to draw english (and a chinese count) in
// every window.
'Approve all ({n})': '全部批准({n})',
'1 hold': '共 1 条',
'{n} holds': '共 {n} 条',
'1 hold · to {to}': '共 1 条 · 发给 {to}',
'{n} holds · to {to}': '共 {n} 条 · 发给 {to}',
'Auto-sent to {to}': '已自动发给 {to}',
'Not sent: delivery failed': '未发出:发送失败',
'{from} → {to}': '{from} → {to}',
Expand Down
3 changes: 0 additions & 3 deletions core/test/i18n-template-draws.baseline.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": 1,
"entries": [
"plugins/social/client.js:Approve all ({})",
"plugins/social/client.js:Asked to join {}. It opens in your sidebar as soon as their FlyBot seats your Bots.",
"plugins/social/client.js:Auto-send my Bots' replies to {}",
"plugins/social/client.js:Auto-send {} → room",
Expand All @@ -28,8 +27,6 @@
"plugins/social/client.js:{} Send your message again: it starts a new chat.",
"plugins/social/client.js:{} failed: {}",
"plugins/social/client.js:{} tried to start a chat with {}. {} is not shared with them.",
"plugins/social/client.js:{} 条",
"plugins/social/client.js:{} 条 · to {}",
"plugins/social/client.js:{}'s replies to {} go out without asking you first.#1",
"plugins/social/client.js:{}'s replies to {} go out without asking you first.#2",
"plugins/timeline/client.js:Could not copy the report: {}",
Expand Down
18 changes: 12 additions & 6 deletions core/test/i18n-template-draws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ test('the plugins on main are pinned, and a template draw nobody pinned fails',
assert.equal(Number.parseInt(out.stdout.trimEnd().split('\n').at(-1), 10), current.size, 'the summary line counts the pins')
})

// Acceptance: the list names the Approve-all row on main, and its identity is the skeleton the reader
// sees, never the line a comment above it happens to move.
test('the Approve-all template on main is a member, and 12 comment lines leave the set identical', () => {
const file = fileURLToPath(new URL('../../plugins/social/client.js', import.meta.url))
const source = readFileSync(file, 'utf8')
const member = scanTemplateDraws().filter(entry => entry.file === 'plugins/social/client.js' && entry.key === '{} 条 · to {}')
// Acceptance: a row with two holes is a member of the list, and its identity is the skeleton the reader
// sees, never the line a comment above it happens to move. The Approve-all draw this used to read on main
// now goes through `tr()` (#3061), so the same shape is pinned here as a source rather than borrowed from
// the repository — the scanner's promise is about any source, and the copy on main is no longer a draw.
test('a two-hole template draw is a member, and 12 comment lines leave the set identical', () => {
const source = [
'const approveAllTitle = approveRecipients.length ? `${n} 条 · to ${who}` : `${n} 条`',
'const approveAllLabel = `Approve all (${n})`',
"h('button', { title: approveAllTitle }, approveAllLabel)",
'',
].join('\n')
const member = templateDraws(source, 'plugins/social/client.js').filter(entry => entry.key === '{} 条 · to {}')
assert.equal(member.length, 1, 'the Approve-all row names its two holes')
const shifted = `${'// a comment above the draw\n'.repeat(12)}${source}`
const keys = entries => entries.map(entry => `${entry.file}\u0000${entry.key}`).sort()
Expand Down
9 changes: 8 additions & 1 deletion patches/ds-bot/0001-core-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
Content: '内容',
'Referenced {labels}': '引用了 {labels}',
', ': '、',
@@ -41,22 +41,86 @@ const ZH = {
@@ -41,22 +41,93 @@ const ZH = {
' and ': '、',
and: '和',
'{count} members': '{count} 位成员',
Expand Down Expand Up @@ -912,6 +912,13 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
+ 'Not sent': '未发出',
+ '{name} · Not sent': '{name} · 未发出',
+ 'Sent to {to}': '已发给 {to}',
+ // #3061: the approve-all button and its title, which used to draw english (and a chinese count) in
+ // every window.
+ 'Approve all ({n})': '全部批准({n})',
+ '1 hold': '共 1 条',
+ '{n} holds': '共 {n} 条',
+ '1 hold · to {to}': '共 1 条 · 发给 {to}',
+ '{n} holds · to {to}': '共 {n} 条 · 发给 {to}',
+ 'Auto-sent to {to}': '已自动发给 {to}',
+ 'Not sent: delivery failed': '未发出:发送失败',
+ '{from} → {to}': '{from} → {to}',
Expand Down
9 changes: 8 additions & 1 deletion patches/ds-bot/0008-client-bundle.patch
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ diff --git a/client.js b/client.js
Content: "内容",
"Referenced {labels}": "引用了 {labels}",
", ": "、",
@@ -78,21 +78,85 @@ var ZH = {
@@ -78,21 +78,92 @@ var ZH = {
" and ": "、",
and: "和",
"{count} members": "{count} 位成员",
Expand Down Expand Up @@ -219,6 +219,13 @@ diff --git a/client.js b/client.js
+ "Not sent": "未发出",
+ "{name} · Not sent": "{name} · 未发出",
+ "Sent to {to}": "已发给 {to}",
+ // #3061: the approve-all button and its title, which used to draw english (and a chinese count) in
+ // every window.
+ "Approve all ({n})": "全部批准({n})",
+ "1 hold": "共 1 条",
+ "{n} holds": "共 {n} 条",
+ "1 hold · to {to}": "共 1 条 · 发给 {to}",
+ "{n} holds · to {to}": "共 {n} 条 · 发给 {to}",
+ "Auto-sent to {to}": "已自动发给 {to}",
+ "Not sent: delivery failed": "未发出:发送失败",
+ "{from} → {to}": "{from} → {to}",
Expand Down
3 changes: 0 additions & 3 deletions patches/ds-bot/files/test/i18n-template-draws.baseline.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": 1,
"entries": [
"plugins/social/client.js:Approve all ({})",
"plugins/social/client.js:Asked to join {}. It opens in your sidebar as soon as their FlyBot seats your Bots.",
"plugins/social/client.js:Auto-send my Bots' replies to {}",
"plugins/social/client.js:Auto-send {} → room",
Expand All @@ -28,8 +27,6 @@
"plugins/social/client.js:{} Send your message again: it starts a new chat.",
"plugins/social/client.js:{} failed: {}",
"plugins/social/client.js:{} tried to start a chat with {}. {} is not shared with them.",
"plugins/social/client.js:{} 条",
"plugins/social/client.js:{} 条 · to {}",
"plugins/social/client.js:{}'s replies to {} go out without asking you first.#1",
"plugins/social/client.js:{}'s replies to {} go out without asking you first.#2",
"plugins/timeline/client.js:Could not copy the report: {}",
Expand Down
18 changes: 12 additions & 6 deletions patches/ds-bot/files/test/i18n-template-draws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ test('the plugins on main are pinned, and a template draw nobody pinned fails',
assert.equal(Number.parseInt(out.stdout.trimEnd().split('\n').at(-1), 10), current.size, 'the summary line counts the pins')
})

// Acceptance: the list names the Approve-all row on main, and its identity is the skeleton the reader
// sees, never the line a comment above it happens to move.
test('the Approve-all template on main is a member, and 12 comment lines leave the set identical', () => {
const file = fileURLToPath(new URL('../../plugins/social/client.js', import.meta.url))
const source = readFileSync(file, 'utf8')
const member = scanTemplateDraws().filter(entry => entry.file === 'plugins/social/client.js' && entry.key === '{} 条 · to {}')
// Acceptance: a row with two holes is a member of the list, and its identity is the skeleton the reader
// sees, never the line a comment above it happens to move. The Approve-all draw this used to read on main
// now goes through `tr()` (#3061), so the same shape is pinned here as a source rather than borrowed from
// the repository — the scanner's promise is about any source, and the copy on main is no longer a draw.
test('a two-hole template draw is a member, and 12 comment lines leave the set identical', () => {
const source = [
'const approveAllTitle = approveRecipients.length ? `${n} 条 · to ${who}` : `${n} 条`',
'const approveAllLabel = `Approve all (${n})`',
"h('button', { title: approveAllTitle }, approveAllLabel)",
'',
].join('\n')
const member = templateDraws(source, 'plugins/social/client.js').filter(entry => entry.key === '{} 条 · to {}')
assert.equal(member.length, 1, 'the Approve-all row names its two holes')
const shifted = `${'// a comment above the draw\n'.repeat(12)}${source}`
const keys = entries => entries.map(entry => `${entry.file}\u0000${entry.key}`).sort()
Expand Down
12 changes: 9 additions & 3 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@
function qrRsGenerator(degree) {
let poly = [1]
for (let i = 0; i < degree; i += 1) {
const next = new Array(poly.length + 1).fill(0)

Check warning on line 715 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
for (let j = 0; j < poly.length; j += 1) {
next[j] ^= poly[j]
next[j + 1] ^= qrMul(poly[j], QR_GF_EXP[i])
Expand All @@ -723,7 +723,7 @@
}
function qrRsRemainder(bytes, degree) {
const gen = qrRsGenerator(degree)
const res = new Array(bytes.length + degree).fill(0)

Check warning on line 726 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
for (let i = 0; i < bytes.length; i += 1) res[i] = bytes[i]
for (let i = 0; i < bytes.length; i += 1) {
const factor = res[i]
Expand Down Expand Up @@ -797,8 +797,8 @@
}
function qrSkeleton(version) {
const size = version * 4 + 17
const modules = Array.from({ length: size }, () => new Array(size).fill(0))

Check warning on line 800 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
const fixed = Array.from({ length: size }, () => new Array(size).fill(false))

Check warning on line 801 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
const set = (x, y, dark) => { modules[y][x] = dark ? 1 : 0; fixed[y][x] = true }
const finder = (cx, cy) => {
for (let dy = -4; dy <= 4; dy += 1) {
Expand Down Expand Up @@ -1062,7 +1062,7 @@
return out
}
const cleanRoomName = (value, fallback = '') => stripUntrustedMarkers(value)
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 1065 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim()
Expand Down Expand Up @@ -1106,7 +1106,7 @@
let matrix
try { matrix = qrMatrix(text) } catch { return null }
const size = matrix.size
return h('div', { className: 'fs-qr', 'data-flybot': kind, 'data-modules': size, ...(attrs ?? {}) },

Check warning on line 1109 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-useless-fallback-in-spread)

Empty fallbacks in spreads are unnecessary
h('svg', {
className: 'fs-qr-svg', width: size, height: size, viewBox: `0 0 ${size} ${size}`,
role: 'img', 'aria-label': label, shapeRendering: 'crispEdges',
Expand Down Expand Up @@ -1412,7 +1412,7 @@
const next = id || null
if (next === this.roomId) return
this.roomId = next
for (const fn of [...this.listeners]) fn()

Check warning on line 1415 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-useless-spread)

Using a spread operator here creates a new array unnecessarily.
},
subscribe(fn) {
this.listeners.add(fn)
Expand Down Expand Up @@ -2478,7 +2478,7 @@
const dockRecords = new Map()
const dockRecordListeners = new Set()
const dockRecordKey = (sessionId, id) => `${id}:${sessionId}`
const dockRecordChanged = () => { for (const fn of [...dockRecordListeners]) fn() }

Check warning on line 2481 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-useless-spread)

Using a spread operator here creates a new array unnecessarily.
const dockRecordOf = (sessionId, id) => dockRecords.get(dockRecordKey(sessionId, id))
const dockFailuresOf = (sessionId) => {
const out = {}
Expand Down Expand Up @@ -2538,6 +2538,9 @@

function ChatApprovalDock({ sessionId, roster, room, bot, actions, claim, t } = {}) {
useStyles()
// #3061: the dock's own strings read the window's dictionary. The host hands the translator down
// as a prop; without one the module translator (the one every other line here uses) answers.
const trIn = (text, params) => (typeof t === 'function' ? t(text, params) : tr(text, params))
const locked = readOnlyReason(roster)
const [items, setItems] = useState([])
const [local, setLocal] = useState([])
Expand Down Expand Up @@ -2780,10 +2783,13 @@
// cannot be undone is readable before it.
const toApprove = mine.filter(waiting)
const approveRecipients = recipientNames(toApprove)
const approveAllLabel = `Approve all (${toApprove.length})`
// #3061: both strings go through the window's dictionary; the source is english and the count
// is the holds the click sends, the names are the people it reaches.
const approveAllLabel = trIn('Approve all ({n})', { n: toApprove.length })
// A failed hold counts in `mine` but not in the send, so one hold can be the whole batch (#3015).
const approveAllTitle = approveRecipients.length
? `${toApprove.length} 条 · to ${approveRecipients.join(', ')}`
: `${toApprove.length} 条`
? trIn(toApprove.length === 1 ? '1 hold · to {to}' : '{n} holds · to {to}', { n: toApprove.length, to: approveRecipients.join(', ') })
: trIn(toApprove.length === 1 ? '1 hold' : '{n} holds', { n: toApprove.length })
// #1640: this card is drawn exactly when the room's own card is decided somewhere this chat does
// not draw. A held reply is decided on its own bubble here (#418); a Bot's hold is decided in a
// chat this person can open (#254). A card we cannot place keeps the neutral sentence: the dock
Expand Down
47 changes: 43 additions & 4 deletions plugins/social/test/social.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4549,7 +4549,7 @@ test('#260: Approve all approves Bot Social holds too, not only local ones', asy
const all = tree.find(node => node.props['data-flybot'] === 'approve-all')
assert.ok(all, 'Approve all is offered for Bot Social holds (they carry status: pending)')
assert.deepEqual(all.children, ['Approve all (2)'], `the label carries the count, saw ${JSON.stringify(all.children)}`)
assert.equal(all.props.title, '2 条 · to Bob', `the title names the person, saw ${JSON.stringify(all.props.title)}`)
assert.equal(all.props.title, '2 holds · to Bob', `the title names the person, saw ${JSON.stringify(all.props.title)}`)
await all.props.onClick()
const decided = calls.filter(([endpoint]) => endpoint === 'social/decide-approval').map(([, payload]) => payload.approvalId)
assert.deepEqual(decided.sort(), ['s1', 's2'])
Expand All @@ -4565,7 +4565,46 @@ test('#3011: Approve all says how many holds it sends and to whom', () => {
const all = tree.find(node => node.props['data-flybot'] === 'approve-all')
assert.ok(all, 'Approve all is offered for three waiting holds')
assert.deepEqual(all.children, ['Approve all (3)'], `the label carries the count, saw ${JSON.stringify(all.children)}`)
assert.equal(all.props.title, '3 条 · to Eve, Bob', `the title names each person once, saw ${JSON.stringify(all.props.title)}`)
assert.equal(all.props.title, '3 holds · to Eve, Bob', `the title names each person once, saw ${JSON.stringify(all.props.title)}`)
})

test('#3061: Approve all reads its label and tooltip in the language of the window', async () => {
const { walk, pluginOf } = loadSocialClient(async () => ({}))
const { DICTIONARY } = await import('../../../core/src/client/i18n.js')
// The same translator the host hands a plugin: the window's dictionary, then the english keys as
// written when a window has no entry.
const translate = (language) => (text, params) => {
const used = DICTIONARY[language]?.[text] ?? text
return String(used).replace(/\{(\w+)\}/g, (_, name) => String(params?.[name] ?? ''))
}
const hold = (id, to, toName) => ({ id, kind: 'outbound_message', status: 'pending', from: 'Chief', to, toName, text: id })
const items = [hold('h1', '@eve.home', 'Eve'), hold('h2', '@bob.home', 'Bob'), hold('h3', '@eve.home', 'Eve')]
const room = { id: 'room-1', participants: [{ handle: '@eve.home' }, { handle: '@bob.home' }] }
const draw = (items, t) => walk(pluginOf([items, [], true, true])
.ChatApprovalDock({ bot: { id: 'mine' }, roster: { bots: [] }, room, t }))
.find(node => node.props['data-flybot'] === 'approve-all')

// Three holds, two people: the english window reads the source strings.
const en = draw(items)
assert.deepEqual(en.children, ['Approve all (3)'], `the english label carries the count, saw ${JSON.stringify(en.children)}`)
assert.equal(en.props.title, '3 holds · to Eve, Bob', `the english title names each person once, saw ${JSON.stringify(en.props.title)}`)

// The chinese window reads the same sentence from its dictionary, so neither string stays English.
const zh = draw(items, translate('zh'))
assert.deepEqual(zh.children, ['全部批准(3)'], `the chinese label follows the window, saw ${JSON.stringify(zh.children)}`)
assert.equal(zh.props.title, '共 3 条 · 发给 Eve, Bob', `the chinese title follows the window, saw ${JSON.stringify(zh.props.title)}`)

// Holds whose person the dock cannot name keep the count alone — and that sentence follows too.
const unnamed = [
{ id: 'u1', kind: 'outbound_message', status: 'pending', from: 'Chief', to: '@eve.home', text: 'u1' },
{ id: 'u2', kind: 'outbound_message', status: 'pending', from: 'Chief', to: '@bob.home', text: 'u2' },
]
const enAlone = draw(unnamed)
assert.deepEqual(enAlone.children, ['Approve all (2)'], `the english label counts both, saw ${JSON.stringify(enAlone.children)}`)
assert.equal(enAlone.props.title, '2 holds', `the english count alone, saw ${JSON.stringify(enAlone.props.title)}`)
const zhAlone = draw(unnamed, translate('zh'))
assert.deepEqual(zhAlone.children, ['全部批准(2)'], `the chinese label counts both, saw ${JSON.stringify(zhAlone.children)}`)
assert.equal(zhAlone.props.title, '共 2 条', `the chinese count follows the window, saw ${JSON.stringify(zhAlone.props.title)}`)
})

test('#3015: Approve all counts the holds it sends, not a failed one drawn beside them', async () => {
Expand All @@ -4582,7 +4621,7 @@ test('#3015: Approve all counts the holds it sends, not a failed one drawn besid
const all = tree.find(node => node.props['data-flybot'] === 'approve-all')
assert.ok(all, 'Approve all is offered while one hold is waiting')
assert.deepEqual(all.children, ['Approve all (1)'], `the count is the holds the click sends, saw ${JSON.stringify(all.children)}`)
assert.equal(all.props.title, '1 条 · to Eve', `the title names only the person it sends to, saw ${JSON.stringify(all.props.title)}`)
assert.equal(all.props.title, '1 hold · to Eve', `the title names only the person it sends to, saw ${JSON.stringify(all.props.title)}`)
await all.props.onClick()
const decisions = calls.filter(([endpoint]) => endpoint === 'social/decide-approval' || endpoint === 'decide')
assert.deepEqual(decisions.map(([endpoint, payload]) => [endpoint, payload.approvalId ?? payload.id]), [['social/decide-approval', 'w1']], `only the waiting hold is sent, saw ${JSON.stringify(decisions)}`)
Expand Down Expand Up @@ -5087,7 +5126,7 @@ test('#114: in-chat dock lists drafts with Approve all; others see a waiting lin
const approveAll = tree.find(n => n.props['data-flybot'] === 'approve-all')
assert.ok(approveAll, 'Approve all is offered for the two drafts')
assert.ok(approveAll.children.includes('Approve all (2)'), `the label carries the count, saw ${JSON.stringify(approveAll.children)}`)
assert.equal(approveAll.props.title, '2 条', `with no person named the title is the count alone, saw ${JSON.stringify(approveAll.props.title)}`)
assert.equal(approveAll.props.title, '2 holds', `with no person named the title is the count alone, saw ${JSON.stringify(approveAll.props.title)}`)
assert.equal(tree.filter(n => n.props['data-flybot'] === 'chat-approval').length, 2)
assert.ok(tree.some(n => n.props.className === 'fs-draft' && n.children.includes('one')))
assert.ok(tree.some(n => n.props.className === 'fs-sub' && n.children.includes('Chief → Hsliu')))
Expand Down
Loading