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/3114-room-auto-send-zh.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The face-to-face room’s Auto-send switches (`Auto-send Chief → room` and the checkbox’s own name) and the sidebar’s `Past rooms` fold now read in the window’s language instead of English ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)).
5 changes: 5 additions & 0 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ var ZH = {
// #3032: the four approval-card controls that were still drawn as bare English.
"Waiting for the owner's approval": "等待 owner 批准",
"Auto-send from now on": "以后自动发送",
// #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold.
"Auto-send {bot} → room": "{bot} 发给房间的消息自动发送",
"Auto-send {bot}'s room messages": "自动发送 {bot} 在房间里的消息",
"my Bot": "我的 Bot",
"Past rooms": "历史房间",
Decline: "拒绝",
pending: "等待中",
"Decide on the reply bubble above.": "在上面的回复气泡里批准。",
Expand Down
5 changes: 5 additions & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ const ZH = {
// #3032: the four approval-card controls that were still drawn as bare English.
"Waiting for the owner's approval": '等待 owner 批准',
'Auto-send from now on': '以后自动发送',
// #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold.
'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送',
"Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息',
'my Bot': '我的 Bot',
'Past rooms': '历史房间',
Decline: '拒绝',
pending: '等待中',
'Decide on the reply bubble above.': '在上面的回复气泡里批准。',
Expand Down
1 change: 0 additions & 1 deletion core/test/i18n-missing-entries.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"entries": [
"plugins/social/client.js:Chat paused",
"plugins/social/client.js:Could not reach FlyBot. Check that it is still running.",
"plugins/social/client.js:Past rooms",
"plugins/social/client.js:Remove this Bot from Friends' Bots and from your groups. This does not unfriend the owner.",
"plugins/social/client.js:Social is not running: the plugin did not start. See Settings → Feedback.",
"plugins/social/client.js:Social#1",
Expand Down
2 changes: 0 additions & 2 deletions core/test/i18n-template-draws.baseline.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"version": 1,
"entries": [
"plugins/social/client.js:Auto-send {} → room",
"plugins/social/client.js:Auto-send {}'s room messages",
"plugins/social/client.js:{} Send your message again: it starts a new chat.",
"plugins/timeline/client.js:Could not copy the report: {}",
"plugins/timeline/client.js:Last {}",
Expand Down
7 changes: 6 additions & 1 deletion patches/ds-bot/0001-core-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
Content: '内容',
'Referenced {labels}': '引用了 {labels}',
', ': '、',
@@ -41,22 +41,197 @@ const ZH = {
@@ -41,22 +41,202 @@ const ZH = {
' and ': '、',
and: '和',
'{count} members': '{count} 位成员',
Expand Down Expand Up @@ -1052,6 +1052,11 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
+ // #3032: the four approval-card controls that were still drawn as bare English.
+ "Waiting for the owner's approval": '等待 owner 批准',
+ 'Auto-send from now on': '以后自动发送',
+ // #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold.
+ 'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送',
+ "Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息',
+ 'my Bot': '我的 Bot',
+ 'Past rooms': '历史房间',
+ Decline: '拒绝',
+ pending: '等待中',
+ 'Decide on the reply bubble above.': '在上面的回复气泡里批准。',
Expand Down
7 changes: 6 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,196 @@ var ZH = {
@@ -78,21 +78,201 @@ var ZH = {
" and ": "、",
and: "和",
"{count} members": "{count} 位成员",
Expand Down Expand Up @@ -316,6 +316,11 @@ diff --git a/client.js b/client.js
+ // #3032: the four approval-card controls that were still drawn as bare English.
+ "Waiting for the owner's approval": "等待 owner 批准",
+ "Auto-send from now on": "以后自动发送",
+ // #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold.
+ "Auto-send {bot} → room": "{bot} 发给房间的消息自动发送",
+ "Auto-send {bot}'s room messages": "自动发送 {bot} 在房间里的消息",
+ "my Bot": "我的 Bot",
+ "Past rooms": "历史房间",
+ Decline: "拒绝",
+ pending: "等待中",
+ "Decide on the reply bubble above.": "在上面的回复气泡里批准。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"entries": [
"plugins/social/client.js:Chat paused",
"plugins/social/client.js:Could not reach FlyBot. Check that it is still running.",
"plugins/social/client.js:Past rooms",
"plugins/social/client.js:Remove this Bot from Friends' Bots and from your groups. This does not unfriend the owner.",
"plugins/social/client.js:Social is not running: the plugin did not start. See Settings → Feedback.",
"plugins/social/client.js:Social#1",
Expand Down
2 changes: 0 additions & 2 deletions patches/ds-bot/files/test/i18n-template-draws.baseline.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"version": 1,
"entries": [
"plugins/social/client.js:Auto-send {} → room",
"plugins/social/client.js:Auto-send {}'s room messages",
"plugins/social/client.js:{} Send your message again: it starts a new chat.",
"plugins/timeline/client.js:Could not copy the report: {}",
"plugins/timeline/client.js:Last {}",
Expand Down
7 changes: 4 additions & 3 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,15 +555,16 @@
const AUTO_SEND_NOTE = "Don't ask each time."

function FaceAutoSend({ on, busy, onChange, bot } = {}) {
const who = bot || tr('my Bot')
return h('label', { className: 'fs-auto fs-face-auto', title: tr(AUTO_SEND_NOTE), 'data-flybot': 'face-auto-bot' },
h('input', {
type: 'checkbox',
checked: on === true,
disabled: !!busy,
'aria-label': `Auto-send ${bot || 'my Bot'}'s room messages`,
'aria-label': tr("Auto-send {bot}'s room messages", { bot: who }),
onChange: e => onChange?.(e.target.checked),
}),
`Auto-send ${bot || 'my Bot'} → room`)
tr('Auto-send {bot} → room', { bot: who }))
}

// Leave asks once (#182): leaving ends my part in the room for good.
Expand Down Expand Up @@ -722,7 +723,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 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 j = 0; j < poly.length; j += 1) {
next[j] ^= poly[j]
next[j + 1] ^= qrMul(poly[j], QR_GF_EXP[i])
Expand All @@ -733,7 +734,7 @@
}
function qrRsRemainder(bytes, degree) {
const gen = qrRsGenerator(degree)
const res = new Array(bytes.length + degree).fill(0)

Check warning on line 737 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 @@ -807,8 +808,8 @@
}
function qrSkeleton(version) {
const size = version * 4 + 17
const modules = Array.from({ length: size }, () => new Array(size).fill(0))

Check warning on line 811 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 812 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 @@ -1072,7 +1073,7 @@
return out
}
const cleanRoomName = (value, fallback = '') => stripUntrustedMarkers(value)
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 1076 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 @@ -1116,7 +1117,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 1120 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 @@ -1422,7 +1423,7 @@
const next = id || null
if (next === this.roomId) return
this.roomId = next
for (const fn of [...this.listeners]) fn()

Check warning on line 1426 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 @@ -2489,7 +2490,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 2493 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 All @@ -2513,7 +2514,7 @@
function trimDockRetried() {
let spent = 0
for (const record of dockRecords.values()) if (record.retried) spent++
for (const [key, record] of [...dockRecords]) {

Check warning on line 2517 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.
if (spent <= DOCK_RETRIED_MAX) break
if (!record.retried) continue
dockRecords.delete(key)
Expand Down Expand Up @@ -3096,7 +3097,7 @@
h('div', { className: 'fs-past', 'data-flybot': 'face-past' },
h('button', { type: 'button', className: 'fs-past-head', 'aria-expanded': pastOpen, onClick: togglePast },
h('span', { className: 'fs-chev', 'aria-hidden': true, 'data-closed': pastOpen ? undefined : true }, '▾'),
'Past rooms',
tr('Past rooms'),
h('span', { className: 'fs-count' }, String(past.length))),
pastOpen ? past.map(room => card(room, true)) : null))
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/social/test/add-friend-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test('#3114 cut 22: the baselines lose these draws and the dictionary gains the
assert.deepEqual(still, [], `${file.replace('.baseline.json', '')} still pins ${still[0]}`)
}
// The three baselines shrink by exactly these draws and nothing else does: the ratchet's numbers.
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 12, 48])
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47])
// Every new key is the dictionary's, and each answers with Chinese.
for (const key of [
'Accept an invite', 'Invite a friend', 'Paste invite link or code',
Expand Down
2 changes: 1 addition & 1 deletion plugins/social/test/friend-settings-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ test('#3114 cut 23: the two baselines lose these draws and nothing else', () =>
entriesOf('i18n-plugins.baseline.json').length,
entriesOf('i18n-template-draws.baseline.json').length,
entriesOf('i18n-missing-entries.baseline.json').length,
], [12, 12, 48])
], [12, 10, 47])
// People with access is reused, never added twice; the same for the friend's own fallback name.
assert.equal(zh['Your friend'], '你的朋友')
})
119 changes: 119 additions & 0 deletions plugins/social/test/room-auto-send-i18n.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// #3114 cut 27: the face-to-face room head drew its per-Bot Auto-send switch as bare English
// (`Auto-send Chief → room` and the checkbox's own name `Auto-send Chief's room messages`), and the
// sidebar's folded list of ended rooms drew `Past rooms` the same way. This pins them: a zh window
// reads the dictionary's words, a window whose host has no translator keeps today's English word for
// word, and the two baselines lose the three pins those draws held.
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'
import { runInNewContext } from 'node:vm'
import { DICTIONARY } from '../../../core/src/client/i18n.js'

const zh = DICTIONARY.zh
// The language a window runs in: `t` answers with the Chinese dictionary for a key it carries and
// echoes anything else, which is what the host's own translator does for an entry it lacks.
const translator = (text, params) => {
const translated = Object.hasOwn(zh, text) ? zh[text] : String(text)
return params ? translated.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match)) : translated
}
const zhWindow = { t: translator, slots: { register: () => () => {} }, call: async () => ({}) }
const bareWindow = { slots: { register: () => () => {} }, call: async () => ({}) }

// The client is a classic script that registers its factory on `window`, and the plugin reads
// `__flybot__` off the global object at render time — so the sandbox is that global object.
// `states` seeds the component's useState calls in order (the room list reads its loaded rooms).
function loadApp(flybot, states = []) {
const registered = []
const sandbox = { window: { __ModuleLoader__: { load: entry => registered.push(entry) } }, console, setTimeout, clearTimeout, setInterval, clearInterval }
sandbox.globalThis = sandbox
sandbox.__flybot__ = flybot
runInNewContext(readFileSync(new URL('../client.js', import.meta.url), 'utf8'), sandbox)
let seed = 0
const app = registered[0].factory(() => ({
createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),
Fragment: 'F', useEffect() {}, useRef: value => ({ current: value }), useMemo: fn => fn(),
useState: value => [seed < states.length ? states[seed++] : value, () => {}],
}))
return app
}
// These are plain render functions once the effects are inert, so the tree is the render.
function walk(node, all = []) {
if (!node || typeof node !== 'object') return all
if (typeof node.type === 'function') return walk(node.type(node.props), all)
all.push(node)
for (const child of node.children ?? []) walk(child, all)
return all
}
const findNode = (nodes, match) => nodes.find(match)
const directTexts = node => (node?.children ?? []).filter(child => typeof child === 'string' && child.trim())

test('#3114 cut 27: the room head’s Auto-send switches speak the window’s language', () => {
const app = loadApp(zhWindow)
const nodes = walk(app.FaceAutoSend({ bot: 'Chief', on: true }))
// The switch keeps the note it already had, and its two names come from the dictionary.
assert.equal(nodes[0].props.title, '不要每次都问。', 'the tooltip is still "Don\'t ask each time."')
assert.equal(findNode(nodes, n => n.props?.type === 'checkbox')?.props['aria-label'], '自动发送 Chief 在房间里的消息')
assert.deepEqual(directTexts(nodes[0]), ['Chief 发给房间的消息自动发送'])
// A Bot whose name did not arrive falls back through the dictionary too, not to bare `my Bot`.
const unknown = walk(app.FaceAutoSend({}))
assert.deepEqual(directTexts(unknown[0]), ['我的 Bot 发给房间的消息自动发送'])
assert.equal(findNode(unknown, n => n.props?.type === 'checkbox')?.props['aria-label'], '自动发送 我的 Bot 在房间里的消息')
})

test('#3114 cut 27: the sidebar’s Past rooms fold speaks the window’s language', () => {
// One ended room: the fold draws its head and the count, and the section is still `fs-past`.
const room = { id: 'g1', faceRoomId: 'frm_1', status: 'closed', name: 'Den' }
const app = loadApp(zhWindow, [[room], false])
const nodes = walk(app.FaceRooms({}))
const head = findNode(nodes, n => n.props?.className === 'fs-past-head')
assert.deepEqual(directTexts(head), ['历史房间'])
assert.equal(findNode(nodes, n => n.props?.className === 'fs-count')?.children[0], '1', 'the count is still the number of ended rooms')
assert.ok(findNode(nodes, n => n.props?.['data-flybot'] === 'face-past'), 'the fold is still `face-past`')
})

// A host with no translator keeps the English it drew before this change, character for character —
// `tr()` replaces a string only when the host answers for it.
test('a host with no translator keeps today’s English in the room head and the fold', () => {
const app = loadApp(bareWindow)
const named = walk(app.FaceAutoSend({ bot: 'Chief' }))
assert.deepEqual(directTexts(named[0]), ['Auto-send Chief → room'])
assert.equal(findNode(named, n => n.props?.type === 'checkbox')?.props['aria-label'], "Auto-send Chief's room messages")
const unknown = walk(app.FaceAutoSend({}))
assert.deepEqual(directTexts(unknown[0]), ['Auto-send my Bot → room'])
const room = { id: 'g1', faceRoomId: 'frm_1', status: 'closed', name: 'Den' }
const fold = loadApp(bareWindow, [[room], false])
const head = findNode(walk(fold.FaceRooms({})), n => n.props?.className === 'fs-past-head')
assert.deepEqual(directTexts(head), ['Past rooms'])
})

// The baselines may only shrink, and an entry leaves when its zh key lands — a draw that is
// translated no longer needs pinning. The files are read as the repository ships them.
const pinned = [
['i18n-missing-entries.baseline.json', ['Past rooms']],
['i18n-template-draws.baseline.json', ['Auto-send {} → room', "Auto-send {}'s room messages"]],
]
const entriesOf = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries

test('#3114 cut 27: the two baselines lose these draws and the dictionary gains the keys', () => {
for (const [file, keys] of pinned) {
const entries = entriesOf(file)
const still = keys.map(key => `plugins/social/client.js:${key}`).filter(id => entries.includes(id))
assert.deepEqual(still, [], `${file.replace('.baseline.json', '')} still pins ${still[0]}`)
}
// The baselines shrink by exactly these draws and nothing else does: the totals are the ratchet's
// numbers, and a later cut that moves them moves these numbers with it.
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47])
// Every new key is the dictionary's, each answer character for character — the arrow's single
// spaces and the straight `'` included, so a trimmed or curly-quoted copy is caught here.
assert.deepEqual(Object.entries({
'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送',
"Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息',
'my Bot': '我的 Bot',
'Past rooms': '历史房间',
}).map(([key]) => [key, zh[key]]), Object.entries({
'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送',
"Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息',
'my Bot': '我的 Bot',
'Past rooms': '历史房间',
}))
})
2 changes: 1 addition & 1 deletion plugins/social/test/sharing-page-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ test('#3114 cut 20: the three baselines lose these draws', () => {
}
// The baselines shrink by exactly these draws and nothing else does: the totals are the ratchet's
// numbers, and a later cut that moves them moves these numbers with it.
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 12, 48])
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47])

// A host with no translator keeps the English it drew before this change, character for
// character — `tr()` replaces a string only when the host answers for it.
Expand Down
2 changes: 1 addition & 1 deletion plugins/social/test/sharing-rooms-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ test('#3114 cut 26: the two baselines lose these draws and the dictionary gains
}
// The baselines shrink by exactly these draws and nothing else does: the totals are the ratchet's
// numbers, and a later cut that moves them moves these numbers with it.
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 12, 48])
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47])
// Every new key is the dictionary's, each answer character for character — the four keys that end
// in a space and the one that starts with it included, so a trimmed copy is caught here.
assert.deepEqual(Object.entries({
Expand Down
Loading