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(email): advance to the next thread after send and mark done (#8229)

teo38820463f004
diff --git a/apps/web/src/features/block-email/component/useEmailThreadTools.tsx b/apps/web/src/features/block-email/component/useEmailThreadTools.tsx
index 778067c6f5..9b6f52f00a 100644
--- a/apps/web/src/features/block-email/component/useEmailThreadTools.tsx
+++ b/apps/web/src/features/block-email/component/useEmailThreadTools.tsx
@@ -112,7 +112,10 @@ export function useEmailThreadTools(props: EmailThreadToolsOptions) {
return;
}
if (props.listNavigation) {
- props.listNavigation.markDone(emailCtx.archiveThread);
+ fireAndForget(
+ props.listNavigation.markDone(emailCtx.archiveThread),
+ 'email-thread-tools'
+ );
return;
}
// Prefer the active Mark done command so it drives soup navigation and
diff --git a/apps/web/src/features/block-email/use-email-list-navigation.test.ts b/apps/web/src/features/block-email/use-email-list-navigation.test.ts
index ad0e07fd3c..3d1e0dbc1b 100644
--- a/apps/web/src/features/block-email/use-email-list-navigation.test.ts
+++ b/apps/web/src/features/block-email/use-email-list-navigation.test.ts
@@ -86,17 +86,18 @@ beforeEach(() => {
});
describe('email list navigation adapter', () => {
- it('finds the source list when native navigation gives the email a new split', () => {
+ it('finds the source list when native navigation gives the email a new split', async () => {
mocks.handle.id = 'native-detail';
const [nav, dispose] = createRoot(
(dispose) => [createNavigation(() => 'a'), dispose] as const
);
expect(nav.canNext()).toBe(true);
- nav.markDone(() => true);
+ const marked = nav.markDone(() => true);
expect(mocks.open).toHaveBeenCalledWith(
expect.objectContaining({ id: 'b' }),
expect.objectContaining({ splitHandle: mocks.handle, mergeHistory: true })
);
+ await marked;
dispose();
mocks.handle.id = 'email-split';
});
@@ -120,7 +121,7 @@ describe('email list navigation adapter', () => {
(dispose) => [createNavigation(() => 'b'), dispose] as const
);
const archive = vi.fn(() => true);
- nav[action](archive);
+ const stepped = nav[action](archive);
await vi.waitFor(() => expect(mocks.open).toHaveBeenCalledOnce());
expect(mocks.loadMore).toHaveBeenCalledTimes(3);
expect(mocks.open).toHaveBeenCalledWith(
@@ -128,6 +129,7 @@ describe('email list navigation adapter', () => {
expect.anything()
);
expect(archive).toHaveBeenCalledTimes(action === 'markDone' ? 1 : 0);
+ await stepped;
dispose();
}
);
@@ -144,7 +146,7 @@ describe('email list navigation adapter', () => {
(dispose) => [createNavigation(() => 'b'), dispose] as const
);
const archive = vi.fn(() => true);
- nav.markDone(archive);
+ const marked = nav.markDone(archive);
if (leave === 'dispose') dispose();
else mocks.active = false;
mocks.rows.push({ id: 'c', type: 'email' });
@@ -153,6 +155,7 @@ describe('email list navigation adapter', () => {
await vi.waitFor(() => expect(nav.canPrevious()).toBe(true));
expect(archive).not.toHaveBeenCalled();
expect(mocks.open).not.toHaveBeenCalled();
+ expect(await marked).toBe(false);
dispose();
}
);
@@ -164,11 +167,12 @@ describe('email list navigation adapter', () => {
(dispose) => [createNavigation(() => 'b'), dispose] as const
);
const archive = vi.fn(() => true);
- nav.markDone(archive);
+ const marked = nav.markDone(archive);
await vi.waitFor(() => expect(nav.canPrevious()).toBe(true));
expect(mocks.loadMore).toHaveBeenCalledOnce();
expect(archive).not.toHaveBeenCalled();
expect(mocks.open).not.toHaveBeenCalled();
+ expect(await marked).toBe(false);
dispose();
});
@@ -231,8 +235,9 @@ describe('email list navigation adapter', () => {
return true;
});
- nav.markDone(archive);
+ const marked = nav.markDone(archive);
await vi.waitFor(() => expect(mocks.open).toHaveBeenCalledOnce());
+ expect(await marked).toBe(true);
expect(archive).toHaveBeenCalledOnce();
expect(mocks.open).toHaveBeenLastCalledWith(
expect.objectContaining({ id: 'b' }),
@@ -262,8 +267,9 @@ describe('email list navigation adapter', () => {
return true;
});
- nav.markDone(archive);
- nav.markDone(archive);
+ const first = nav.markDone(archive);
+ const repeated = nav.markDone(archive);
+ expect(await repeated).toBe(false);
expect(archive).not.toHaveBeenCalled();
expect(mocks.loadMore).toHaveBeenCalledOnce();
mocks.rows.push({ id: 'c', type: 'email' });
@@ -271,6 +277,7 @@ describe('email list navigation adapter', () => {
finishLoading();
await vi.waitFor(() => expect(mocks.open).toHaveBeenCalledOnce());
+ expect(await first).toBe(true);
expect(archive).toHaveBeenCalledOnce();
expect(mocks.open).toHaveBeenCalledWith(
expect.objectContaining({ id: 'c' }),
@@ -283,40 +290,43 @@ describe('email list navigation adapter', () => {
const [nav, dispose] = createRoot(
(dispose) => [createNavigation(() => 'b'), dispose] as const
);
- nav.markDone(() => true);
+ const marked = nav.markDone(() => true);
await vi.waitFor(() =>
expect(mocks.open).toHaveBeenCalledWith(
expect.objectContaining({ id: 'a' }),
expect.anything()
)
);
+ expect(await marked).toBe(true);
dispose();
});
it.each(['missing', 'a'])(
'archives without navigating when %s has no neighboring email',
- (id) => {
+ async (id) => {
mocks.rows = [{ id: 'a', type: 'email' }];
const [nav, dispose] = createRoot(
(dispose) => [createNavigation(() => id), dispose] as const
);
const archive = vi.fn(() => true);
- nav.markDone(archive);
+ const marked = nav.markDone(archive);
expect(archive).toHaveBeenCalledWith({
navigate: false,
navigateBack: undefined,
});
expect(mocks.open).not.toHaveBeenCalled();
+ expect(await marked).toBe(true);
dispose();
}
);
- it('does not advance when the archive command rejects the action', () => {
+ it('does not advance when the archive command rejects the action', async () => {
const [nav, dispose] = createRoot(
(dispose) => [createNavigation(() => 'a'), dispose] as const
);
- nav.markDone(() => false);
+ const marked = nav.markDone(() => false);
expect(mocks.open).not.toHaveBeenCalled();
+ expect(await marked).toBe(false);
dispose();
});
@@ -331,10 +341,11 @@ describe('email list navigation adapter', () => {
(dispose) => [createNavigation(() => currentId), dispose] as const
);
const archive = vi.fn(() => true);
- nav.markDone(archive);
+ const marked = nav.markDone(archive);
await vi.waitFor(() => expect(nav.canPrevious()).toBe(true));
expect(archive).not.toHaveBeenCalled();
expect(mocks.open).not.toHaveBeenCalled();
+ expect(await marked).toBe(false);
dispose();
});
});
diff --git a/apps/web/src/features/block-email/use-email-list-navigation.ts b/apps/web/src/features/block-email/use-email-list-navigation.ts
index 724c3061c6..5e94ee1122 100644
--- a/apps/web/src/features/block-email/use-email-list-navigation.ts
+++ b/apps/web/src/features/block-email/use-email-list-navigation.ts
@@ -86,11 +86,12 @@ export function useEmailListNavigation(
toast.failure('Unable to open the next or previous email');
}
};
+ /** Resolves whether it archived the thread through `archiveThread`. */
const navigate = async (
direction: -1 | 1,
archiveThread?: EmailThreadCommands['archiveThread']
- ) => {
- if (!panel || disposed || navigating()) return;
+ ): Promise<boolean> => {
+ if (!panel || disposed || navigating()) return false;
setNavigating(true);
const currentId = threadId();
const current = entities().find(
@@ -108,30 +109,30 @@ export function useEmailListNavigation(
try {
while (direction === 1 && !target(direction) && canLoadNext()) {
await list?.loadMore();
- if (!isCurrent()) return;
+ if (!isCurrent()) return false;
}
- if (!isCurrent()) return;
+ if (!isCurrent()) return false;
// Capture the destination before archiving removes the current list row.
// At the end of the list, triage falls back to the previous email.
const next =
target(direction) ?? (archiveThread ? target(-1) : undefined);
- if (
- archiveThread &&
- !archiveThread({
+ const archived =
+ !!archiveThread &&
+ archiveThread({
navigate: false,
navigateBack:
current && next
? () =>
fireAndForget(open(current, referredFrom), 'email-navigation')
: undefined,
- })
- )
- return;
- if (!next) return;
- await open(next, referredFrom);
+ });
+ if (archiveThread && !archived) return false;
+ if (next) await open(next, referredFrom);
+ return archived;
} catch {
if (isCurrent())
toast.failure('Unable to open the next or previous email');
+ return false;
} finally {
setNavigating(false);
}
@@ -145,8 +146,9 @@ export function useEmailListNavigation(
next: () => {
fireAndForget(navigate(1), 'email-navigation');
},
- markDone: (archiveThread) => {
- fireAndForget(navigate(1, archiveThread), 'email-navigation');
+ markDone: async (archiveThread, requested) => {
+ if (requested !== undefined && requested !== threadId()) return false;
+ return navigate(1, archiveThread);
},
};
}
diff --git a/apps/web/src/features/email-compose/primitives/reply-composer.ts b/apps/web/src/features/email-compose/primitives/reply-composer.ts
index c31015c30a..30dceb7650 100644
--- a/apps/web/src/features/email-compose/primitives/reply-composer.ts
+++ b/apps/web/src/features/email-compose/primitives/reply-composer.ts
@@ -140,6 +140,8 @@ export type ReplyComposerOptions = {
onUndoHandle?: (handle: EmailUndoHandle) => void;
/** False keeps the view on this thread instead of opening the next one. */
navigate?: boolean;
+ /** True once the send was undone; marking done may still be pending. */
+ cancelled?: () => boolean;
}) => void;
setShowReply?: Setter<boolean>;
/** Reopens this reply's thread when the composer is no longer on screen. */
@@ -1132,12 +1134,16 @@ export function createReplyComposer(
// Each undo action retains this send's inbox, thread and mark-done, even
// if the composer sends again or navigation disposes the view.
let markDoneUndoHandle: EmailUndoHandle | undefined;
+ // Advancing may archive after a page loads; an undo before then must
+ // not leave the restored thread marked done.
+ let sendUndone = false;
const undoSend = (draftId: string) =>
props.delivery.undoSend({
threadId: result.threadId,
draftId,
inboxId,
onUndone: async () => {
+ sendUndone = true;
await restoreAfterUndoSend(draftId, result.threadId, inboxId);
const doneHandle = markDoneUndoHandle;
markDoneUndoHandle = undefined;
@@ -1177,13 +1183,15 @@ export function createReplyComposer(
}
if (willMarkDone) {
try {
- // Sending a reply stays on the thread; explicit Mark done advances.
+ // A plain send stays on the thread; Send and mark done advances to
+ // the next thread, like Mark done.
props.onMarkDone?.({
silent: true,
onUndoHandle: (handle) => {
markDoneUndoHandle = handle;
},
- navigate: false,
+ navigate: markDone,
+ cancelled: () => sendUndone,
});
} catch (error) {
props.notices.reportError(error);
diff --git a/apps/web/src/features/email-compose/primitives/send-schedule.test.ts b/apps/web/src/features/email-compose/primitives/send-schedule.test.ts
index 4ca6a69521..740f7f9d3e 100644
--- a/apps/web/src/features/email-compose/primitives/send-schedule.test.ts
+++ b/apps/web/src/features/email-compose/primitives/send-schedule.test.ts
@@ -583,8 +583,9 @@ describe('send and schedule ordering', () => {
.mocked(composeContext.notices.feedback.success)
.mock.calls.find(([text]) => text === 'Email sent');
expect(onMarkDone).toHaveBeenCalledOnce();
+ // Send and mark done moves on to the next thread, like Mark done.
expect(onMarkDone).toHaveBeenCalledWith(
- expect.objectContaining({ silent: true, navigate: false })
+ expect.objectContaining({ silent: true, navigate: true })
);
sentNotice?.[1]?.actions?.[0].onClick();
await vi.advanceTimersByTimeAsync(0);
@@ -853,6 +854,26 @@ describe('send and schedule ordering', () => {
newer.dispose();
}
});
+ it('stays on the thread after a plain reply in the inbox', async () => {
+ const composeContext = createComposeContext();
+ const onMarkDone = vi.fn();
+ const state = mountReplyComposer(
+ composeContext,
+ undefined,
+ { onMarkDone },
+ { inboxVisible: true }
+ );
+ try {
+ await state.sendEmail();
+ // Replying files the thread away, but the reader keeps it open.
+ expect(onMarkDone).toHaveBeenCalledWith(
+ expect.objectContaining({ silent: true, navigate: false })
+ );
+ } finally {
+ state.dispose();
+ }
+ });
+
it('completes reply mark-done when the post-send refresh fails', async () => {
const composeContext = createComposeContext();
const failure = new Error('Refresh failed');
diff --git a/apps/web/src/features/email-thread/context/email-thread-context.ts b/apps/web/src/features/email-thread/context/email-thread-context.ts
index 02f8f607ea..efba2b34b2 100644
--- a/apps/web/src/features/email-thread/context/email-thread-context.ts
+++ b/apps/web/src/features/email-thread/context/email-thread-context.ts
@@ -21,6 +21,8 @@ export interface ArchiveThreadOptions {
/** Disable automatic list navigation when the host handles it. */
navigate?: boolean;
navigateBack?: () => void;
+ /** Checked just before archiving; a send undone first is not marked done. */
+ cancelled?: () => boolean;
}
/** Domain snapshots and request progress; query keys and cursors stay in the adapter. */
@@ -66,7 +68,15 @@ export interface EmailThreadListNavigation {
previous(): void;
next(): void;
afterReminderSaved?(): Promise<void>;
- markDone(archiveThread: EmailThreadCommands['archiveThread']): void;
+ /**
+ * Archives through `archiveThread` and opens the next email. With
+ * `threadId`, only while that thread is the open one. Resolves whether it
+ * archived: false when the host was busy, closed, or showing another thread.
+ */
+ markDone(
+ archiveThread: EmailThreadCommands['archiveThread'],
+ threadId?: string
+ ): Promise<boolean>;
}
/** Host behavior is optional. A thread can render without a block or router. */
diff --git a/apps/web/src/features/email-thread/primitives/email-thread-state.test.ts b/apps/web/src/features/email-thread/primitives/email-thread-state.test.ts
index c2dfd608a6..2fe6bc656d 100644
--- a/apps/web/src/features/email-thread/primitives/email-thread-state.test.ts
+++ b/apps/web/src/features/email-thread/primitives/email-thread-state.test.ts
@@ -1,10 +1,109 @@
import { createRoot, createSignal } from 'solid-js';
-import { describe, expect, it } from 'vitest';
+import { describe, expect, it, vi } from 'vitest';
+import type { ArchiveThreadOptions } from '../context/email-thread-context';
import type { EmailThread } from '../core/email-thread';
import { createThreadContext, message, thread } from '../tests/fixtures';
import { createEmailThreadState } from './email-thread-state';
describe('thread state with an injected source', () => {
+ function advancingState(
+ markDone: (
+ archive: (options?: ArchiveThreadOptions) => boolean,
+ threadId?: string
+ ) => Promise<boolean>
+ ) {
+ const archiveThread = vi.fn((_options?: ArchiveThreadOptions) => true);
+ const context = createThreadContext({
+ thread: () => thread([message('last')]),
+ });
+ const state = createEmailThreadState(
+ {
+ ...context,
+ createCommands: (snapshot) => ({
+ ...context.createCommands(snapshot),
+ archiveThread,
+ }),
+ },
+ {
+ listNavigation: {
+ canNext: () => true,
+ canPrevious: () => false,
+ next() {},
+ previous() {},
+ markDone,
+ },
+ }
+ );
+ return { state, archiveThread };
+ }
+
+ it('archives through the host list so done-and-advance keeps its undo', () =>
+ createRoot(async (dispose) => {
+ try {
+ const markDone = vi.fn(
+ async (
+ archive: (options?: ArchiveThreadOptions) => boolean,
+ _threadId?: string
+ ) =>
+ // The host picks the next thread and archives without its own
+ // navigation, as Email's list navigation does.
+ archive({ navigate: false, nextEntityId: 'next' })
+ );
+ const { state, archiveThread } = advancingState(markDone);
+ const onUndoHandle = vi.fn();
+ expect(
+ state.archiveThreadAndAdvance({
+ silent: true,
+ onUndoHandle,
+ navigate: true,
+ })
+ ).toBe(true);
+ await vi.waitFor(() => expect(archiveThread).toHaveBeenCalledOnce());
+ expect(archiveThread).toHaveBeenCalledWith({
+ silent: true,
+ onUndoHandle,
+ navigate: false,
+ nextEntityId: 'next',
+ });
+ // It asks to advance only from the thread it shows.
+ expect(markDone.mock.calls[0][1]).toBe(thread([message('last')]).db_id);
+ } finally {
+ dispose();
+ }
+ }));
+
+ it('marks the thread done in place when the host has moved on', () =>
+ createRoot(async (dispose) => {
+ try {
+ // The send resolved after the user opened another thread.
+ const { state, archiveThread } = advancingState(async () => false);
+ state.archiveThreadAndAdvance({ silent: true, navigate: true });
+ await vi.waitFor(() => expect(archiveThread).toHaveBeenCalledOnce());
+ expect(archiveThread).toHaveBeenCalledWith(
+ expect.objectContaining({ silent: true, navigate: false })
+ );
+ } finally {
+ dispose();
+ }
+ }));
+
+ it('does not mark done a send that was undone first', () =>
+ createRoot(async (dispose) => {
+ try {
+ const { state, archiveThread } = advancingState(async (archive) =>
+ archive({ navigate: false })
+ );
+ state.archiveThreadAndAdvance({
+ navigate: true,
+ cancelled: () => true,
+ });
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(archiveThread).not.toHaveBeenCalled();
+ } finally {
+ dispose();
+ }
+ }));
+
it('does not move an open bottom reply to a newly sent message', () =>
createRoot((dispose) => {
try {
diff --git a/apps/web/src/features/email-thread/primitives/email-thread-state.ts b/apps/web/src/features/email-thread/primitives/email-thread-state.ts
index 26c088aa60..4fe6152067 100644
--- a/apps/web/src/features/email-thread/primitives/email-thread-state.ts
+++ b/apps/web/src/features/email-thread/primitives/email-thread-state.ts
@@ -1,3 +1,4 @@
+import { fireAndForget } from '@core/util/fireAndForget';
import type { Accessor } from 'solid-js';
import { createEffect, createMemo, createSignal, on } from 'solid-js';
import { createStore } from 'solid-js/store';
@@ -87,6 +88,8 @@ export type EmailThreadState = {
};
archiveThread: (opts?: ArchiveThreadOptions) => boolean;
+ /** Marks the thread done and opens the next one in the host's list. */
+ archiveThreadAndAdvance: (opts?: ArchiveThreadOptions) => boolean;
/** True when the thread is archived, i.e. currently marked done. */
isThreadDone: Accessor<boolean>;
/** True when the done state can actually be reversed — see
@@ -241,13 +244,39 @@ export function createEmailThreadState(
);
};
+ const commands = threadContext.createCommands(threadSnapshot);
+ const archiveUnlessCancelled = (opts?: ArchiveThreadOptions) =>
+ !opts?.cancelled?.() && commands.archiveThread(opts);
+ // A send resolves after a round trip; by then the user may have moved on.
+ // The host advances only from this thread; otherwise it is marked done
+ // where it is.
+ const advanceFrom = async (
+ navigation: NonNullable<typeof host.listNavigation>,
+ threadId: string,
+ opts?: ArchiveThreadOptions
+ ) => {
+ const archived = await navigation.markDone(
+ (step) => archiveUnlessCancelled({ ...opts, ...step }),
+ threadId
+ );
+ if (!archived) archiveUnlessCancelled({ ...opts, navigate: false });
+ };
+ const archiveThreadAndAdvance = (opts?: ArchiveThreadOptions) => {
+ const navigation = host.listNavigation;
+ const threadId = threadContext.source.id();
+ if (!navigation || !threadId) return archiveUnlessCancelled(opts);
+ fireAndForget(advanceFrom(navigation, threadId, opts), 'email-thread');
+ return true;
+ };
+
return {
registerMessagesList: setMessagesListRef,
registerMessagesContainer: setMessagesContainerRef,
thread: selected,
recipientOptions: recipients.options,
onRecipientsChange: recipients.add,
- ...threadContext.createCommands(threadSnapshot),
+ ...commands,
+ archiveThreadAndAdvance,
messagesContainerRef,
messagesListRef,
query: {
diff --git a/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts b/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts
index 20b90dddf6..7808663fc1 100644
--- a/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts
+++ b/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts
@@ -117,7 +117,7 @@ it('delegates keyboard mark done to host list navigation', () => {
try {
expect(state.handlers()?.markDone()).toBe(true);
- expect(markDone).toHaveBeenCalledWith(state.context.archiveThread);
+ expect(markDone).toHaveBeenCalledOnce();
} finally {
state.dispose();
}
diff --git a/apps/web/src/features/email-thread/primitives/thread-navigation.ts b/apps/web/src/features/email-thread/primitives/thread-navigation.ts
index b8d96219fc..a704bf1cc3 100644
--- a/apps/web/src/features/email-thread/primitives/thread-navigation.ts
+++ b/apps/web/src/features/email-thread/primitives/thread-navigation.ts
@@ -594,11 +594,7 @@ export function createThreadNavigation(
}
return true;
};
- const markDone = () => {
- if (!host.listNavigation) return context.archiveThread();
- host.listNavigation.markDone(context.archiveThread);
- return true;
- };
+ const markDone = () => context.archiveThreadAndAdvance();
onMount(() =>
host.registerKeyboard?.({
replyToFocusedMessage: () => openHotkeyTarget('reply-all'),
diff --git a/apps/web/src/features/email-thread/views/bottom-reply-buttons.tsx b/apps/web/src/features/email-thread/views/bottom-reply-buttons.tsx
index 9002a74605..7d207a0de6 100644
--- a/apps/web/src/features/email-thread/views/bottom-reply-buttons.tsx
+++ b/apps/web/src/features/email-thread/views/bottom-reply-buttons.tsx
@@ -3,6 +3,7 @@ import type { EmailMessage } from '@app/features/email-message/core/email-messag
import { FloatRegionOrInline } from '@components/app/mobile/float-regions/FloatRegion';
import { inboxIconProps } from '@core/component/inboxIcon';
import { UserIcon } from '@core/component/UserIcon';
+import { fireAndForget } from '@core/util/fireAndForget';
import ArrowBendUpLeft from '@phosphor/arrow-bend-up-left.svg';
import ArrowBendUpRight from '@phosphor/arrow-bend-up-right.svg';
import ArrowDown from '@phosphor/arrow-down.svg';
@@ -88,7 +89,10 @@ export function BottomReplyButtons(props: {
if (isDone()) {
ctx.markThreadNotDone();
} else if (props.navigation) {
- props.navigation.markDone(ctx.archiveThread);
+ fireAndForget(
+ props.navigation.markDone(ctx.archiveThread),
+ 'email-thread'
+ );
} else {
ctx.archiveThread();
}
diff --git a/apps/web/src/features/email-thread/views/thread-reply-input.tsx b/apps/web/src/features/email-thread/views/thread-reply-input.tsx
index d2846816ef..01cc5a2de8 100644
--- a/apps/web/src/features/email-thread/views/thread-reply-input.tsx
+++ b/apps/web/src/features/email-thread/views/thread-reply-input.tsx
@@ -153,7 +153,11 @@ function ThreadReplyInputSession(props: ThreadReplyInputProps) {
formSeed={seed}
onEngaged={() => setEngaged(true)}
sideEffectOnSend={afterSend}
- onMarkDone={ctx.archiveThread}
+ onMarkDone={(options) =>
+ options?.navigate
+ ? ctx.archiveThreadAndAdvance(options)
+ : ctx.archiveThread(options)
+ }
setShowReply={props.setShowReply}
markdownDomRef={props.markdownDomRef}
unframed={props.unframed}
diff --git a/apps/web/src/features/email-view/use-email-detail-list-navigation.ts b/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
index 3d9dcab11f..ba924f7525 100644
--- a/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
+++ b/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
@@ -7,7 +7,6 @@ import type {
EmailThreadListNavigation,
} from '@app/features/email-thread/context/email-thread-context';
import { toast } from '@core/component/Toast/Toast';
-import { fireAndForget } from '@core/util/fireAndForget';
import type { EntityData } from '@entity';
import type { Accessor } from 'solid-js';
import { useEmailView } from './email-view-context';
@@ -52,24 +51,29 @@ export function useEmailDetailListNavigation(
...navigation,
// A saved reminder hides the thread; navigation follows its old position.
afterReminderSaved: () => navigation.navigate(1, { fallbackDirection: -1 }),
- markDone: (archiveThread: EmailThreadCommands['archiveThread']) => {
- fireAndForget(
- navigation.navigate(1, {
- fallbackDirection: -1,
- beforeOpen: (next, current) =>
- archiveThread({
- navigate: false,
- nextEntityId: next?.id,
- navigateBack:
- current && next
- ? () => {
- navigation.open(current);
- }
- : undefined,
- }),
- }),
- 'email-view'
- );
+ markDone: async (
+ archiveThread: EmailThreadCommands['archiveThread'],
+ requested?: string
+ ) => {
+ if (requested !== undefined && requested !== threadId()) return false;
+ let archived = false;
+ await navigation.navigate(1, {
+ fallbackDirection: -1,
+ beforeOpen: (next, current) => {
+ archived = archiveThread({
+ navigate: false,
+ nextEntityId: next?.id,
+ navigateBack:
+ current && next
+ ? () => {
+ navigation.open(current);
+ }
+ : undefined,
+ });
+ return archived;
+ },
+ });
+ return archived;
},
};
}
diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.md
index a79797f352..d61c3deaf0 100644
--- a/docs/agent-guide/email.md
+++ b/docs/agent-guide/email.md
@@ -502,8 +502,12 @@ Macro Markdown messages retain document mentions. Ordinary HTML bodies use an
open shadow root: Playwright text locators can reach them, but a card's ordinary
`innerText` or `querySelector` does not traverse that root.
-Sending a reply from an inbox thread marks that thread done but stays on it;
-only the explicit Mark done action opens the next email.
+Sending a reply from an inbox thread marks that thread done but stays on it.
+Send and mark done (Shift+Cmd+Enter) and Mark done open the next email, counted
+from where the thread sat when it was opened (a reply draft lifts its thread to
+the top of Signal while it is written). If the user has already moved to
+another thread when the send finishes, the replied thread is marked done
+without navigating; Undo before then leaves it in the inbox.
Sending a message shows it in the open thread immediately, while delivery is
still pending. It stays visible until the thread refresh confirms it, with no
duplicate message. Failed delivery removes that message and restores the reply