Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat[new channels]: highlight new message rails (#1930)

Peter Chinmanf410a0498969
diff --git a/js/app/packages/app/index.css b/js/app/packages/app/index.css
index 08595fceef..6466762c47 100644
--- a/js/app/packages/app/index.css
+++ b/js/app/packages/app/index.css
@@ -750,18 +750,22 @@ html[data-modality="keyboard"] [contenteditable="true"]:focus-visible::after {
}
:root {
+ --message-padding: .5rem;
--thread-shift: 32px;
--user-icon-width: 36px;
- --body-padding: .5rem;
- --left-of-connector: 16px;
- --left-of-user-icon: calc(var(--left-of-connector) - var(--user-icon-width) / 2);
+ --body-padding: 0.5rem;
+ --left-of-connector: calc(
+ var(--message-padding) + var(--user-icon-width) / 2
+ );
+ --left-of-user-icon: calc(
+ var(--left-of-connector) - var(--user-icon-width) / 2
+ );
}
@media (min-width: 640px) {
:root {
--thread-shift: 40px;
- --body-padding: .5rem;
- --left-of-connector: 28px;
+ --body-padding: 0.5rem;
}
}
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsx
index 262bddeba2..a2d6446415 100644
--- a/js/app/packages/channel/Channel/Channel.tsx
+++ b/js/app/packages/channel/Channel/Channel.tsx
@@ -6,10 +6,12 @@ import {
import {
createMemo,
createSignal,
+ onMount,
Show,
Suspense,
type Accessor,
} from 'solid-js';
+import { useBeforeLeave } from '@solidjs/router';
import {
defaultThreadListTargetFromMessage,
ThreadList,
@@ -38,6 +40,10 @@ import { ChannelInput, createInputAttachmentTracker } from '../Input';
import { createChannelMessageActions } from './create-channel-message-actions';
import { createActivityTracker } from '@channel/activity-tracker';
import { useChannelActivity } from '@core/context/channels';
+import {
+ invalidateChannelsActivity,
+ useUpdateChannelsActivityMutation,
+} from '@queries/channel/activity';
import { createChannelDragState } from './create-channel-drag-state';
import { ChannelDropZone } from './ChannelDropZone';
import { buildPostMessageRequest } from '@channel/Input/message-payload';
@@ -74,6 +80,26 @@ export function Channel(props: ChannelProps) {
const activity = useChannelActivity(props.channelId);
+ const updateActivityMutation = useUpdateChannelsActivityMutation({
+ onSuccess: () => {
+ invalidateChannelsActivity();
+ },
+ });
+
+ onMount(() => {
+ updateActivityMutation.mutate({
+ channelId: props.channelId,
+ activityType: 'view',
+ });
+ });
+
+ useBeforeLeave(() => {
+ updateActivityMutation.mutate({
+ channelId: props.channelId,
+ activityType: 'view',
+ });
+ });
+
const [threadListNavigation, setThreadListNavigation] =
createSignal<ThreadListNavigation>();
const [threadListScrollState, setThreadListScrollState] =
@@ -98,7 +124,7 @@ export function Channel(props: ChannelProps) {
const shift = () => threadPaginator.isShifting();
const activityTracker = createActivityTracker({
- lastViewedAt: () => activity().viewed_at,
+ lastViewedAt: () => activity()?.viewed_at,
userId,
});
@@ -188,6 +214,7 @@ export function Channel(props: ChannelProps) {
onDismissNewMessages:
activityTracker.dismissNewMessages,
}}
+ isNewMessage={activityTracker.isNewMessage}
/>
)}
</Show>
diff --git a/js/app/packages/channel/Channel/util.ts b/js/app/packages/channel/Channel/util.ts
index 54c5914c05..ec8e949ab6 100644
--- a/js/app/packages/channel/Channel/util.ts
+++ b/js/app/packages/channel/Channel/util.ts
@@ -2,6 +2,9 @@ import type { DateValue } from '@core/util/date';
import type { ChannelMessagesData } from '@queries/channel/channel-messages';
import type { ApiChannelMessage } from '@service-comms/client';
+/** Minimal shape needed by isNewMessage — satisfied by both ApiChannelMessage and ApiThreadReply. */
+export type NewMessageCheckable = { created_at: string; sender_id: string };
+
export function flattenMessages(
data: ChannelMessagesData | undefined
): ApiChannelMessage[] {
@@ -17,7 +20,7 @@ export function flattenMessages(
}
export function isNewMessage(
- message: ApiChannelMessage,
+ message: NewMessageCheckable,
ctx: {
dismissed: boolean;
lastViewedAt: DateValue | undefined | null;
diff --git a/js/app/packages/channel/Message/Layout.tsx b/js/app/packages/channel/Message/Layout.tsx
index e3b3c3c8f4..92cddb893e 100644
--- a/js/app/packages/channel/Message/Layout.tsx
+++ b/js/app/packages/channel/Message/Layout.tsx
@@ -1,5 +1,5 @@
-import { splitProps, type JSX } from 'solid-js';
import { cn } from '@ui/utils/classname';
+import { type JSX, splitProps } from 'solid-js';
export function Layout(props: JSX.HTMLAttributes<HTMLDivElement>) {
const [local, rest] = splitProps(props, ['class', 'children']);
diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsx
index 8987833ace..0a3925b432 100644
--- a/js/app/packages/channel/Thread/ChannelThread.tsx
+++ b/js/app/packages/channel/Thread/ChannelThread.tsx
@@ -6,6 +6,7 @@ import { useUserId } from '@core/context/user';
import { tryMacroId, useDisplayName } from '@core/user';
import { Thread } from './Thread';
import type { ThreadProps } from './types';
+import type { ApiThreadReply } from '@service-comms/client';
import {
DEFAULT_VISIBLE_REPLY_COUNT,
getCollapsedRepliesCount,
@@ -50,8 +51,16 @@ export function ChannelThread(props: ThreadProps) {
if (replies && !repliesQuery.isLoading) return replies;
return thread().preview ?? [];
};
+ const firstReplyIsNewMessage = () => {
+ const first = activeReplies()[0];
+ return first ? props.isNewMessage?.(first) : false;
+ };
const collapsedRepliesCount = () =>
getCollapsedRepliesCount(thread().reply_count, DEFAULT_VISIBLE_REPLY_COUNT);
+ const collapsedRepliesContainsNewMessages = () =>
+ activeReplies()
+ .slice(DEFAULT_VISIBLE_REPLY_COUNT)
+ .some((reply: ApiThreadReply) => props.isNewMessage?.(reply));
const collapsedReplyUsers = () => getUniqueReplyUserIds(activeReplies());
const collapsedLatestReplyAt = () =>
getThreadLatestReplyAt(thread().latest_reply_at, activeReplies());
@@ -86,7 +95,10 @@ export function ChannelThread(props: ThreadProps) {
</MarkMessaageNotifications>
<Show when={hasReplies() || props.isReplying()}>
<div class="relative w-full">
- <Thread.RailDecorations isReplying={props.isReplying} />
+ <Thread.ReplyRailDecorations
+ isReplying={props.isReplying}
+ firstThreadReplyNewMessage={firstReplyIsNewMessage()}
+ />
<Suspense>
<Thread.RepliesContainer>
<Show
@@ -98,6 +110,7 @@ export function ChannelThread(props: ThreadProps) {
replies={previewReplies()}
getMessageActions={props.getMessageActions}
messageEditor={props.messageEditor}
+ isNewMessage={props.isNewMessage}
/>
}
>
@@ -108,6 +121,7 @@ export function ChannelThread(props: ThreadProps) {
replies={fetchedReplies()}
getMessageActions={props.getMessageActions}
messageEditor={props.messageEditor}
+ isNewMessage={props.isNewMessage}
/>
</Suspense>
</Show>
@@ -140,6 +154,7 @@ export function ChannelThread(props: ThreadProps) {
participants={collapsedReplyUsers()}
latestReplyAt={collapsedLatestReplyAt()}
onClick={expand}
+ hasNewMessages={collapsedRepliesContainsNewMessages()}
/>
</Show>
<Show when={shouldShowReplyButton()}>
diff --git a/js/app/packages/channel/Thread/Thread.ts b/js/app/packages/channel/Thread/Thread.ts
index b8854e791a..bc6c0e08b3 100644
--- a/js/app/packages/channel/Thread/Thread.ts
+++ b/js/app/packages/channel/Thread/Thread.ts
@@ -1,5 +1,5 @@
import { ThreadRow } from './ThreadRow';
-import { ThreadRailDecorations } from './ThreadRailDecorations';
+import { ThreadReplyRailDecorations } from './ThreadReplyRailDecorations';
import { ThreadRepliesContainer } from './ThreadRepliesContainer';
import { ThreadReplyButton } from './ThreadReplyButton';
import { ThreadReplyList } from './ThreadReplyList';
@@ -11,7 +11,7 @@ import { ThreadActionsFooter } from './ThreadActionsFooter';
export const Thread = {
Row: ThreadRow,
- RailDecorations: ThreadRailDecorations,
+ ReplyRailDecorations: ThreadReplyRailDecorations,
RepliesContainer: ThreadRepliesContainer,
ReplyButton: ThreadReplyButton,
ReplyList: ThreadReplyList,
diff --git a/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsx b/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsx
index 73a3c6fe9d..f916703174 100644
--- a/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsx
+++ b/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsx
@@ -18,6 +18,7 @@ type ThreadCollapsedIndicatorProps =
collapsedRepliesCount: number;
participants: string[];
latestReplyAt?: string;
+ hasNewMessages?: boolean;
};
const MAX_VISIBLE_PARTICIPANTS = 4;
@@ -28,6 +29,7 @@ export function ThreadCollapsedIndicator(props: ThreadCollapsedIndicatorProps) {
'collapsedRepliesCount',
'participants',
'latestReplyAt',
+ 'hasNewMessages',
]);
const [hover, setHover] = createSignal(false);
const visibleParticipants = () =>
@@ -39,7 +41,8 @@ export function ThreadCollapsedIndicator(props: ThreadCollapsedIndicatorProps) {
<button
type="button"
class={cn(
- 'flex flex-row gap-2 items-center text-xs w-fit h-[var(--user-icon-width)] touch:min-h-[var(--user-icon-width)] border border-edge-muted bg-menu hover:bg-hover hover-transition-bg pr-2 pl-1 mb-2 select-none focus:bracket-offset-2',
+ 'flex flex-row gap-2 items-center text-xs w-fit h-[var(--user-icon-width)] touch:min-h-[var(--user-icon-width)] border bg-menu hover:bg-hover hover-transition-bg pr-2 pl-1 mb-2 select-none focus:bracket-offset-2',
+ local.hasNewMessages ? 'border-accent' : 'border-edge-muted',
local.class
)}
onMouseEnter={() => {
diff --git a/js/app/packages/channel/Thread/ThreadRail.tsx b/js/app/packages/channel/Thread/ThreadRail.tsx
new file mode 100644
index 0000000000..ca5d401155
--- /dev/null
+++ b/js/app/packages/channel/Thread/ThreadRail.tsx
@@ -0,0 +1,19 @@
+import { cn } from '@ui/utils/classname';
+
+interface ThreadRailProps {
+ newMessage?: boolean;
+}
+
+export function ThreadRail(props: ThreadRailProps) {
+ return (
+ <div
+ class={cn(
+ 'pointer-events-none absolute top-0 bottom-0 border-l border-edge-muted',
+ props.newMessage && 'border-accent'
+ )}
+ style={{
+ left: 'var(--left-of-connector)',
+ }}
+ />
+ );
+}
diff --git a/js/app/packages/channel/Thread/ThreadRailDecorations.tsx b/js/app/packages/channel/Thread/ThreadRailDecorations.tsx
deleted file mode 100644
index 782b762eca..0000000000
--- a/js/app/packages/channel/Thread/ThreadRailDecorations.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import type { Accessor } from 'solid-js';
-import {
- getInnerRailBottom,
- innerRailTop,
- innerRailX,
- threadConnectorStyle,
-} from './utils/thread-rail-geometry';
-
-type ThreadRailDecorationsProps = {
- isReplying: Accessor<boolean>;
-};
-
-export function ThreadRailDecorations(props: ThreadRailDecorationsProps) {
- return (
- <>
- <div class="pointer-events-none absolute" style={threadConnectorStyle}>
- <div class="absolute text-edge-muted -z-1 w-full h-full">
- <svg
- xmlns="http://www.w3.org/2000/svg"
- fill="none"
- viewBox="0 0 24 18"
- width="100%"
- height="100%"
- >
- <path
- stroke="currentColor"
- vector-effect="non-scaling-stroke"
- d="M0 0.5 24 17.5"
- />
- </svg>
- </div>
- </div>
- <div
- class="pointer-events-none absolute bottom-0 -z-1 border-l border-edge-muted/80"
- style={{
- left: innerRailX,
- top: innerRailTop,
- bottom: getInnerRailBottom(props.isReplying()),
- }}
- />
- </>
- );
-}
diff --git a/js/app/packages/channel/Thread/ThreadReplyList.tsx b/js/app/packages/channel/Thread/ThreadReplyList.tsx
index 23062460ec..248db66b91 100644
--- a/js/app/packages/channel/Thread/ThreadReplyList.tsx
+++ b/js/app/packages/channel/Thread/ThreadReplyList.tsx
@@ -7,7 +7,9 @@ import {
import type { ApiThreadReply } from '@service-comms/client';
import { MarkMessaageNotifications } from '@notifications/components/MarkMessageNotifications';
import { buildThreadReplyListMeta } from './reply-list-meta';
+import { ThreadRail } from './ThreadRail';
import type { MessageEditor } from '../Channel/create-message-editor';
+import type { NewMessageCheckable } from '../Channel/util';
export function ThreadReplyList(props: {
channelId: string;
@@ -15,9 +17,10 @@ export function ThreadReplyList(props: {
replies: Array<ApiThreadReply>;
getMessageActions?: (message: MessageData) => MessageActions | undefined;
messageEditor?: MessageEditor;
+ isNewMessage?: (message: NewMessageCheckable) => boolean;
}) {
const listMetaByReplyId = createMemo(() =>
- buildThreadReplyListMeta(props.replies)
+ buildThreadReplyListMeta(props.replies, props.isNewMessage)
);
return (
@@ -29,18 +32,23 @@ export function ThreadReplyList(props: {
});
return (
- <MarkMessaageNotifications
- messageId={reply.id}
- channelId={props.channelId}
- >
- <ChannelMessage
- channelId={props.channelId}
- message={reply}
- actions={props.getMessageActions?.(replyMessage())}
- listMeta={listMetaByReplyId()[reply.id]}
- messageEditor={props.messageEditor}
+ <div class="relative">
+ <ThreadRail
+ newMessage={listMetaByReplyId()[reply.id].isNewMessage}
/>
- </MarkMessaageNotifications>
+ <MarkMessaageNotifications
+ messageId={reply.id}
+ channelId={props.channelId}
+ >
+ <ChannelMessage
+ channelId={props.channelId}
+ message={reply}
+ actions={props.getMessageActions?.(replyMessage())}
+ listMeta={listMetaByReplyId()[reply.id]}
+ messageEditor={props.messageEditor}
+ />
+ </MarkMessaageNotifications>
+ </div>
);
}}
</For>
diff --git a/js/app/packages/channel/Thread/ThreadReplyRailDecorations.tsx b/js/app/packages/channel/Thread/ThreadReplyRailDecorations.tsx
new file mode 100644
index 0000000000..58a1f02b3a
--- /dev/null
+++ b/js/app/packages/channel/Thread/ThreadReplyRailDecorations.tsx
@@ -0,0 +1,54 @@
+import { cn } from '@ui/utils/classname';
+import { type Accessor, Show } from 'solid-js';
+import {
+ getInnerRailBottom,
+ innerRailTop,
+ innerRailX,
+ threadConnectorStyle,
+} from './utils/thread-rail-geometry';
+
+type ThreadReplyRailProps = {
+ isReplying: Accessor<boolean>;
+ firstThreadReplyNewMessage?: boolean;
+};
+
+export function ThreadReplyRailDecorations(props: ThreadReplyRailProps) {
+ return (
+ <>
+ <div class="pointer-events-none absolute" style={threadConnectorStyle}>
+ <div
+ class={cn(
+ 'absolute text-edge-muted -z-1 w-full h-full',
+ props.firstThreadReplyNewMessage && 'text-accent'
+ )}
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 18"
+ width="100%"
+ height="100%"
+ >
+ <path
+ stroke="currentColor"
+ vector-effect="non-scaling-stroke"
+ d="M0 0.5 24 17.5"
+ />
+ </svg>
+ </div>
+ </div>
+ {/* THIS IS A HACKY ELEMENT POSITIONED TO BLOCK THE STUB END OF THE RAIL THAT POKE UP ABOVE THE USER ICON */}
+ <div class="pointer-events-none absolute bg-panel left-[calc(var(--left-of-connector)+var(--thread-shift))] top-0 min-h-[var(--message-padding)] min-w-4 -translate-x-1/2 z-1" />
+ <Show when={props.isReplying()}>
+ <div
+ class="pointer-events-none absolute bottom-0 -z-1 border-l border-[blue]"
+ style={{
+ left: innerRailX,
+ top: innerRailTop,
+ bottom: getInnerRailBottom(props.isReplying()),
+ }}
+ />
+ </Show>
+ </>
+ );
+}
diff --git a/js/app/packages/channel/Thread/ThreadRow.tsx b/js/app/packages/channel/Thread/ThreadRow.tsx
index de1f409e53..d80f74cde0 100644
--- a/js/app/packages/channel/Thread/ThreadRow.tsx
+++ b/js/app/packages/channel/Thread/ThreadRow.tsx
@@ -5,6 +5,7 @@ import {
NewDivider,
type ChannelMessageListMeta,
} from '../Message';
+import { ThreadRail } from './ThreadRail';
type ThreadRowProps = ParentProps & {
message: ApiChannelMessage;
@@ -16,12 +17,6 @@ export function ThreadRow(props: ThreadRowProps) {
return (
<div class="w-full flex justify-center">
<div class="macro-message-width w-full relative">
- <div
- class="pointer-events-none absolute top-0 bottom-0 border-l border-edge-muted/60"
- style={{
- left: 'var(--left-of-connector)',
- }}
- />
<NewDivider
listMeta={props.listMeta}
onDismiss={props.onDismissNewMessages}
@@ -30,7 +25,10 @@ export function ThreadRow(props: ThreadRowProps) {
createdAt={props.message.created_at}
listMeta={props.listMeta}
/>
- {props.children}
+ <div class="relative">
+ <ThreadRail newMessage={props.listMeta?.isNewMessage} />
+ {props.children}
+ </div>
</div>
</div>
);
diff --git a/js/app/packages/channel/Thread/reply-list-meta.ts b/js/app/packages/channel/Thread/reply-list-meta.ts
index bda1f81b94..92086031cb 100644
--- a/js/app/packages/channel/Thread/reply-list-meta.ts
+++ b/js/app/packages/channel/Thread/reply-list-meta.ts
@@ -1,16 +1,27 @@
import type { ApiThreadReply } from '@service-comms/client';
import type { ChannelMessageListMeta } from '../Message';
import { shouldGroupWithPreviousMessage } from '../Channel/message-grouping-meta';
+import type { NewMessageCheckable } from '../Channel/util';
export function buildThreadReplyListMeta(
- replies: ApiThreadReply[]
+ replies: ApiThreadReply[],
+ isNewMessageFn?: (message: NewMessageCheckable) => boolean
): Record<string, ChannelMessageListMeta> {
+ let foundFirstNewMessage = false;
+
return replies.reduce<Record<string, ChannelMessageListMeta>>(
(metaById, reply, index, items) => {
+ const isNewMessage = isNewMessageFn?.(reply) ?? false;
+ const isFirstNewMessage = isNewMessage && !foundFirstNewMessage;
+
+ if (isFirstNewMessage) {
+ foundFirstNewMessage = true;
+ }
+
metaById[reply.id] = {
index,
- isNewMessage: false,
- isFirstNewMessage: false,
+ isNewMessage,
+ isFirstNewMessage,
isGroupedWithPrevious: shouldGroupWithPreviousMessage(
reply,
items[index - 1]
diff --git a/js/app/packages/channel/Thread/types.ts b/js/app/packages/channel/Thread/types.ts
index e0140cb5b0..be26cd545e 100644
--- a/js/app/packages/channel/Thread/types.ts
+++ b/js/app/packages/channel/Thread/types.ts
@@ -7,6 +7,7 @@ import type {
import type { Accessor, Setter } from 'solid-js';
import type { InputSnapshot } from '@channel/Input';
import type { MessageEditor } from '@channel/Channel/create-message-editor';
+import type { NewMessageCheckable } from '@channel/Channel/util';
export type ThreadActions = {
onDismissNewMessages?: () => void;
@@ -33,4 +34,5 @@ export type ThreadProps = {
listMeta?: ChannelMessageListMeta;
threadActions?: ThreadActions;
messageEditor?: MessageEditor;
+ isNewMessage?: (reply: NewMessageCheckable) => boolean;
} & ThreadState;
diff --git a/js/app/packages/channel/activity-tracker.ts b/js/app/packages/channel/activity-tracker.ts
index 2d6068dad6..748b426982 100644
--- a/js/app/packages/channel/activity-tracker.ts
+++ b/js/app/packages/channel/activity-tracker.ts
@@ -1,13 +1,15 @@
import type { DateValue } from '@core/util/date';
-import type { ApiChannelMessage } from '@service-comms/client';
import { createMemo, createSignal, type Accessor } from 'solid-js';
-import { isNewMessage as isNewMessagePure } from './Channel/util';
+import {
+ isNewMessage as isNewMessagePure,
+ type NewMessageCheckable,
+} from './Channel/util';
-type ActivityTracker = {
+export type ActivityTracker = {
openedAt: Accessor<Date>;
newMessagesDismissed: Accessor<boolean>;
dismissNewMessages: () => void;
- isNewMessage: (message: ApiChannelMessage) => boolean;
+ isNewMessage: (message: NewMessageCheckable) => boolean;
};
type ActivityTrackerOptions = {
@@ -23,10 +25,17 @@ export function createActivityTracker(
const openedChannelAt = createMemo<Date>((prev) => prev ?? new Date());
- const isNewMessage = (message: ApiChannelMessage) =>
+ // Freeze lastViewedAt at the value present when the channel was first opened.
+ // This prevents a query refetch (triggered by the activity mutation on mount)
+ // from resetting viewed_at to "now" and hiding all the new-message indicators.
+ const frozenLastViewedAt = createMemo<DateValue | undefined | null>((prev) =>
+ prev !== undefined ? prev : props.lastViewedAt()
+ );
+
+ const isNewMessage = (message: NewMessageCheckable) =>
isNewMessagePure(message, {
dismissed: newMessagesDismissed(),
- lastViewedAt: props.lastViewedAt(),
+ lastViewedAt: frozenLastViewedAt(),
openedAt: openedChannelAt(),
userId: props.userId(),
});