3 Commits
Author SHA1 Message Date
SalastilandClaude Sonnet 5.5 10f0180aab 1.3.1: Discord first-word lock; CHANGELOG
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-21 21:03:45 -04:00
SalastilandClaude Sonnet 5.5 b04189ad6b Discord: first-word lock, nonce, upload limit and send pacing; window banner and check; nobilis pointer
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-21 20:42:43 -04:00
SalastilandClaude Sonnet 5.5 5b438be371 The message box: bold, italic, underline and strikethrough are the browser's own, which toggle off from all of the box and keep its undo; the others are put back without the browser re-applying what it replaced
Select all then bold twice left the box bold: the browser keeps the formatting of the run it replaces when the selection is everything in it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-21 20:01:48 -04:00
12 changed files with 173 additions and 40 deletions
-23
View File
@@ -1,23 +0,0 @@
# On a merge, .gitmodules keeps the answer this branch already has.
#
# master names the daemon at github.com because master is what a stranger
# clones, and development names it at the Gitea instance where the work
# happens. Without this, a merge that touched .gitmodules on both sides would
# stop and ask which host is right - and the answer is always "the one the
# branch being merged into already said".
#
# `merge=ours` needs a driver by that name, which is one line per clone and
# not something a repository can carry for you:
#
# git config merge.ours.driver true
#
# Without it git falls back to an ordinary merge, which conflicts rather than
# doing the wrong thing quietly - so a clone that has not run it is no worse
# off than before this file existed.
#
# The edge, because it is a real one: this keeps the *whole file*, not just the
# URL. If development ever adds a second submodule, master takes none of that
# entry while still taking the gitlink the merge brings with it - a submodule
# with nothing in .gitmodules to say where it comes from. Adding a submodule is
# therefore a thing to re-do by hand on master, and the only such thing.
/.gitmodules merge=ours
+8
View File
@@ -17,6 +17,14 @@ Each section has two parts:
that made it, including dependency updates
(`node scripts/changelog-deps.mjs <previous tag>` lists those).
## [1.3.1]
### Fixes, patches and changes
- Discord is not spoken to first from here: a server where your account has not said anything since it joined, and a conversation with nothing in it, are locked with a note to send the first message from Discord's own app or website, after Discord flagged accounts for exactly that. Whether you have spoken is looked for in what moho keeps and then in Discord's search (one request a server, remembered), the lock lifts by itself once there is a message of yours there, and a message sent from moho does not count ([moho `b04189a`](https://github.com/Moho-Chat/moho/commit/b04189a), [nobilis `b9a79e4`](https://github.com/Moho-Chat/nobilis/commit/b9a79e4))
- Discord messages carry a nonce and an explicit list of who may be mentioned, as Discord's own clients send them; a file is checked against what the account may upload before any of it is sent, and waits a few seconds after a message instead of following straight on ([moho `b04189a`](https://github.com/Moho-Chat/moho/commit/b04189a), [nobilis `b9a79e4`](https://github.com/Moho-Chat/nobilis/commit/b9a79e4))
- Taking bold, italic, underline or strikethrough off all of the message box (select all, then the same button or key) works, and undo and redo step over formatting and leave the selection where it was ([moho `5b438be`](https://github.com/Moho-Chat/moho/commit/5b438be))
## [1.3.0]
### Major features
+2 -1
View File
@@ -1,7 +1,8 @@
# Maintainer: Salastil <[email protected]>
pkgname=moho-git
pkgver=r1.268751e
pkgrel=1
pkgdesc="Unified desktop chat client for IRC, Discord, Matrix, Kick, Sneedchat and Steam"
pkgdesc="Unified desktop chat client for IRC, Discord, Sneedchat and Matrix"
arch=('x86_64')
url="https://github.com/Moho-Chat/moho"
license=('GPL3')
+1 -1
Submodule nobilis updated: 264ee7a1f5...04e4e85f97
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "moho",
"version": "1.3.0",
"version": "1.3.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "moho",
"version": "1.3.0",
"version": "1.3.1",
"license": "GPL-3.0-or-later",
"dependencies": {
"@electron-toolkit/preload": "^3.0.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "moho",
"version": "1.3.0",
"version": "1.3.1",
"description": "Unified desktop chat client for IRC, Discord, Sneedchat and Matrix",
"author": "Salastil <[email protected]>",
"license": "GPL-3.0-or-later",
+62 -8
View File
@@ -4,10 +4,11 @@
* to a selection can be taken off again - by the keyboard shortcut or the strip's button, over the whole run,
* over part of it, or over a selection reaching past it - and each step can be undone with the box's own undo.
*
* node scripts/check-composer-format.mjs
* node scripts/check-composer-format.mjs (SERVICE=sneedchat to try another service's box)
*/
import { launchApp, sleep } from './lib/harness.mjs'
const SERVICE = process.env.SERVICE ?? 'discord'
const { page, stop } = await launchApp({ env: { MOHO_UI_SHOTS: '1' } })
const ev = (code) => page.evaluate(code)
const results = []
@@ -21,7 +22,13 @@ const html = () => ev(`document.querySelector(${JSON.stringify(BOX)}).innerHTML.
const marked = () =>
ev(`(() => {
const mark = { bold: '**', italic: '_', underline: '__', strike: '~~', code: '\`', spoiler: '||', quote: '> ' }
const walk = (n) => n.nodeType === 3 ? n.nodeValue : n instanceof HTMLElement && n.dataset.fmt ? (mark[n.dataset.fmt] ?? '') + [...n.childNodes].map(walk).join('') + (n.dataset.fmt === 'quote' ? '' : mark[n.dataset.fmt] ?? '') : [...n.childNodes].map(walk).join('')
const native = { B: 'bold', STRONG: 'bold', I: 'italic', EM: 'italic', U: 'underline', S: 'strike', STRIKE: 'strike' }
const walk = (n) => {
if (n.nodeType === 3) return n.nodeValue
const kind = n instanceof HTMLElement ? (n.dataset.fmt ?? native[n.nodeName]) : null
const inner = [...n.childNodes].map(walk).join('')
return kind ? (mark[kind] ?? '') + inner + (kind === 'quote' ? '' : mark[kind] ?? '') : inner
}
return walk(document.querySelector(${JSON.stringify(BOX)}))
})()`)
const type = async (text) => {
@@ -62,10 +69,10 @@ try {
await page.call('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false })
await ev(`(() => {
const s = window.__mohoShots.store
const acct = { id: 'discord:me', service: 'discord', name: 'me', host: '', port: 0, state: 'connected', hasPassword: true, nick: 'me' }
const buf = { id: 'discord:me|chat', accountId: 'discord:me', kind: 'channel', name: 'chat', lastActivityTs: 5, category: 'Channels', groupId: 'account:discord:me' }
s.set({ accounts: [acct], groups: [{ id: 'account:discord:me', accountId: 'discord:me', service: 'discord', kind: 'account', name: 'me', position: 0 }], buffers: [buf], messagesByBuffer: { 'discord:me|chat': [] }, activeBufferId: 'discord:me|chat' })
s.selectGroup('account:discord:me')
const acct = { id: '${SERVICE}:me', service: '${SERVICE}', name: 'me', host: '', port: 0, state: 'connected', hasPassword: true, nick: 'me' }
const buf = { id: '${SERVICE}:me|chat', accountId: '${SERVICE}:me', kind: 'channel', name: 'chat', lastActivityTs: 5, category: 'Channels', groupId: 'account:${SERVICE}:me' }
s.set({ accounts: [acct], groups: [{ id: 'account:${SERVICE}:me', accountId: '${SERVICE}:me', service: '${SERVICE}', kind: 'account', name: 'me', position: 0 }], buffers: [buf], messagesByBuffer: { '${SERVICE}:me|chat': [] }, activeBufferId: '${SERVICE}:me|chat' })
s.selectGroup('account:${SERVICE}:me')
})()`)
await sleep(1200)
@@ -90,6 +97,53 @@ try {
check('undo puts it back after it was taken off', (await marked()) === 'one **two** three four', await marked())
check('and leaves the word selected', (await ev(`String(getSelection())`)) === 'two', await ev(`String(getSelection())`))
console.log('All of the box')
await type('one two three')
await ev(`(() => { const b = document.querySelector(${JSON.stringify(BOX)}); b.focus(); getSelection().selectAllChildren(b) })()`)
await bold()
check('everything goes bold (select all, then the key)', (await marked()) === '**one two three**', await marked())
await bold()
check('and the key again takes it all off', (await marked()) === 'one two three', await marked())
await bold()
await undo()
check('and undo puts the box back as it was', (await marked()) === 'one two three', await marked())
await ev(`(() => { const b = document.querySelector(${JSON.stringify(BOX)}); b.focus(); getSelection().selectAllChildren(b) })()`)
await sleep(250)
await strip('Bold')
await sleep(250)
check('everything goes bold from the strip', (await marked()) === '**one two three**', await marked())
await strip('Bold')
check('and the strip again takes it all off', (await marked()) === 'one two three', await marked())
for (const [title, m] of [['Code', '`'], ['Spoiler', '||'], ['Italic', '_']]) {
await ev(`(() => { const b = document.querySelector(${JSON.stringify(BOX)}); b.focus(); getSelection().selectAllChildren(b) })()`)
await sleep(250)
await strip(title)
const on = await marked()
await sleep(250)
await strip(title)
check(`${title}: all of the box goes on and comes off again`, on === `${m}one two three${m}` && (await marked()) === 'one two three', `${on} -> ${await marked()}`)
}
console.log('Formats the window makes itself (code, spoiler) undo as well')
for (const [title, m] of [['Code', '`'], ['Spoiler', '||']]) {
await type('one two three four')
await select('two')
await sleep(250)
await strip(title)
const on = await marked()
await undo()
const off = await marked()
const kept = await ev(`String(getSelection())`)
await redo()
check(`${title}: on, undo takes it off with the word still selected, redo puts it on`, on === `one ${m}two${m} three four` && off === 'one two three four' && kept === 'two' && (await marked()) === on, `${on} | ${off} | ${kept} | ${await marked()}`)
await ev(`(() => { const b = document.querySelector(${JSON.stringify(BOX)}); b.focus(); getSelection().selectAllChildren(b) })()`)
await sleep(250)
await strip(title)
await strip(title)
await undo()
check(`${title}: over all of the box, taken off and undone`, (await marked()).replace(/[\`|]/g, '') === 'one two three four' && (await marked()).includes(m), await marked())
}
console.log('Undo leaves a selection that is safe to type over')
await type('one two three four')
await select('two')
@@ -130,9 +184,9 @@ try {
if (!(await select('line\nsecond'))) await select('linesecond')
await bold()
const lines = await ev(`document.querySelector(${JSON.stringify(BOX)}).innerHTML`)
check('a selection over two lines is bold, and the break is still there', /data-fmt="bold"/.test(lines) && (/<br/.test(lines) || /\n/.test(lines)) && (await marked()).replace(/\n/g, '').includes('**'), lines)
check('a selection over two lines is bold, and the break is still there', /<b>|data-fmt="bold"/.test(lines) && (/<br/.test(lines) || /\n/.test(lines)) && (await marked()).replace(/\n/g, '').includes('**'), lines)
await bold()
check('and comes off whole', !/data-fmt/.test(await html()), await html())
check('and comes off whole', !/data-fmt|<b>/.test(await html()), await html())
console.log('Part of a run')
await type('one two three four')
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env node
/**
* The message box in a Discord server (or conversation) the account has not spoken in: replaced by the reason, in a
* scratch moho with injected state (nothing is contacted). The daemon decides the lock; this checks what the window
* makes of the `readOnly` it is given.
*
* node scripts/check-first-word-lock.mjs [output directory]
*/
import fs from 'node:fs'
import path from 'node:path'
import { launchApp, sleep } from './lib/harness.mjs'
const out = process.argv[2]
if (out) fs.mkdirSync(out, { recursive: true })
const { page, stop } = await launchApp({ env: { MOHO_UI_SHOTS: '1' } })
const ev = (code) => page.evaluate(code)
const results = []
const check = (what, ok, detail = '') => {
results.push(ok)
console.log(ok ? ' ok ' : ' FAIL', what, ok ? '' : detail)
}
const REASON = "Send your first message in this server from Discord's own app or website. Discord flags accounts that start talking in a server from another client."
try {
await sleep(2500)
await page.call('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false })
await ev(`(() => {
const s = window.__mohoShots.store
const acct = { id: 'discord:me', service: 'discord', name: 'me', host: '', port: 0, state: 'connected', hasPassword: true, nick: 'me' }
const mk = (name, readOnly) => ({ id: 'discord:me|' + name, accountId: 'discord:me', kind: 'channel', name, lastActivityTs: 5, category: 'Channels', groupId: 'account:discord:me', ...(readOnly ? { readOnly } : {}) })
s.set({ accounts: [acct], groups: [{ id: 'account:discord:me', accountId: 'discord:me', service: 'discord', kind: 'account', name: 'me', position: 0 }], buffers: [mk('chasm/#general', ${JSON.stringify(REASON)}), mk('chasm/#open')], messagesByBuffer: { 'discord:me|chasm/#general': [], 'discord:me|chasm/#open': [] }, activeBufferId: 'discord:me|chasm/#general' })
s.selectGroup('account:discord:me')
})()`)
await sleep(1000)
check('a locked server shows the reason where the box would be', (await ev(`document.querySelector('.composer-readonly')?.innerText ?? ''`)).includes('first message in this server'))
check('with a line saying moho opens it by itself', (await ev(`document.querySelector('.composer-readonly')?.innerText ?? ''`)).includes('opens this up by itself'))
check('and no message box to type in', !(await ev(`!!document.querySelector('.composer-input')`)))
if (out) {
const { data } = await page.call('Page.captureScreenshot', { format: 'png' })
fs.writeFileSync(path.join(out, 'first-word-lock.png'), Buffer.from(data, 'base64'))
}
await ev(`(() => { const s = window.__mohoShots.state(); window.__mohoShots.patch({ buffers: s.buffers.map((b) => ({ ...b, readOnly: undefined })) }) })()`)
await sleep(500)
check('once the lock is lifted the box is back', await ev(`!!document.querySelector('.composer-input')`))
} catch (e) {
console.log(' FAIL', e.message)
results.push(false)
} finally {
await stop()
}
process.exit(results.every(Boolean) ? 0 : 1)
+3 -2
View File
@@ -27,14 +27,15 @@ const shot = async (name) => {
const mouse = (type, x, y, button = 'left') => page.call('Input.dispatchMouseEvent', { type, x, y, button, buttons: type === 'mouseReleased' ? 0 : button === 'right' ? 2 : 1, clickCount: 1 })
const menuLabels = () => ev(`[...document.querySelectorAll('.context-menu .context-menu-item')].map((e) => e.innerText.trim().split('\\n').pop())`)
/** Sets a field the way a person's edit does, so the window's own handlers run. */
const setField = (selector, value, how) => ev(`(() => {
const setField = (selector, value, how) => ev(`(async () => {
const el = document.querySelector(${JSON.stringify(selector)})
if (!el) return false
if (${JSON.stringify(how)} === 'input') el.focus()
const proto = el instanceof HTMLSelectElement ? HTMLSelectElement.prototype : HTMLInputElement.prototype
Object.getOwnPropertyDescriptor(proto, 'value').set.call(el, ${JSON.stringify(value)})
el.dispatchEvent(new Event(${JSON.stringify(how)}, { bubbles: true }))
if (${JSON.stringify(how)} === 'input') el.blur()
// Time for the window to take the edit before the field is left, as it has when a person types.
if (${JSON.stringify(how)} === 'input') { await new Promise((r) => setTimeout(r, 200)); el.blur() }
return true
})()`)
const openGeneral = async () => {
+3
View File
@@ -877,6 +877,8 @@ export function Composer({ thread = false }: { thread?: boolean } = {}): JSX.Ele
// A channel's comments are written to its discussion group, which the channel's own lock says nothing about.
if (buffer.readOnly && !(thread && service === 'telegram')) {
const official = buffer.readOnly.includes('official Discord')
// Discord's first-word lock: the daemon opens it by itself once the account has spoken there.
const firstWord = buffer.readOnly.includes("Discord's own app")
return (
<div className="composer">
<div className="divider-h" />
@@ -887,6 +889,7 @@ export function Composer({ thread = false }: { thread?: boolean } = {}): JSX.Ele
{official && (
<span className="small">Discord will never ask you for your password or account token.</span>
)}
{firstWord && <span className="small">moho notices when you have, and opens this up by itself.</span>}
</div>
</div>
</div>
@@ -69,6 +69,21 @@ describe('serialising the box', () => {
})
})
describe('what the browser makes in the box', () => {
it('reads its own bold, italic, underline and strikethrough as ours', () => {
const made = box(el('B', [text('b')]), text(' '), el('I', [text('i')]), text(' '), el('U', [text('u')]), text(' '), el('STRIKE', [text('s')]))
expect(serialize(made, 'discord')).toBe('**b** *i* __u__ ~~s~~')
expect(serialize(made, 'sneedchat')).toBe('[b]b[/b] [i]i[/i] [u]u[/u] [s]s[/s]')
})
it('sees through the plain wrapper put round content when a format is taken off', () => {
const wrapped = box(el('SPAN', [text('one '), fmt('bold', [text('two')]), text(' three')], { plain: '' }))
expect(serialize(wrapped, 'discord')).toBe('one **two** three')
})
it('does not say bold twice for bold inside bold', () => {
expect(serialize(box(el('B', [fmt('bold', [text('x')])])), 'discord')).toBe('**x**')
})
})
describe('markup details', () => {
it('fences code with more backticks than it holds', () => {
expect(wrap('discord', 'code', 'a`b')).toBe('``a`b``')
+26 -2
View File
@@ -190,6 +190,9 @@ export function transformFormat(root: HTMLElement, range: Range, kind: FormatKin
return true
}
/** The formats the browser can make and unmake itself, and its name for each. */
const NATIVE: Partial<Record<FormatKind, string>> = { bold: 'bold', italic: 'italic', underline: 'underline', strike: 'strikeThrough' }
/** Where a point in the box is, by child positions from the box down, so it can be found again in a copy. */
function pathOf(root: Node, node: Node, offset: number): number[] {
const path = [offset]
@@ -215,6 +218,16 @@ function resolve(root: Node, path: number[]): [Node, number] {
* replacement lands in cannot put back a format that was just taken off.
*/
export function applyFormat(root: HTMLElement, kind: FormatKind, colour?: string): boolean {
const native = NATIVE[kind]
if (native) {
// The browser's own bold, italic, underline and strikethrough: it knows how to take them off again from all of a
// selection, part of one or the whole box - the last of which the replacement below cannot do, because the
// browser keeps the formatting of what it replaces when that is everything in the box - and its undo steps over
// them and puts the selection back by itself. Serialising reads the elements it makes as it does ours.
root.focus()
document.execCommand('styleWithCSS', false, 'false')
return document.execCommand(native)
}
const before = root.innerHTML
const beforeSelection = currentSelection(root)
const selection = window.getSelection()
@@ -224,9 +237,20 @@ export function applyFormat(root: HTMLElement, kind: FormatKind, colour?: string
root.focus()
const copy = root.cloneNode(true) as HTMLElement
// Content that begins with plain text is put in a wrapper of its own. The browser keeps the formatting of whatever
// it replaces when the replacement is text and the selection is everything inside one formatted run - so taking a
// format off all of the box put it straight back - and does not when the replacement starts with an element.
const wrapped = copy.firstChild?.nodeType === 3
const shift = (path: number[]): number[] => (wrapped ? [0, ...path] : path)
if (wrapped) {
const wrapper = document.createElement('span')
wrapper.dataset.plain = ''
wrapper.append(...Array.from(copy.childNodes))
copy.append(wrapper)
}
const range = document.createRange()
range.setStart(...resolve(copy, pathOf(root, picked.startContainer, picked.startOffset)))
range.setEnd(...resolve(copy, pathOf(root, picked.endContainer, picked.endOffset)))
range.setStart(...resolve(copy, shift(pathOf(root, picked.startContainer, picked.startOffset))))
range.setEnd(...resolve(copy, shift(pathOf(root, picked.endContainer, picked.endOffset))))
if (!transformFormat(copy, range, kind, colour)) return false
const start = pathOf(copy, range.startContainer, range.startOffset)