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-group-name.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Name a new group chat in the sidebar **+** pane and refuse a name another group chat already has before the room is made, with the Chinese note shown under the name field (#3114).
29 changes: 25 additions & 4 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ var ZH = {
"Replace photo": "更换照片",
"Upload photo": "上传照片",
"A Bot named {name} already exists": "已经有叫 {name} 的 Bot 了",
"A group chat named {name} already exists": "已经有叫「{name}」的群聊了",
"The Bot runs on this model. You can change it later in its details.": "Bot 会使用这个模型。以后可以在详情里修改。",
"Add a provider and a model in DeepSeek Harness first, or pick one in the Bot's chat later.": "请先在 DeepSeek Harness 里添加服务商和模型,或者稍后在 Bot 的对话里选择。",
"Creating…": "创建中…",
Expand Down Expand Up @@ -5431,6 +5432,9 @@ button.bt-q-opt:active{background:var(--bt-active)}
.bt-readonly-line-head{padding:0 20px 8px}
.bt-readonly-line-head>.bt-hint{padding:0;text-align:left}
.bt-nc-spacer{flex:1}
.bt-nc-name{display:flex;align-items:center;gap:8px;padding:0 12px 8px;font-size:13px;box-sizing:border-box}
.bt-nc-name input{flex:1;min-width:120px;border:0;outline:none;background:none;color:var(--bt-ink);font-size:14px;height:26px}
.bt-nc-name+.bt-drop{top:82px}
.bt-nc-compose{padding:0 16px 14px;display:flex;justify-content:center}
.bt-nc-card{display:flex;align-items:flex-end;gap:6px;width:100%;max-width:var(--dsh-chat-content-width,748px);min-height:44px;padding:4px 6px;border-radius:22px;border:1px solid var(--bt-line-2);background:var(--bt-main);box-shadow:0 2px 8px -2px rgba(0,0,0,.06);box-sizing:border-box}
.bt-nc-plus{width:34px;height:34px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;color:var(--bt-ink-2);background:var(--bt-hover);flex:none}
Expand Down Expand Up @@ -16987,6 +16991,7 @@ function NewChat({ mode, roster, actions }) {
const [compose, setCompose] = (0, import_react37.useState)(mode !== "new");
const [admin, setAdmin] = (0, import_react37.useState)(null);
const [message, setMessage] = (0, import_react37.useState)("");
const [groupName, setGroupName] = (0, import_react37.useState)("");
const [busy, setBusy] = (0, import_react37.useState)(false);
const [error, setError] = (0, import_react37.useState)("");
const [fix, setFix] = (0, import_react37.useState)(null);
Expand All @@ -17006,6 +17011,8 @@ function NewChat({ mode, roster, actions }) {
const matches = pool.filter((bot) => !picked.includes(bot.id) && bot.id !== admin && (wanted === "" || bot.name.toLowerCase().includes(wanted) || pickerBotLabel(bot).toLowerCase().includes(wanted) || (bot.role ?? "").toLowerCase().includes(wanted)));
const exact = bots.some((bot) => bot.name.toLowerCase() === wanted);
const pickedBots = picked.map((id) => roster.byId[id]).filter(Boolean);
const finalGroupName = groupName.trim();
const groupNameClash = finalGroupName === "" ? void 0 : (roster.rooms ?? []).find((room2) => (room2.name ?? "").trim().toLowerCase() === finalGroupName.toLowerCase());
const run = async (task) => {
if (busy) return;
setError("");
Expand All @@ -17016,7 +17023,7 @@ function NewChat({ mode, roster, actions }) {
try {
await task();
} catch (failure) {
setError(failure?.message ?? String(failure));
setError(hostText(failure?.message ?? String(failure)));
setFix(ungrantedLocalFix(failure?.details) ?? null);
} finally {
setBusy(false);
Expand Down Expand Up @@ -17088,14 +17095,14 @@ function NewChat({ mode, roster, actions }) {
return afterCreate({ id: bot.id, text: message, actions });
};
const makeGroup = async () => {
if (locked || admin === null || picked.length === 0) return;
if (locked || admin === null || picked.length === 0 || groupNameClash) return;
const text2 = message.trim();
const { members, remotes } = splitRoomPicks(roster, [admin, ...picked]);
const participants = remotes.length === 0 ? void 0 : [
...members.map((id) => ({ kind: "bot", id, role: id === admin ? "admin" : "member" })),
...remotes
];
const room2 = await actions.createRoom(members, { admin, ...participants ? { participants } : {} });
const room2 = await actions.createRoom(members, { admin, ...participants ? { participants } : {}, ...finalGroupName !== "" && !groupNameClash ? { name: finalGroupName } : {} });
if (text2) await actions.send(room2.id, text2);
actions.openSession(room2.id);
close();
Expand Down Expand Up @@ -17261,12 +17268,26 @@ ${listed}`, { axis: "y", ...QUICK_EDGES });
group && admin !== null ? locked ? readOnlyLine(import_react37.createElement, roster, actions, { key: "readonly-admin" }) : (0, import_react37.createElement)("button", {
type: "button",
className: "bt-send bt-to-create",
disabled: busy || picked.length === 0,
disabled: busy || picked.length === 0 || groupNameClash !== void 0,
title: picked.length === 0 ? t("Add at least one more Bot") : void 0,
onClick: createGroup
}, t("Create group chat")) : null,
(0, import_react37.createElement)("button", { type: "button", className: "bt-x", "aria-label": t("Close new chat"), onClick: close }, "×")
),
// Optional: a blank name leaves the host to name the room, and a taken one is refused here.
group && admin !== null && !menuOnly ? (0, import_react37.createElement)(
"div",
{ className: "bt-nc-name" },
(0, import_react37.createElement)("span", { className: "bt-to-label" }, t("Group name")),
(0, import_react37.createElement)("input", {
value: groupName,
maxLength: 60,
placeholder: t("Name after members"),
"aria-label": t("Group name"),
onChange: (event) => setGroupName(event.target.value)
}),
groupNameClash ? (0, import_react37.createElement)("span", { className: "bt-note bt-danger" }, t("A group chat named {name} already exists", { name: groupNameClash.name })) : null
) : null,
(0, import_react37.createElement)("div", { ref: drop, className: "bt-drop" }, (0, import_react37.createElement)(
"div",
{ ref: glide.box, role: "listbox", "aria-label": t("Recipients"), className: "bt-drop-list" },
Expand Down
1 change: 1 addition & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ const ZH = {
'Replace photo': '更换照片',
'Upload photo': '上传照片',
'A Bot named {name} already exists': '已经有叫 {name} 的 Bot 了',
'A group chat named {name} already exists': '已经有叫「{name}」的群聊了',
'The Bot runs on this model. You can change it later in its details.': 'Bot 会使用这个模型。以后可以在详情里修改。',
"Add a provider and a model in DeepSeek Harness first, or pick one in the Bot's chat later.": '请先在 DeepSeek Harness 里添加服务商和模型,或者稍后在 Bot 的对话里选择。',
'Creating…': '创建中…',
Expand Down
22 changes: 17 additions & 5 deletions core/src/client/new-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useEscape, usePaneLeft } from './overlay-hooks.js'
import { CreateBot } from './create-bot.js'
import { afterCreate } from './bot-draft.js'
import { QUICK_EDGES, useFlip, useGlide, useMorph } from './motion.js'
import { t } from './i18n.js'
import { hostText, t } from './i18n.js'
import { readOnlyLine } from './read-only.js'
import { lockedWindow } from './schedules.js'
import { newChatActionRows } from './flybot-registry.js'
Expand All @@ -21,6 +21,7 @@ export function NewChat({ mode, roster, actions }) {
// A new group chat picks its admin first, then the other members.
const [admin, setAdmin] = useState(null)
const [message, setMessage] = useState('')
const [groupName, setGroupName] = useState('')
const [busy, setBusy] = useState(false)
const [error, setError] = useState('')
// A group with a friend's Bot refused because one of my Bots is not shared with that friend:
Expand All @@ -46,6 +47,9 @@ export function NewChat({ mode, roster, actions }) {
const matches = pool.filter(bot => !picked.includes(bot.id) && bot.id !== admin && (wanted === '' || bot.name.toLowerCase().includes(wanted) || pickerBotLabel(bot).toLowerCase().includes(wanted) || (bot.role ?? '').toLowerCase().includes(wanted)))
const exact = bots.some(bot => bot.name.toLowerCase() === wanted)
const pickedBots = picked.map(id => roster.byId[id]).filter(Boolean)
const finalGroupName = groupName.trim()
// roster.findRooms' normalize trims and folds case, so the pane refuses the same names first.
const groupNameClash = finalGroupName === '' ? undefined : (roster.rooms ?? []).find(room => (room.name ?? '').trim().toLowerCase() === finalGroupName.toLowerCase())
const run = async (task) => {
if (busy) return
setError('')
Expand All @@ -54,7 +58,7 @@ export function NewChat({ mode, roster, actions }) {
setInviteLink('')
setBusy(true)
try { await task() } catch (failure) {
setError(failure?.message ?? String(failure))
setError(hostText(failure?.message ?? String(failure)))
setFix(ungrantedLocalFix(failure?.details) ?? null)
} finally { setBusy(false) }
}
Expand Down Expand Up @@ -130,14 +134,14 @@ export function NewChat({ mode, roster, actions }) {
// The admin and at least one more Bot make a group; a message typed below goes with it,
// else the admin opens by asking what the group is for.
const makeGroup = async () => {
if (locked || admin === null || picked.length === 0) return
if (locked || admin === null || picked.length === 0 || groupNameClash) return
const text = message.trim()
const { members, remotes } = splitRoomPicks(roster, [admin, ...picked])
const participants = remotes.length === 0 ? undefined : [
...members.map(id => ({ kind: 'bot', id, role: id === admin ? 'admin' : 'member' })),
...remotes,
]
const room = await actions.createRoom(members, { admin, ...(participants ? { participants } : {}) })
const room = await actions.createRoom(members, { admin, ...(participants ? { participants } : {}), ...(finalGroupName !== '' && !groupNameClash ? { name: finalGroupName } : {}) })
if (text) await actions.send(room.id, text)
actions.openSession(room.id)
close()
Expand Down Expand Up @@ -254,10 +258,18 @@ export function NewChat({ mode, roster, actions }) {
group && admin !== null ? (locked
? readOnlyLine(h, roster, actions, { key: 'readonly-admin' })
: h('button', {
type: 'button', className: 'bt-send bt-to-create', disabled: busy || picked.length === 0,
type: 'button', className: 'bt-send bt-to-create', disabled: busy || picked.length === 0 || groupNameClash !== undefined,
title: picked.length === 0 ? t('Add at least one more Bot') : undefined, onClick: createGroup,
}, t('Create group chat'))) : null,
h('button', { type: 'button', className: 'bt-x', 'aria-label': t('Close new chat'), onClick: close }, '×')),
// Optional: a blank name leaves the host to name the room, and a taken one is refused here.
group && admin !== null && !menuOnly ? h('div', { className: 'bt-nc-name' },
h('span', { className: 'bt-to-label' }, t('Group name')),
h('input', {
value: groupName, maxLength: 60, placeholder: t('Name after members'), 'aria-label': t('Group name'),
onChange: event => setGroupName(event.target.value),
}),
groupNameClash ? h('span', { className: 'bt-note bt-danger' }, t('A group chat named {name} already exists', { name: groupNameClash.name })) : null) : null,
h('div', { ref: drop, className: 'bt-drop' }, h('div', { ref: glide.box, role: 'listbox', 'aria-label': t('Recipients'), className: 'bt-drop-list' },
h('span', { ref: glide.thumb, className: 'bt-thumb', 'aria-hidden': true }),
options.length === 0 ? h('div', { className: 'bt-hint' }, mode === 'search' ? t('No Bots match') : t('Type a name to create a Bot'))
Expand Down
3 changes: 3 additions & 0 deletions core/src/client/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ button.bt-q-opt:active{background:var(--bt-active)}
.bt-readonly-line-head{padding:0 20px 8px}
.bt-readonly-line-head>.bt-hint{padding:0;text-align:left}
.bt-nc-spacer{flex:1}
.bt-nc-name{display:flex;align-items:center;gap:8px;padding:0 12px 8px;font-size:13px;box-sizing:border-box}
.bt-nc-name input{flex:1;min-width:120px;border:0;outline:none;background:none;color:var(--bt-ink);font-size:14px;height:26px}
.bt-nc-name+.bt-drop{top:82px}
.bt-nc-compose{padding:0 16px 14px;display:flex;justify-content:center}
.bt-nc-card{display:flex;align-items:flex-end;gap:6px;width:100%;max-width:var(--dsh-chat-content-width,748px);min-height:44px;padding:4px 6px;border-radius:22px;border:1px solid var(--bt-line-2);background:var(--bt-main);box-shadow:0 2px 8px -2px rgba(0,0,0,.06);box-sizing:border-box}
.bt-nc-plus{width:34px;height:34px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;color:var(--bt-ink-2);background:var(--bt-hover);flex:none}
Expand Down
50 changes: 48 additions & 2 deletions core/test/group-create-readonly.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { build } from 'esbuild'

const { outputFiles } = await build({
stdin: {
contents: "export { NewGroupForm } from './src/client/group-settings.js'\nexport { NewChat } from './src/client/new-chat.js'",
contents: "export { DICTIONARY } from './src/client/i18n.js'\nexport { NewGroupForm } from './src/client/group-settings.js'\nexport { NewChat } from './src/client/new-chat.js'",
resolveDir: fileURLToPath(new URL('..', import.meta.url)),
},
bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',
Expand Down Expand Up @@ -54,7 +54,7 @@ runInNewContext(outputFiles[0].text, {
throw new Error(`Unexpected platform module ${name}`)
},
})
const { NewGroupForm, NewChat } = module.exports
const { NewGroupForm, NewChat, DICTIONARY } = module.exports

const chief = { id: 'chief', name: 'Chief', remote: false }
const scout = { id: 'scout', name: 'Scout', remote: false }
Expand Down Expand Up @@ -122,6 +122,9 @@ const press = (nodes, predicate) => {
const chips = nodes => nodes.filter(node => hasClass(node, 'bt-ng-chip'))
const groupCreate = nodes => nodes.filter(node => hasClass(node, 'bt-send') && ownText(node).trim() === 'Create group chat')
const readOnlyLine = nodes => nodes.filter(node => hasClass(node, 'bt-read-only'))
const nameField = nodes => nodes.filter(node => node.type === 'input' && node.props?.['aria-label'] === 'Group name')
const noteOf = nodes => nodes.filter(node => hasClass(node, 'bt-note') && hasClass(node, 'bt-danger'))
const rosterWithRoom = name => ({ ...base, rooms: [{ id: 'r-taken', name, named: true, members: ['chief', 'scout'], admin: 'chief' }] })

// Settings → Group chats → Create group chat → NewGroupForm: pick an admin and one member, then
// press Create. A locked window must not send create-room.
Expand Down Expand Up @@ -161,6 +164,25 @@ const newChatGroup = async (roster) => {
return { calls, nodes, create }
}

const newChatNamed = async (roster, name) => {
const { calls, actions } = actionsOf()
const pane = mount(NewChat, { mode: 'group', roster, actions })
let nodes = pane.draw()
press(nodes, node => node.props?.role === 'option' && ownText(node).includes('Chief'))
await flush()
nodes = pane.draw()
press(nodes, node => node.props?.role === 'option' && ownText(node).includes('Scout'))
await flush()
nodes = pane.draw()
const field = nameField(nodes)
if (field[0]) field[0].props.onChange({ target: { value: name } })
nodes = pane.draw()
const create = groupCreate(nodes)[0]
if (create && !create.props.disabled) create.props.onClick()
await flush()
return { calls, nodes, create, field }
}

test('a read-only window draws no group-create control on the Settings form and sends nothing', async () => {
const locked = await settingsGroup(rosterWith(SENTENCE))
assert.equal(locked.calls.length, 0, 'no write action reaches the host')
Expand Down Expand Up @@ -197,3 +219,27 @@ test('a writable window keeps both group-create controls and still writes', asyn
assert.equal(readOnlyLine(pane.nodes).length, 0, 'no read-only line in a writable window')
}
})

test('#3114: the New… group pane offers a group name and sends it with create-room', async () => {
const pane = await newChatNamed(rosterWith(undefined), 'Launch')
assert.equal(pane.field.length, 1, 'the pane offers one name field')
assert.equal(pane.calls.length, 1, 'Create group chat reaches the host once')
assert.equal(pane.calls[0][2].name, 'Launch', 'the typed name goes with create-room')
assert.equal(DICTIONARY.zh['A group chat named {name} already exists'], '已经有叫「{name}」的群聊了')
})

test('#3114: a blank group name is left out, so the room keeps its member names', async () => {
const pane = await newChatNamed(rosterWith(undefined), ' ')
assert.equal(pane.field.length, 1, 'the pane still offers the field')
assert.equal(pane.calls.length, 1, 'the group is still made')
assert.equal('name' in pane.calls[0][2], false, 'a blank name sends no name key')
})

test('#3114: a group name another group already uses is refused before the write', async () => {
const pane = await newChatNamed(rosterWithRoom('Launch'), ' launch ')
assert.equal(pane.create?.props?.disabled, true, 'Create is disabled for a taken name')
assert.equal(pane.calls.length, 0, 'no create-room reaches the host')
const note = noteOf(pane.nodes)
assert.equal(note.length, 1, 'the pane says the name is taken')
assert.equal(ownText(note[0]).trim(), 'A group chat named Launch already exists')
})
Loading
Loading