mirror of
https://github.com/block/buzz.git
synced 2026-10-31 06:21:34 +00:00
Editing a message to add an @mention never notified the newly-mentioned party. build_message_edit (kind 40003) emitted h/e/imeta/emoji tags but no `p` tags at all — the send path's mention_tags(mentions) was simply omitted from the edit path, so no mention-filtered subscription (e.g. the ACP agent harness) ever saw the added mention. Emit `p` tags for newly-added mentions ONLY. The composer diffs the edited body's resolved mentions against the original body's (both via the same channel-roster resolver the send path uses) and passes just the added set down through the edit command into build_message_edit. A typo-fix edit that leaves the mention set unchanged emits zero `p` tags and re-wakes nobody. Plumbing threads one new arg per layer: build_message_edit(mentions), edit_message(mention_pubkeys), editMessage/useEditMessageMutation (mentionPubkeys), handleEditSave + the onEditSave signature. The diff lives in a pure threading.ts helper (diffAddedMentionPubkeys) next to normalizeMentionPubkeys — lowercase/dedup/self-scrub, case-insensitive comparison so a case-only difference is never treated as newly added. Tests: events.rs pins the builder contract (added -> `p` tag, unchanged -> none, dedup+lowercase); diffAddedMentionPubkeys.test.mjs covers the diff both ways plus self-scrub, case-only no-op, remove/re-add. check-file-sizes.mjs: MessageComposer.tsx limit ratcheted 1091 -> 1114 (+23, load-bearing composer-side wiring; diff logic lives in threading.ts), matching the file's existing per-lane ratchet convention. Co-authored-by: Tyler <109685178+tlongwell-block@users.noreply.github.com> Signed-off-by: Tyler <109685178+tlongwell-block@users.noreply.github.com>
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { diffAddedMentionPubkeys } from "./threading.ts";
|
|
|
|
const ALICE = "a".repeat(64);
|
|
const BOB = "b".repeat(64);
|
|
const SELF = "c".repeat(64);
|
|
|
|
test("returns mentions the edit newly adds", () => {
|
|
// Original mentioned Alice; edit adds Bob.
|
|
assert.deepEqual(diffAddedMentionPubkeys([ALICE], [ALICE, BOB], SELF), [BOB]);
|
|
});
|
|
|
|
test("typo-fix edit with unchanged mentions re-wakes nobody", () => {
|
|
assert.deepEqual(diffAddedMentionPubkeys([ALICE], [ALICE], SELF), []);
|
|
});
|
|
|
|
test("adding the first mention to a previously unmentioned body", () => {
|
|
assert.deepEqual(diffAddedMentionPubkeys([], [ALICE], SELF), [ALICE]);
|
|
});
|
|
|
|
test("removing a mention adds nothing", () => {
|
|
assert.deepEqual(diffAddedMentionPubkeys([ALICE, BOB], [ALICE], SELF), []);
|
|
});
|
|
|
|
test("case-only difference is not treated as newly added", () => {
|
|
// Original stored uppercase, edit resolves lowercase (or vice versa).
|
|
assert.deepEqual(
|
|
diffAddedMentionPubkeys([ALICE.toUpperCase()], [ALICE], SELF),
|
|
[],
|
|
);
|
|
});
|
|
|
|
test("self-mention added in the edit is scrubbed, never notified", () => {
|
|
assert.deepEqual(diffAddedMentionPubkeys([ALICE], [ALICE, SELF], SELF), []);
|
|
});
|
|
|
|
test("duplicate added mention collapses to one", () => {
|
|
assert.deepEqual(diffAddedMentionPubkeys([], [BOB, BOB, BOB], SELF), [BOB]);
|
|
});
|
|
|
|
test("re-adding a removed mention counts as newly added", () => {
|
|
// Original had no Bob (he was removed in a prior state); this edit adds him.
|
|
assert.deepEqual(diffAddedMentionPubkeys([ALICE], [ALICE, BOB], SELF), [BOB]);
|
|
});
|