From 574bc690b2213a4cd7487cbc6b497762683e3f9b Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Fri, 20 Nov 2026 09:10:06 +0800 Subject: [PATCH] Read a paused friend chat's notice in the window's language (#3114) Fixes #3238 Part of #3114 Docs-not-needed: user-visible zh copy only; no subsystem behaviour, API or ownership changed. --- changelog.d/3114-paused-chat-zh.fixed.md | 1 + core/client.js | 5 + core/src/client/i18n.js | 5 + core/test/i18n-missing-entries.baseline.json | 1 - core/test/i18n-template-draws.baseline.json | 1 - patches/ds-bot/0001-core-fixes.patch | 7 +- patches/ds-bot/0008-client-bundle.patch | 7 +- .../test/i18n-missing-entries.baseline.json | 1 - .../test/i18n-template-draws.baseline.json | 1 - plugins/social/client.js | 8 +- plugins/social/test/add-friend-i18n.test.js | 2 +- .../social/test/friend-settings-i18n.test.js | 2 +- plugins/social/test/paused-chat-i18n.test.js | 116 ++++++++++++++++++ .../social/test/room-auto-send-i18n.test.js | 2 +- plugins/social/test/sharing-page-i18n.test.js | 2 +- .../social/test/sharing-rooms-i18n.test.js | 2 +- 16 files changed, 150 insertions(+), 13 deletions(-) create mode 100644 changelog.d/3114-paused-chat-zh.fixed.md create mode 100644 plugins/social/test/paused-chat-i18n.test.js diff --git a/changelog.d/3114-paused-chat-zh.fixed.md b/changelog.d/3114-paused-chat-zh.fixed.md new file mode 100644 index 000000000..48e56d48f --- /dev/null +++ b/changelog.d/3114-paused-chat-zh.fixed.md @@ -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)). diff --git a/core/client.js b/core/client.js index d2285ca52..bc6156c5f 100644 --- a/core/client.js +++ b/core/client.js @@ -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} 条未显示", diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index bacccb405..8244287d7 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -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} 条未显示', diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index b054e709b..c309cc865 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -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.", diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index c6236e45b..31055470c 100644 --- a/core/test/i18n-template-draws.baseline.json +++ b/core/test/i18n-template-draws.baseline.json @@ -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 {}.", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 9b0f9d6dc..71b38ccdb 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -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} 位成员', @@ -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} 条未显示', diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 374bb6888..797507687 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -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} 位成员", @@ -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} 条未显示", diff --git a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json index b054e709b..c309cc865 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -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.", diff --git a/patches/ds-bot/files/test/i18n-template-draws.baseline.json b/patches/ds-bot/files/test/i18n-template-draws.baseline.json index c6236e45b..31055470c 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.baseline.json +++ b/patches/ds-bot/files/test/i18n-template-draws.baseline.json @@ -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 {}.", diff --git a/plugins/social/client.js b/plugins/social/client.js index 07ff182dd..31e692f87 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -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. diff --git a/plugins/social/test/add-friend-i18n.test.js b/plugins/social/test/add-friend-i18n.test.js index 0e177f6aa..ec7ec66a3 100644 --- a/plugins/social/test/add-friend-i18n.test.js +++ b/plugins/social/test/add-friend-i18n.test.js @@ -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', diff --git a/plugins/social/test/friend-settings-i18n.test.js b/plugins/social/test/friend-settings-i18n.test.js index 52b0e6a1d..05b6ef25c 100644 --- a/plugins/social/test/friend-settings-i18n.test.js +++ b/plugins/social/test/friend-settings-i18n.test.js @@ -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'], '你的朋友') }) diff --git a/plugins/social/test/paused-chat-i18n.test.js b/plugins/social/test/paused-chat-i18n.test.js new file mode 100644 index 000000000..01a7eee06 --- /dev/null +++ b/plugins/social/test/paused-chat-i18n.test.js @@ -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)) +}) diff --git a/plugins/social/test/room-auto-send-i18n.test.js b/plugins/social/test/room-auto-send-i18n.test.js index 8f84db5b6..e9a6f0d1f 100644 --- a/plugins/social/test/room-auto-send-i18n.test.js +++ b/plugins/social/test/room-auto-send-i18n.test.js @@ -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({ diff --git a/plugins/social/test/sharing-page-i18n.test.js b/plugins/social/test/sharing-page-i18n.test.js index 19e5395fa..fe3037c92 100644 --- a/plugins/social/test/sharing-page-i18n.test.js +++ b/plugins/social/test/sharing-page-i18n.test.js @@ -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. diff --git a/plugins/social/test/sharing-rooms-i18n.test.js b/plugins/social/test/sharing-rooms-i18n.test.js index 28848c99a..a1100b0ed 100644 --- a/plugins/social/test/sharing-rooms-i18n.test.js +++ b/plugins/social/test/sharing-rooms-i18n.test.js @@ -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({