Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(community): message ref opens the context sheet in place, not navigate

Shelly5ca96a2067b1
diff --git a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx
index 3c3c79ae4..a73920ab7 100644
--- a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx
+++ b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx
@@ -595,42 +595,45 @@ function ChannelView() {
router.push(`/c/channels/${params.serverId}/${id}`)
}, [router, params.serverId])
- // Message context sheet for unloaded message refs
- const [contextSheetSeq, setContextSheetSeq] = useState<number | null>(null)
+ // The message context side sheet's target. A message ref opens it to preview
+ // a message + surrounding context WITHOUT navigating (Gus #417). The target
+ // carries the source channel (which may differ from the open one — a
+ // cross-channel ref) so the sheet resolves that channel's seq and shows its
+ // name in the header. `label` is the source channel's display name (passed in
+ // so the sheet needn't refetch metadata).
+ const [contextTarget, setContextTarget] = useState<
+ { serverId: string; channelId: string; label: string; seq: number } | null
+ >(null)
+ // Chained `#N` refs inside the sheet reopen it on the new seq — same channel
+ // as the currently-shown one (a `#N` in a previewed message is scoped to that
+ // message's channel).
+ const openContextSeq = useCallback((seq: number) => {
+ setContextTarget((prev) =>
+ prev ? { ...prev, seq } : { serverId, channelId, label: channelName, seq },
+ )
+ }, [serverId, channelId, channelName])
- // Jump to a message by seq within THIS channel — invoked by a same-channel
- // message-ref pill (`/server/channel#N` where the channel is open) via the
- // `jumpToSeq` UI-handler. Loaded in the window → reuse the mount-time scroll
- // path (`setScrollToMessageId` scrolls + highlights); not loaded → open the
- // context sheet, which resolves seq→id server-side. Reads `messages` lazily
- // off the actions ref so the callback stays reference-stable (no memo churn).
+ // Same-channel message ref (`/server/channel#N`, channel open) via `jumpToSeq`:
+ // message loaded in the window → scroll+highlight it in place; not loaded →
+ // open the context sheet on THIS channel. Reads `messages` lazily off the
+ // actions ref so the callback stays reference-stable (no memo churn).
const jumpToSeq = useCallback((seq: number) => {
const msg = actionsCtxRef.current.messages.find((m) => m.seq === seq)
if (msg) setScrollToMessageId(msg.id)
- else setContextSheetSeq(seq)
- }, [])
- useEffect(() => {
- useCommunityStore.getState().registerUiHandlers({ jumpToSeq })
- return () => useCommunityStore.getState().registerUiHandlers({ jumpToSeq: undefined })
- }, [jumpToSeq])
-
- // Cross-channel message ref: a pill in another channel navigated here with
- // `?msgseq=N` (see shell-frame's `navigate`). Land on that message once — a
- // freshly-opened channel rarely has an arbitrary seq in its initial window,
- // so this usually opens the context sheet (resolves seq→id server-side); if
- // the message happens to be loaded, jumpToSeq scrolls to it. Captured once at
- // mount and the param is stripped so a refresh/back doesn't re-trigger.
- const [jumpSeqTarget] = useState<number | null>(() => {
- const raw = searchParams.get("msgseq")
- const n = raw ? parseInt(raw, 10) : NaN
- return Number.isFinite(n) && n > 0 ? n : null
- })
+ else setContextTarget({ serverId, channelId, label: channelName, seq })
+ }, [serverId, channelId, channelName])
+ // Cross-channel message ref via `openMessageContext`: open the sheet IN PLACE
+ // on the target (other) channel — never navigate (Gus #417). The sheet's
+ // access-checked read path returns not-found for a channel the viewer can't
+ // see, so a private-channel ref leaks nothing.
+ const openMessageContext = useCallback(
+ (target: { serverId: string; channelId: string; label: string; seq: number }) => setContextTarget(target),
+ [],
+ )
useEffect(() => {
- if (jumpSeqTarget === null) return
- jumpToSeq(jumpSeqTarget)
- router.replace(`/c/channels/${params.serverId}/${channelId}`, { scroll: false })
- // eslint-disable-next-line react-hooks/exhaustive-deps -- run once for this mount's cross-channel jump
- }, [])
+ useCommunityStore.getState().registerUiHandlers({ jumpToSeq, openMessageContext })
+ return () => useCommunityStore.getState().registerUiHandlers({ jumpToSeq: undefined, openMessageContext: undefined })
+ }, [jumpToSeq, openMessageContext])
// Stable so it doesn't bust the memoized message rows; reads uiHandlers
// lazily through the actions ref (assigned just below).
@@ -1052,7 +1055,7 @@ function ChannelView() {
onLoadNewer={fetchNewerMessages}
onJumpToPresent={jumpToPresent}
unreadCount={unreadCount}
- onOpenContextSheet={setContextSheetSeq}
+ onOpenContextSheet={openContextSeq}
/>
<Composer
channel={channelName}
@@ -1080,17 +1083,18 @@ function ChannelView() {
)}
{manageMembersDialog}
<MessageContextSheet
- open={contextSheetSeq !== null}
- onOpenChange={(v) => { if (!v) setContextSheetSeq(null) }}
- channelId={channelId}
- targetSeq={contextSheetSeq}
+ open={contextTarget !== null}
+ onOpenChange={(v) => { if (!v) setContextTarget(null) }}
+ channelId={contextTarget?.channelId ?? channelId}
+ channelLabel={contextTarget?.label}
+ targetSeq={contextTarget?.seq ?? null}
pinnedIds={pinnedIds}
- onOpenContextSheet={setContextSheetSeq}
+ onOpenContextSheet={openContextSeq}
onOpenProfile={openProfile}
resolveUserName={resolveUserName}
onReply={(target) => {
setReplyTo(target)
- setContextSheetSeq(null)
+ setContextTarget(null)
}}
/>
</>
@@ -1202,7 +1206,7 @@ function ChannelView() {
onLoadNewer={fetchNewerMessages}
onJumpToPresent={jumpToPresent}
unreadCount={unreadCount}
- onOpenContextSheet={setContextSheetSeq}
+ onOpenContextSheet={openContextSeq}
/>
<Composer
channel={channelName}
@@ -1230,17 +1234,18 @@ function ChannelView() {
)}
{manageMembersDialog}
<MessageContextSheet
- open={contextSheetSeq !== null}
- onOpenChange={(v) => { if (!v) setContextSheetSeq(null) }}
- channelId={channelId}
- targetSeq={contextSheetSeq}
+ open={contextTarget !== null}
+ onOpenChange={(v) => { if (!v) setContextTarget(null) }}
+ channelId={contextTarget?.channelId ?? channelId}
+ channelLabel={contextTarget?.label}
+ targetSeq={contextTarget?.seq ?? null}
pinnedIds={pinnedIds}
- onOpenContextSheet={setContextSheetSeq}
+ onOpenContextSheet={openContextSeq}
onOpenProfile={openProfile}
resolveUserName={resolveUserName}
onReply={(target) => {
setReplyTo(target)
- setContextSheetSeq(null)
+ setContextTarget(null)
}}
/>
</>
diff --git a/src/web/src/components/community/channel-ref-pill.tsx b/src/web/src/components/community/channel-ref-pill.tsx
index 69b9cce4a..cf0258670 100644
--- a/src/web/src/components/community/channel-ref-pill.tsx
+++ b/src/web/src/components/community/channel-ref-pill.tsx
@@ -149,23 +149,29 @@ export function ChannelRefPill({ children }: { children?: React.ReactNode }) {
if (view.kind === "plain") return <>{view.text}</>
if (view.kind === "muted") return <ChannelPill muted>{view.label}</ChannelPill>
- // A message ref (`#N` suffix) whose target is the ALREADY-OPEN channel should
- // SCROLL to the message, not navigate (navigating to the current channel is a
- // no-op that leaves the viewport put — the same-channel regression from
- // dropping the bare-`#N` pill). Route through the `jumpToSeq` UI-handler the
- // page registers (message loaded → scroll; else context sheet resolves
- // seq→id). Cross-channel refs navigate via the `navigate` UI-handler — NOT a
- // local `useRouter()`: this pill renders inside the memoized Streamdown
- // message tree where `router.push` is a silent no-op (the click did nothing);
- // the shell registers `navigate` off its live router. Scroll-after-navigate
- // is a separate followup (see message-ref-upgrade.md).
- const sameChannelSeq =
- view.messageSuffix !== undefined && view.href.channelId === currentChannelId
- ? view.messageSuffix
- : undefined
- const onClick = sameChannelSeq !== undefined
- ? () => uiHandlers.jumpToSeq?.(sameChannelSeq)
- : () => uiHandlers.navigate?.(view.href.serverId, view.href.channelId, view.messageSuffix)
+ // Click intent depends on what the ref points at (Gus #417):
+ // - A MESSAGE ref (`#N`) means "see that message's context", NOT "go to that
+ // channel". So it never navigates:
+ // · same channel → `jumpToSeq` (message loaded → scroll to it; else the
+ // context sheet resolves seq→id) — stays put.
+ // · other channel → `openMessageContext` opens the context side sheet IN
+ // PLACE for the target channel's seq (access-checked read path), so the
+ // viewer reads the context without leaving their current channel.
+ // - A plain CHANNEL/THREAD ref (no `#N`) means "go there" → `navigate`
+ // (through the shell's live router — a subtree `useRouter().push` no-ops
+ // inside the memoized Streamdown tree, a pre-existing bug).
+ const isMsgRef = view.messageSuffix !== undefined
+ const sameChannel = view.href.channelId === currentChannelId
+ const onClick = isMsgRef
+ ? sameChannel
+ ? () => uiHandlers.jumpToSeq?.(view.messageSuffix!)
+ : () => uiHandlers.openMessageContext?.({
+ serverId: view.href.serverId,
+ channelId: view.href.channelId,
+ label: view.label,
+ seq: view.messageSuffix!,
+ })
+ : () => uiHandlers.navigate?.(view.href.serverId, view.href.channelId)
return (
<>
diff --git a/src/web/src/components/community/message-context-sheet.tsx b/src/web/src/components/community/message-context-sheet.tsx
index 2688d05a1..14990042f 100644
--- a/src/web/src/components/community/message-context-sheet.tsx
+++ b/src/web/src/components/community/message-context-sheet.tsx
@@ -8,6 +8,7 @@ import { deriveThreadName } from "@alook/shared"
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet"
import { useSheetResize, SheetResizeHandle } from "@/components/ui/sheet-resize-handle"
import { MessageRow } from "./message-row"
+import { ChannelIcon } from "./channel-icon"
import { Skeleton } from "@/components/ui/skeleton"
import { apiFetch, toastApiError } from "@/lib/api/client"
import { ApiError } from "@/lib/errors"
@@ -115,6 +116,7 @@ export function MessageContextSheet({
open,
onOpenChange,
channelId,
+ channelLabel,
targetSeq,
pinnedIds,
onOpenContextSheet,
@@ -126,6 +128,10 @@ export function MessageContextSheet({
open: boolean
onOpenChange: (v: boolean) => void
channelId: string
+ // Source channel's display name for the header — a message ref opens this
+ // sheet to preview a (possibly other) channel's message in place, so the
+ // header names which channel's context this is (Gus #417/#423, Alli #420).
+ channelLabel?: string
targetSeq: number | null
pinnedIds?: Set<string>
onOpenContextSheet?: (seq: number) => void
@@ -362,10 +368,26 @@ export function MessageContextSheet({
className="flex flex-col p-0 data-[side=right]:sm:inset-y-2 data-[side=right]:sm:right-2 data-[side=right]:sm:h-auto data-[side=right]:sm:rounded-xl data-[side=right]:sm:border data-[side=right]:sm:overflow-hidden"
>
<SheetResizeHandle onPointerDown={onPointerDown} onPointerMove={onPointerMove} onPointerUp={onPointerUp} />
+ {/* Header names WHICH channel's context this is (Gus #417/#423, Alli
+ #420): channel icon + name as the primary line, the seq as weaker
+ secondary info — the intent here is "reading a channel's context",
+ the seq is just the locator. Shown consistently (same- or cross-
+ channel) for one message-side-sheet mental model. Frameless (no
+ border) matches the existing quiet header. Falls back to just `#N`
+ if no label was passed (older callers). */}
<SheetHeader className="gap-0 border-b-0 py-3">
- <SheetTitle className="flex items-baseline gap-0.5 font-mono text-2xl font-semibold tracking-tight">
- <span className="text-muted-foreground">#</span>
- <span>{targetSeq ?? ""}</span>
+ <SheetTitle className="flex items-center gap-1.5 text-lg font-semibold tracking-tight">
+ {channelLabel ? (
+ <>
+ <ChannelIcon className="shrink-0 text-muted-foreground" />
+ <span className="min-w-0 truncate">{channelLabel}</span>
+ <span className="shrink-0 font-mono text-base font-normal text-muted-foreground">#{targetSeq ?? ""}</span>
+ </>
+ ) : (
+ <span className="font-mono text-2xl">
+ <span className="text-muted-foreground">#</span>{targetSeq ?? ""}
+ </span>
+ )}
</SheetTitle>
</SheetHeader>
diff --git a/src/web/src/components/community/shell-frame.tsx b/src/web/src/components/community/shell-frame.tsx
index 0197fcfd6..17a14363d 100644
--- a/src/web/src/components/community/shell-frame.tsx
+++ b/src/web/src/components/community/shell-frame.tsx
@@ -409,17 +409,9 @@ export function ShellFrame({
// shell's router is the live one (rail clicks above navigate through it), so
// the pills route through this bridge instead.
const navigate = useCallback(
- (serverId: string, channelId?: string, seq?: number) => {
+ (serverId: string, channelId?: string) => {
markSwitch(channelId ? "channel" : "server", channelId ?? serverId)
- if (channelId) {
- // `?msgseq=N` makes the destination channel jump to that message on
- // arrival (a cross-channel message ref) — the channel page reads it and
- // calls jumpToSeq. Without a channel (server ref) there's no message.
- const q = seq !== undefined ? `?msgseq=${seq}` : ""
- router.push(`/c/channels/${serverId}/${channelId}${q}`)
- } else {
- router.push(`/c/channels/${serverId}`)
- }
+ router.push(channelId ? `/c/channels/${serverId}/${channelId}` : `/c/channels/${serverId}`)
},
[router],
)
diff --git a/src/web/src/stores/community/index.ts b/src/web/src/stores/community/index.ts
index f0d0f138f..6f679c35c 100644
--- a/src/web/src/stores/community/index.ts
+++ b/src/web/src/stores/community/index.ts
@@ -82,17 +82,25 @@ type CommunityUiHandlers = {
// clicking still scrolls to the message — the behavior the bare-`#N` pill had
// before message-ref-upgrade.md removed it.
jumpToSeq?: (seq: number) => void
- // Navigate to a server (channelId omitted) or a channel, optionally landing on
- // a specific message `seq` (a cross-channel message ref). Registered by the
+ // Navigate to a server (channelId omitted) or a channel. Registered by the
// shell (shell-frame) where the router is the live App-Router instance.
// Channel/server-ref pills call this INSTEAD of a subtree `useRouter()`:
// those pills render deep inside the memoized Streamdown message tree, where
// `useRouter().push` is a no-op (the ref pill's cross-channel click silently
// did nothing — a pre-existing bug the full-path refs exposed). The shell
// router works (rail clicks navigate through it), so route through the bridge.
- // With `seq`, the target channel opens with `?msgseq=N` and jumps to that
- // message on arrival (see the channel page's `?msgseq` handler).
- navigate?: (serverId: string, channelId?: string, seq?: number) => void
+ // (A message ref does NOT navigate — it opens the context sheet in place via
+ // `openMessageContext`; only a plain channel/server ref navigates.)
+ navigate?: (serverId: string, channelId?: string) => void
+ // Open the message context side sheet IN PLACE for a message ref — the
+ // channel page registers this. A message ref's intent is "see that message's
+ // context", not "go to that channel" (Gus #417), so clicking it never
+ // navigates: the sheet resolves the target channel's seq→id + surrounding
+ // messages (via the access-checked read path — a private channel the viewer
+ // can't see returns not-found, no leak) and shows them without leaving the
+ // current channel. `label` is the source channel's display name for the sheet
+ // header (passed in so the sheet needn't refetch channel metadata).
+ openMessageContext?: (target: { serverId: string; channelId: string; label: string; seq: number }) => void
}
type Timer = ReturnType<typeof setTimeout>
@@ -253,7 +261,8 @@ const stableUiHandlers: CommunityUiHandlers = {
useCommunityStore.getState().uiHandlers.openProfile?.(name, e, discriminator, userId),
goBackMobile: () => useCommunityStore.getState().uiHandlers.goBackMobile?.(),
jumpToSeq: (seq) => useCommunityStore.getState().uiHandlers.jumpToSeq?.(seq),
- navigate: (serverId, channelId, seq) => useCommunityStore.getState().uiHandlers.navigate?.(serverId, channelId, seq),
+ navigate: (serverId, channelId) => useCommunityStore.getState().uiHandlers.navigate?.(serverId, channelId),
+ openMessageContext: (target) => useCommunityStore.getState().uiHandlers.openMessageContext?.(target),
}
export const useUiHandlers = () => stableUiHandlers