Skip to content

Commit 3690b03

Browse files
author
ART3
committed
Keep one channel visit across embedded thread retargets
MessageManagement sat inside the subtree keyed by messageId, so showing another thread of the same channel ended the channel visit and started a new one. Re-entry reconciles the previous visit's message force, so a "Mark unread" made in the first thread was lost. Channels keeps it, because its owner wraps the whole channel. MessageManagement now wraps the keyed thread and is itself keyed by session and channel, so only the thread and its overlay remount on a retarget. Also render MessageManagementStatus there, as Channels and Sessions do. A failed or unconfirmed edit left in the outbox removes Edit and disables Delete on its message; without the notice an embedded thread offered no way to retry or discard it. Signed-off-by: ART3 <822f566773c6b5ec5de21614f3900e5dd78a36d772fb826a3ee0f4b140d68255@buzz.block.builderlab.xyz>
1 parent 00cd0ba commit 3690b03

3 files changed

Lines changed: 96 additions & 27 deletions

File tree

‎docs/plugin-architecture.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,14 @@ ownership and trusted-plugin authority do not change.
577577
renders the existing `ThreadPanel` without its side-panel header, close control
578578
or Escape dismissal; the page owns the surrounding header and placement. The
579579
host supplies the rest of the Channels thread behavior: contribution renderers,
580-
message management (edit, delete, mark read/unread, and the channel visit those
581-
rely on), session-channel recipients, Buzz link navigation, and one modal at a
582-
time for a registered panel or media review. The page passes its current ready
583-
session and stable community/viewer scope; retargeting disposes the old thread
584-
and its modal. The page holds no second message reader, cache or outbox.
580+
message management (edit, delete, mark read/unread, and a notice above the
581+
thread to retry or discard a failed edit or deletion), session-channel
582+
recipients, Buzz link navigation, and one modal at a time for a registered panel
583+
or media review. The page passes its current ready session and stable
584+
community/viewer scope; retargeting disposes the old thread and its modal. As in
585+
Channels, showing a thread is one visit to its channel for unread state, and
586+
that visit lasts across threads of the same channel. The page holds no second
587+
message reader, cache or outbox.
585588
Exact message links still navigate to Channels rather than the page's route.
586589

587590
### Composer ownership and mention tools

‎src/features/conversation/EmbeddedThread.test.tsx‎

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useMessageDeletion } from "../messages/MessageManagement";
1717
import type { MessageRowProps } from "../messages/MessageRow";
1818
import type { PanelProps, RegisteredPanel } from "../panels/service";
1919
import type { ChannelMessage } from "../relay/contracts";
20+
import type { OutgoingEvent } from "../relay/outbox";
2021
import type { RelaySession } from "../relay/session";
2122

2223
// The real ThreadPanel and MessageManagement are composed; only leaf UI with
@@ -69,7 +70,10 @@ afterEach(() => {
6970
vi.unstubAllGlobals();
7071
});
7172

72-
function fixture(channelType: "stream" | "session" = "stream") {
73+
function fixture(
74+
channelType: "stream" | "session" = "stream",
75+
operations: readonly OutgoingEvent[] = [],
76+
) {
7377
vi.stubGlobal(
7478
"ResizeObserver",
7579
class {
@@ -112,8 +116,29 @@ function fixture(channelType: "stream" | "session" = "stream") {
112116
canLoadMore: false,
113117
limited: false,
114118
};
115-
const channels = { channels: [{ id: "c", name: "Channel", channelType }] };
119+
const viewer = "a".repeat(64);
120+
const channels = {
121+
channels: [
122+
{ id: "c", name: "Channel", channelType, members: [viewer] },
123+
{ id: "d", name: "Other", channelType, members: [viewer] },
124+
],
125+
};
126+
const unread = {
127+
sync: () => ({ capability: "unsupported" }),
128+
snapshot: () => undefined,
129+
subscribe: () => () => {},
130+
attention: () => ({ unread: false }),
131+
enterChannel: vi.fn(async () => {}),
132+
leaveChannel: vi.fn(),
133+
};
134+
const outbox = {
135+
subscribe: () => () => {},
136+
snapshot: () => operations,
137+
supports: () => true,
138+
retry: vi.fn(),
139+
};
116140
const session = {
141+
viewer,
117142
thread: () => ({
118143
snapshot: () => thread,
119144
subscribe: () => () => {},
@@ -126,14 +151,10 @@ function fixture(channelType: "stream" | "session" = "stream") {
126151
agentChoices: createAgentLibrary(undefined).queries,
127152
messages: { retry() {} },
128153
media: () => undefined,
129-
unread: {
130-
sync: () => ({ capability: "unsupported" }),
131-
snapshot: () => undefined,
132-
subscribe: () => () => {},
133-
attention: () => ({ unread: false }),
134-
},
154+
unread,
155+
outbox,
135156
} as unknown as RelaySession;
136-
const scope = `https://fixture.test:${"a".repeat(64)}`;
157+
const scope = `https://fixture.test:${viewer}`;
137158
const host = {
138159
panels: {
139160
snapshot: () => panels,
@@ -159,6 +180,8 @@ function fixture(channelType: "stream" | "session" = "stream") {
159180
};
160181
return {
161182
props,
183+
unread,
184+
outbox,
162185
listeners,
163186
panelProps: () => captured,
164187
removePanels() {
@@ -215,3 +238,40 @@ it.each([
215238
);
216239
},
217240
);
241+
242+
it("keeps one channel visit while the thread is retargeted within a channel", () => {
243+
const h = fixture();
244+
const view = render(<EmbeddedThread {...h.props} />);
245+
expect(h.unread.enterChannel).toHaveBeenCalledExactlyOnceWith("c");
246+
view.rerender(<EmbeddedThread {...h.props} messageId={"c".repeat(64)} />);
247+
expect(h.unread.enterChannel).toHaveBeenCalledOnce();
248+
expect(h.unread.leaveChannel).not.toHaveBeenCalled();
249+
// Leaving the channel is the barrier: the visit does follow the channel.
250+
view.rerender(<EmbeddedThread {...h.props} channelId="d" />);
251+
expect(h.unread.leaveChannel).toHaveBeenCalledExactlyOnceWith("c");
252+
expect(h.unread.enterChannel).toHaveBeenLastCalledWith("d");
253+
});
254+
255+
it("offers recovery for a failed edit left in the outbox", () => {
256+
const h = fixture("stream", [
257+
{
258+
event: {
259+
id: "edit",
260+
kind: 40003,
261+
content: "edited",
262+
tags: [
263+
["h", "c"],
264+
["e", "a".repeat(64)],
265+
],
266+
},
267+
delivery: "failed",
268+
error: "Relay refused the edit.",
269+
} as unknown as OutgoingEvent,
270+
]);
271+
render(<EmbeddedThread {...h.props} />);
272+
expect(screen.getByRole("status")).toHaveTextContent(
273+
"Message edit: Relay refused the edit.",
274+
);
275+
fireEvent.click(screen.getByRole("button", { name: "Retry message update" }));
276+
expect(h.outbox.retry).toHaveBeenCalledExactlyOnceWith("edit");
277+
});

‎src/features/conversation/EmbeddedThread.tsx‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { buzzLinkTarget } from "../navigation/buzz-links";
1111
import { PanelView } from "../panels/PanelView";
1212
import type { RegisteredPanel } from "../panels/service";
1313
import { MediaReviewViewer } from "../messages/MediaReviewViewer";
14-
import { MessageManagement } from "../messages/MessageManagement";
14+
import {
15+
MessageManagement,
16+
MessageManagementStatus,
17+
} from "../messages/MessageManagement";
1518
import { ThreadPanel, type ThreadPanelProps } from "../messages/ThreadPanel";
1619
import { messageViewKey } from "../messages/view-key";
1720

@@ -35,18 +38,21 @@ type Overlay =
3538
panel?: undefined;
3639
};
3740

38-
/** Retargeting remounts, so overlays and message actions never outlive their thread. */
41+
/**
42+
* As in Channels, the channel visit and message recovery span threads of one
43+
* channel; retargeting remounts only the thread and its overlay.
44+
*/
3945
export function EmbeddedThread(props: Props) {
46+
const { session, scope, channelId, messageId } = props;
4047
return (
41-
<OwnedEmbeddedThread
42-
key={messageViewKey(
43-
props.session,
44-
props.scope,
45-
props.channelId,
46-
props.messageId,
47-
)}
48-
{...props}
49-
/>
48+
<MessageManagement
49+
key={messageViewKey(session, scope, channelId)}
50+
session={session}
51+
channelId={channelId}
52+
>
53+
<MessageManagementStatus />
54+
<OwnedEmbeddedThread key={messageId} {...props} />
55+
</MessageManagement>
5056
);
5157
}
5258

@@ -100,7 +106,7 @@ function OwnedEmbeddedThread({ host, extensions, ...props }: Props) {
100106
return true;
101107
};
102108
return (
103-
<MessageManagement session={session} channelId={channelId}>
109+
<>
104110
<ThreadPanel
105111
{...props}
106112
sessionConversation={channels.some(
@@ -169,6 +175,6 @@ function OwnedEmbeddedThread({ host, extensions, ...props }: Props) {
169175
close={() => setOverlay(undefined)}
170176
/>
171177
)}
172-
</MessageManagement>
178+
</>
173179
);
174180
}

0 commit comments

Comments
 (0)