mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
fix(desktop): channel topic and membership metadata cleanup (#3642)
First slice of #2216, scoped to the system/status lines in the chat timeline. ## Why Two problems on the same surface. **Clearing a channel topic renders as empty quotes.** The relay reports a clear as a `topic_changed` event carrying an empty string — there's no separate "cleared" event type. So the timeline printed: > Alice > changed the topic to “” which reads as if the topic were *set to* two quote marks. Same for purpose. **The membership caption reads like a headline, not a metadata line.** `title` and `action` render on separate lines — the member's name sits in the header row with the avatar and timestamp, and the caption sits beneath it. So the caption was "was added by Alice Chen" standing alone under a name, while its siblings on that same line are "joined the channel" and "left the channel". ## What - Blank, missing, or whitespace-only topic/purpose now reads **"cleared the channel topic"** / **"cleared the channel purpose"**. - Membership captions drop "was": **"added by Alice Chen"**, matching "joined the channel" and "left the channel". - The wording moves to `lib/systemEventCopy.ts` as a pure function, so it's assertable in a unit test instead of only reachable through the DOM. That also removes two JSX fragments from `SystemMessageRow.tsx`, taking it 911 → 900 lines. ## Two E2E assertions this exposed Both were measuring something other than what they claimed, and the copy change tipped them over. Neither is a product bug, but both would have failed the next person too. 1. **`mentions.spec.ts:1245`** asserted a button was un-underlined while the mouse was still parked from a previous `hover()`. Any reflow — new rows, scroll-to-bottom, a different text wrap — can slide that button under the stationary pointer, so the assertion measured *where the mouse happened to be* rather than the resting style. Dropping four characters changed the text wrap, changed the row height, changed the scroll offset, and the pointer landed on it. Now parks the pointer off-target first. 2. **`mentions.spec.ts:1253`** used a bare `role=tooltip` lookup. Once the first tooltip animates out while the second opens, two elements match and strict mode trips. Now scopes to the open tooltip via `:not([data-state="closed"])`. ## Deliberately out of scope - **Timestamps.** The day divider, per-message clock times, the Inbox thread pane, and the inbox list have three divergent date implementations and none fully match the writing standard's Today/Yesterday/weekday/date progression. That's its own slice of #2216. - **Whose avatar shows.** An addition puts the *added* member in the header; a removal puts the *remover* there. Possibly intentional, but it's a design question, not copy. - **`the channel` vs `this channel`.** joined/left/removed say "the channel"; created/archived/unarchived say "this channel". Worth normalizing, but it touches lines this PR otherwise leaves alone. ## Validation - `pnpm check`, `pnpm typecheck` — clean - Unit: **3781/3781**, including 6 new tests in `systemEventCopy.test.mjs` covering set/blank/undefined/null/whitespace for both fields, plus a guard that no variant can emit empty quotes - Smoke E2E `mentions` + `messaging`: **85/85** - The previously fragile test run with `--repeat-each=5`: **5/5** Signed-off-by: Clay Delk <clay.delk@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
ede2686334
commit
9e8fcfda09
@@ -279,7 +279,12 @@ class _MembershipSystemMessageContent extends StatelessWidget {
|
||||
TextSpan(
|
||||
text: event.isSelfJoin
|
||||
? 'joined the channel'
|
||||
: 'was added by ${resolveLabel(event.actorPubkey)}',
|
||||
// No "was": the name renders on the line above via
|
||||
// MessageAuthorMeta, so this reads as a status line rather than a
|
||||
// sentence continuing across the metadata row. Matches desktop's
|
||||
// SystemMessageRow. `SystemEvent.describe` keeps "was added by"
|
||||
// because it builds subject and predicate into one string.
|
||||
: 'added by ${resolveLabel(event.actorPubkey)}',
|
||||
),
|
||||
if (additionalTargets.isNotEmpty)
|
||||
TextSpan(text: event.isSelfJoin ? ' along with ' : ', along with '),
|
||||
|
||||
@@ -101,9 +101,10 @@ class SystemEvent {
|
||||
final target = resolveLabel(targetPubkey);
|
||||
return '$actor removed $target from the channel';
|
||||
}(),
|
||||
SystemEventType.topicChanged => '$actor changed the topic to "$topic"',
|
||||
SystemEventType.topicChanged =>
|
||||
'$actor ${_describeTextFieldChange('topic', topic)}',
|
||||
SystemEventType.purposeChanged =>
|
||||
'$actor changed the purpose to "$purpose"',
|
||||
'$actor ${_describeTextFieldChange('purpose', purpose)}',
|
||||
SystemEventType.channelCreated => '$actor created this channel',
|
||||
SystemEventType.channelArchived => '$actor archived this channel',
|
||||
SystemEventType.channelUnarchived => '$actor unarchived this channel',
|
||||
@@ -113,6 +114,25 @@ class SystemEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/// Caption fragment for a channel topic or purpose change, e.g.
|
||||
/// `changed the topic to "Release planning"` or `cleared the topic`.
|
||||
///
|
||||
/// A blank value means the field was cleared: the relay reports a clear as a
|
||||
/// `topic_changed` / `purpose_changed` event carrying an empty string, not as a
|
||||
/// separate event type. Without this branch the timeline renders
|
||||
/// `changed the topic to ""`, which reads as if the topic were set to two quote
|
||||
/// marks. Whitespace-only values are treated as cleared for the same reason.
|
||||
///
|
||||
/// Mirrors `describeChannelTextFieldChange` in
|
||||
/// `desktop/src/features/messages/lib/systemEventCopy.ts`.
|
||||
String _describeTextFieldChange(String field, String? value) {
|
||||
final trimmed = value?.trim();
|
||||
if (trimmed == null || trimmed.isEmpty) {
|
||||
return 'cleared the $field';
|
||||
}
|
||||
return 'changed the $field to "$trimmed"';
|
||||
}
|
||||
|
||||
@immutable
|
||||
class TimelineReaction {
|
||||
final String emoji;
|
||||
|
||||
@@ -1348,7 +1348,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Bob'), findsOneWidget);
|
||||
final addedAction = findRichText('was added by Alice');
|
||||
final addedAction = findRichText('added by Alice');
|
||||
expect(addedAction, findsOneWidget);
|
||||
expect(find.text('Alice added Bob to the channel'), findsNothing);
|
||||
expect(
|
||||
@@ -1366,7 +1366,7 @@ void main() {
|
||||
expect(timestampRect.left, greaterThan(nameRect.right));
|
||||
final addedText = tester.widget<RichText>(addedAction);
|
||||
expect(
|
||||
effectiveFontSizeForText(addedText.text, 'was added by Alice'),
|
||||
effectiveFontSizeForText(addedText.text, 'added by Alice'),
|
||||
systemMessageBodyTextStyle.fontSize,
|
||||
);
|
||||
});
|
||||
@@ -1435,7 +1435,7 @@ void main() {
|
||||
|
||||
expect(find.text('Bob'), findsOneWidget);
|
||||
expect(
|
||||
findRichText('was added by Alice, along with Carol, Dave, Erin, and '),
|
||||
findRichText('added by Alice, along with Carol, Dave, Erin, and '),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byKey(const Key('membership-overflow')), findsOneWidget);
|
||||
|
||||
@@ -287,6 +287,53 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
// The relay reports a clear as a change carrying an empty string, so
|
||||
// without the cleared branch this reads: changed the topic to "".
|
||||
test('a blank topic or purpose reads as cleared', () {
|
||||
for (final blank in [null, '', ' \n\t ']) {
|
||||
expect(
|
||||
SystemEvent(
|
||||
type: SystemEventType.topicChanged,
|
||||
actorPubkey: 'pk1',
|
||||
topic: blank,
|
||||
).describe(resolve),
|
||||
'Alice cleared the topic',
|
||||
);
|
||||
expect(
|
||||
SystemEvent(
|
||||
type: SystemEventType.purposeChanged,
|
||||
actorPubkey: 'pk1',
|
||||
purpose: blank,
|
||||
).describe(resolve),
|
||||
'Alice cleared the purpose',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('no caption announces empty quotes', () {
|
||||
for (final value in [null, '', ' ', 'Real topic']) {
|
||||
expect(
|
||||
SystemEvent(
|
||||
type: SystemEventType.topicChanged,
|
||||
actorPubkey: 'pk1',
|
||||
topic: value,
|
||||
).describe(resolve),
|
||||
isNot(contains('""')),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('surrounding whitespace is trimmed out of the quotes', () {
|
||||
expect(
|
||||
SystemEvent(
|
||||
type: SystemEventType.topicChanged,
|
||||
actorPubkey: 'pk1',
|
||||
topic: ' Release v2 ',
|
||||
).describe(resolve),
|
||||
'Alice changed the topic to "Release v2"',
|
||||
);
|
||||
});
|
||||
|
||||
test('channel_created', () {
|
||||
final event = SystemEvent(
|
||||
type: SystemEventType.channelCreated,
|
||||
|
||||
Reference in New Issue
Block a user