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-paused-chat-zh.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A friend chat Bot Social paused now says so in the window’s language, title and “send your message again” line included ([#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 @@ -383,6 +383,11 @@ var ZH = {
"{n} holds · to {to}": "共 {n} 条 · 发给 {to}",
"Auto-sent to {to}": "已自动发给 {to}",
"Not sent: delivery failed": "未发出:发送失败",
// The paused friend chat's notice (#3114 cut 28); Bot Social's reason fills `{reason}` untranslated.
"Chat paused": "聊天已暂停",
"Bot Social paused the last chat with this Bot.": "Bot Social 暂停了与这个 Bot 的上一次聊天。",
"Bot Social paused the last chat with this Bot ({reason}).": "Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。",
"{note} Send your message again: it starts a new chat.": "{note}请重新发送消息:这会开始一段新聊天。",
"{from} → {to}": "{from} → {to}",
"+{count} more": "另有 {count} 条",
"{count} more not shown": "还有 {count} 条未显示",
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 @@ -350,6 +350,11 @@ const ZH = {
'{n} holds · to {to}': '共 {n} 条 · 发给 {to}',
'Auto-sent to {to}': '已自动发给 {to}',
'Not sent: delivery failed': '未发出:发送失败',
// The paused friend chat's notice (#3114 cut 28); Bot Social's reason fills `{reason}` untranslated.
'Chat paused': '聊天已暂停',
'Bot Social paused the last chat with this Bot.': 'Bot Social 暂停了与这个 Bot 的上一次聊天。',
'Bot Social paused the last chat with this Bot ({reason}).': 'Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。',
'{note} Send your message again: it starts a new chat.': '{note}请重新发送消息:这会开始一段新聊天。',
'{from} → {to}': '{from} → {to}',
'+{count} more': '另有 {count} 条',
'{count} more not shown': '还有 {count} 条未显示',
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
@@ -1,7 +1,6 @@
{
"version": 1,
"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: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.",
Expand Down
1 change: 0 additions & 1 deletion 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:{} Send your message again: it starts a new chat.",
"plugins/timeline/client.js:Could not copy the report: {}",
"plugins/timeline/client.js:Last {}",
"plugins/timeline/client.js:Looking back: window ends at {}.",
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,202 @@ const ZH = {
@@ -41,22 +41,207 @@ const ZH = {
' and ': '、',
and: '和',
'{count} members': '{count} 位成员',
Expand Down Expand Up @@ -1073,6 +1073,11 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js
+ '{n} holds · to {to}': '共 {n} 条 · 发给 {to}',
+ 'Auto-sent to {to}': '已自动发给 {to}',
+ 'Not sent: delivery failed': '未发出:发送失败',
+ // The paused friend chat's notice (#3114 cut 28); Bot Social's reason fills `{reason}` untranslated.
+ 'Chat paused': '聊天已暂停',
+ 'Bot Social paused the last chat with this Bot.': 'Bot Social 暂停了与这个 Bot 的上一次聊天。',
+ 'Bot Social paused the last chat with this Bot ({reason}).': 'Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。',
+ '{note} Send your message again: it starts a new chat.': '{note}请重新发送消息:这会开始一段新聊天。',
+ '{from} → {to}': '{from} → {to}',
+ '+{count} more': '另有 {count} 条',
+ '{count} more not shown': '还有 {count} 条未显示',
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,201 @@ var ZH = {
@@ -78,21 +78,206 @@ var ZH = {
" and ": "、",
and: "和",
"{count} members": "{count} 位成员",
Expand Down Expand Up @@ -337,6 +337,11 @@ diff --git a/client.js b/client.js
+ "{n} holds · to {to}": "共 {n} 条 · 发给 {to}",
+ "Auto-sent to {to}": "已自动发给 {to}",
+ "Not sent: delivery failed": "未发出:发送失败",
+ // The paused friend chat's notice (#3114 cut 28); Bot Social's reason fills `{reason}` untranslated.
+ "Chat paused": "聊天已暂停",
+ "Bot Social paused the last chat with this Bot.": "Bot Social 暂停了与这个 Bot 的上一次聊天。",
+ "Bot Social paused the last chat with this Bot ({reason}).": "Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。",
+ "{note} Send your message again: it starts a new chat.": "{note}请重新发送消息:这会开始一段新聊天。",
+ "{from} → {to}": "{from} → {to}",
+ "+{count} more": "另有 {count} 条",
+ "{count} more not shown": "还有 {count} 条未显示",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": 1,
"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: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.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": 1,
"entries": [
"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 {}",
"plugins/timeline/client.js:Looking back: window ends at {}.",
Expand Down
8 changes: 6 additions & 2 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4002,9 +4002,13 @@ window.__ModuleLoader__.load({
return () => { live = false; clearInterval(timer) }
}, [handle])
if (!handle || !paused) return null
const note = paused.reason
? tr('Bot Social paused the last chat with this Bot ({reason}).', { reason: paused.reason })
: tr('Bot Social paused the last chat with this Bot.')
return h('div', { className: 'fs-hold fs-chat-approval', 'data-flybot': 'chat-paused', role: 'status' },
h('div', { className: 'fs-label' }, 'Chat paused'),
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.`))
h('div', { className: 'fs-label' }, tr('Chat paused')),
h('div', { className: 'fs-draft' },
tr('{note} Send your message again: it starts a new chat.', { note })))
}

// + menu marks (#385), drawn like the host's line icons: people nearby, and a person to add.
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, 10, 47])
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46])
// 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, 10, 47])
], [12, 9, 46])
// People with access is reused, never added twice; the same for the friend's own fallback name.
assert.equal(zh['Your friend'], '你的朋友')
})
116 changes: 116 additions & 0 deletions plugins/social/test/paused-chat-i18n.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// #3114 cut 28: the quiet card a friend chat draws above the composer once Bot Social has paused
// that chat was bare English (`Chat paused`, `Bot Social paused the last chat with this Bot…` and
// `Send your message again: it starts a new chat.`). This pins it: a zh window reads the
// dictionary's sentences, a window whose host has no translator keeps today's English word for
// word, Bot Social's own reason stays untranslated inside the parentheses, and the two baselines
// lose the two 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 windowWith = t => ({ ...(t ? { t } : {}), slots: { register: () => () => {} }, call: async () => ({}) })
const zhWindow = windowWith(translator)
const bareWindow = windowWith(null)

// 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 card reads its `paused` answer).
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
return registered[0].factory(() => ({
createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),
Fragment: 'F', useEffect() {},
useState: value => [seed < states.length ? states[seed++] : value, () => {}],
}))
}
// 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 BOT = { remote: { handle: '@coder.bob.home' } }
// The answer Bot Social gave for this chat, and the two lines the card draws from it.
const lines = (flybot, paused) => {
const nodes = walk(loadApp(flybot, [paused]).PausedChat({ bot: BOT }))
const texts = className => nodes.find(node => node.props?.className === className)?.children.filter(child => typeof child === 'string').join('')
return { nodes, title: texts('fs-label'), draft: texts('fs-draft') }
}
const reason = 'loop detected'
const entriesOf = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries

test('#3114 cut 28: the paused friend chat speaks the window’s language, with Bot Social’s reason', () => {
const { title, draft } = lines(zhWindow, { reason })
assert.equal(title, '聊天已暂停')
assert.equal(draft, 'Bot Social 暂停了与这个 Bot 的上一次聊天(loop detected)。请重新发送消息:这会开始一段新聊天。')
})

test('#3114 cut 28: a pause with no reason still reads as one sentence pair', () => {
// Bot Social left the reason out: the card drops the parentheses, not the second sentence.
const { title, draft } = lines(zhWindow, {})
assert.equal(title, '聊天已暂停')
assert.equal(draft, 'Bot Social 暂停了与这个 Bot 的上一次聊天。请重新发送消息:这会开始一段新聊天。')
})

// 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, and it fills `{note}` itself.
test('a host with no translator keeps today’s English in the paused notice', () => {
assert.equal(lines(bareWindow, { reason }).draft, 'Bot Social paused the last chat with this Bot (loop detected). Send your message again: it starts a new chat.')
assert.equal(lines(bareWindow, {}).draft, 'Bot Social paused the last chat with this Bot. Send your message again: it starts a new chat.')
assert.equal(lines(bareWindow, { reason }).title, 'Chat paused')
})

test('the card is still drawn only for a friend’s Bot chat that Bot Social paused', () => {
// No `bot.remote.handle` — a Bot that has not told us its handle gets no card, not an empty one.
assert.equal(loadApp(zhWindow).PausedChat({}), null)
// A handle but no pause answer: nothing has been paused, so nothing is drawn.
assert.equal(loadApp(zhWindow, [null]).PausedChat({ bot: BOT }), null)
// Drawn: the marks the host and the styles hang off are the ones they were.
const { nodes } = lines(zhWindow, { reason })
const hold = nodes.find(node => node.props?.['data-flybot'] === 'chat-paused')
assert.equal(hold.props.role, 'status')
assert.equal(hold.props.className, 'fs-hold fs-chat-approval')
})

// 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', ['Chat paused']],
['i18n-template-draws.baseline.json', ['{} Send your message again: it starts a new chat.']],
]
test('#3114 cut 28: 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, 9, 46])
// Every new key is the dictionary's, each answer character for character — the full-width
// parentheses and the missing space after `{note}` included, so a trimmed copy is caught here.
const keys = {
'Chat paused': '聊天已暂停',
'Bot Social paused the last chat with this Bot.': 'Bot Social 暂停了与这个 Bot 的上一次聊天。',
'Bot Social paused the last chat with this Bot ({reason}).': 'Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。',
'{note} Send your message again: it starts a new chat.': '{note}请重新发送消息:这会开始一段新聊天。',
}
assert.deepEqual(Object.entries(keys).map(([key]) => [key, zh[key]]), Object.entries(keys))
})
2 changes: 1 addition & 1 deletion plugins/social/test/room-auto-send-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test('#3114 cut 27: 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, 10, 47])
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46])
// 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({
Expand Down
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, 10, 47])
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46])

// 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, 10, 47])
assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46])
// 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