Skip to content

Commit 0109670

Browse files
t3dotggclaude
andauthored
feat(threads): add per-thread auto-settle switch (#11846)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d5d4874 commit 0109670

42 files changed

Lines changed: 862 additions & 11 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/electron/ElectronMenu.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextM
8080
destructive: sourceItem.destructive === true,
8181
disabled: sourceItem.disabled === true,
8282
...(sourceItem.separatorBefore === true ? { separatorBefore: true } : {}),
83+
...(typeof sourceItem.checked === "boolean" ? { checked: sourceItem.checked } : {}),
8384
};
8485

8586
if (sourceItem.children) {
@@ -168,6 +169,7 @@ export const make = Effect.gen(function* () {
168169
const itemOption: Electron.MenuItemConstructorOptions = {
169170
label: item.label,
170171
enabled: !item.disabled,
172+
...(typeof item.checked === "boolean" ? { type: "checkbox", checked: item.checked } : {}),
171173
};
172174
if (item.children && item.children.length > 0) {
173175
itemOption.submenu = buildTemplate(item.children, complete);

‎apps/mobile/src/components/AppSymbol.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
140140
"checkmark.circle": IconCircleCheck,
141141
circle: IconCircle,
142142
clock: IconClock,
143+
timer: IconClock,
143144
ticket: IconTicket,
144145
cloud: IconCloud,
145146
cube: IconBox,

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function HomeRouteScreen() {
4949
unsnoozeThread,
5050
pinThread,
5151
unpinThread,
52+
setThreadAutoSettle,
5253
moveThread,
5354
renameThread,
5455
regenerateThreadTitle,
@@ -206,6 +207,7 @@ export function HomeRouteScreen() {
206207
onUnsettleThread={unsettleThread}
207208
onPinThread={pinThread}
208209
onUnpinThread={unpinThread}
210+
onSetThreadAutoSettle={setThreadAutoSettle}
209211
onMoveThread={moveThread}
210212
onRenameThread={renameThread}
211213
onRegenerateThreadTitle={regenerateThreadTitle}

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ interface HomeScreenProps {
9696
readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
9797
readonly onPinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
9898
readonly onUnpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
99+
readonly onSetThreadAutoSettle: (
100+
thread: EnvironmentThreadShell,
101+
enabled: boolean,
102+
) => Promise<boolean>;
99103
readonly onMoveThread: (
100104
thread: EnvironmentThreadShell,
101105
direction: ThreadMoveDestination,
@@ -378,6 +382,12 @@ export function HomeScreen(props: HomeScreenProps) {
378382
},
379383
[props.onUnpinThread],
380384
);
385+
const handleSetThreadAutoSettle = useCallback(
386+
(thread: EnvironmentThreadShell, enabled: boolean) => {
387+
void props.onSetThreadAutoSettle(thread, enabled);
388+
},
389+
[props.onSetThreadAutoSettle],
390+
);
381391
const handleRegenerateThreadTitle = useCallback(
382392
(thread: EnvironmentThreadShell) => {
383393
void props.onRegenerateThreadTitle(thread);
@@ -456,6 +466,15 @@ export function HomeScreen(props: HomeScreenProps) {
456466
}
457467
return supported;
458468
}, [serverConfigs]);
469+
const autoSettleOptOutEnvironmentIds = useMemo(() => {
470+
const supported = new Set<EnvironmentId>();
471+
for (const [environmentId, config] of serverConfigs) {
472+
if (config.environment.capabilities.threadAutoSettleOptOut === true) {
473+
supported.add(environmentId);
474+
}
475+
}
476+
return supported;
477+
}, [serverConfigs]);
459478
const pinReorderEnvironmentIds = useMemo(() => {
460479
const supported = new Set<EnvironmentId>();
461480
for (const [environmentId, config] of serverConfigs) {
@@ -726,6 +745,7 @@ export function HomeScreen(props: HomeScreenProps) {
726745
onSettleThread={handleSettleThread}
727746
snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
728747
pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
748+
autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
729749
reorderSupported={
730750
item.item.pinned
731751
? pinReorderEnvironmentIds.has(thread.environmentId)
@@ -738,6 +758,7 @@ export function HomeScreen(props: HomeScreenProps) {
738758
onUnsettleThread={handleUnsettleThread}
739759
onPinThread={handlePinThread}
740760
onUnpinThread={handleUnpinThread}
761+
onSetThreadAutoSettle={handleSetThreadAutoSettle}
741762
onMoveThread={handleMoveThread}
742763
onSwipeableClose={handleSwipeableClose}
743764
onSwipeableWillOpen={handleSwipeableWillOpen}
@@ -758,6 +779,8 @@ export function HomeScreen(props: HomeScreenProps) {
758779
handleSwipeableClose,
759780
handleSwipeableWillOpen,
760781
handleUnsettleThread,
782+
handleSetThreadAutoSettle,
783+
autoSettleOptOutEnvironmentIds,
761784
pinningEnvironmentIds,
762785
machineByEnvironmentId,
763786
pinReorderEnvironmentIds,

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ function environmentSupportsPinReorder(environmentId: EnvironmentThreadShell["en
5959
);
6060
}
6161

62+
function environmentSupportsAutoSettleOptOut(
63+
environmentId: EnvironmentThreadShell["environmentId"],
64+
) {
65+
return (
66+
appAtomRegistry.get(environmentServerConfigsAtom).get(environmentId)?.environment.capabilities
67+
.threadAutoSettleOptOut === true
68+
);
69+
}
70+
6271
function environmentSupportsTitleRegeneration(
6372
environmentId: EnvironmentThreadShell["environmentId"],
6473
) {
@@ -237,6 +246,11 @@ export function useThreadListActions(): {
237246
readonly unsettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
238247
readonly pinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
239248
readonly unpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
249+
/** Sets per-thread automatic settlement on or off. */
250+
readonly setThreadAutoSettle: (
251+
thread: EnvironmentThreadShell,
252+
enabled: boolean,
253+
) => Promise<boolean>;
240254
readonly moveThread: (
241255
thread: EnvironmentThreadShell,
242256
direction: ThreadMoveDestination,
@@ -249,6 +263,9 @@ export function useThreadListActions(): {
249263
const unsnoozeMutation = useAtomCommand(threadEnvironment.unsnooze, { reportFailure: false });
250264
const pinMutation = useAtomCommand(threadEnvironment.pin, { reportFailure: false });
251265
const unpinMutation = useAtomCommand(threadEnvironment.unpin, { reportFailure: false });
266+
const setAutoSettleMutation = useAtomCommand(threadEnvironment.setAutoSettle, {
267+
reportFailure: false,
268+
});
252269
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
253270
reportFailure: false,
254271
});
@@ -435,6 +452,34 @@ export function useThreadListActions(): {
435452
},
436453
[unpinMutation],
437454
);
455+
const setThreadAutoSettle = useCallback(
456+
async (thread: EnvironmentThreadShell, enabled: boolean) => {
457+
if (!environmentSupportsAutoSettleOptOut(thread.environmentId)) {
458+
Alert.alert(
459+
"Could not update auto-settle",
460+
"This environment's server does not support turning auto-settle off per thread yet. Update the server to use it.",
461+
);
462+
return false;
463+
}
464+
selectionHaptic();
465+
const result = await setAutoSettleMutation({
466+
environmentId: thread.environmentId,
467+
input: { threadId: thread.id, enabled },
468+
});
469+
if (result._tag === "Failure") {
470+
const error = Cause.squash(result.cause);
471+
Alert.alert(
472+
"Could not update auto-settle",
473+
error instanceof Error && error.message.trim().length > 0
474+
? error.message
475+
: "The auto-settle setting could not be changed.",
476+
);
477+
return false;
478+
}
479+
return true;
480+
},
481+
[setAutoSettleMutation],
482+
);
438483
const regenerateThreadTitle = useCallback(
439484
async (thread: EnvironmentThreadShell) => {
440485
const key = scopedThreadKey(thread.environmentId, thread.id);
@@ -698,6 +743,7 @@ export function useThreadListActions(): {
698743
unsettleThread,
699744
pinThread,
700745
unpinThread,
746+
setThreadAutoSettle,
701747
moveThread,
702748
renameThread,
703749
regenerateThreadTitle,

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function ThreadNavigationSidebarPane(
150150
unsettleThread,
151151
pinThread,
152152
unpinThread,
153+
setThreadAutoSettle,
153154
moveThread,
154155
renameThread,
155156
regenerateThreadTitle,
@@ -334,6 +335,15 @@ function ThreadNavigationSidebarPane(
334335
}
335336
return supported;
336337
}, [serverConfigs]);
338+
const autoSettleOptOutEnvironmentIds = useMemo(() => {
339+
const supported = new Set<EnvironmentId>();
340+
for (const [environmentId, config] of serverConfigs) {
341+
if (config.environment.capabilities.threadAutoSettleOptOut === true) {
342+
supported.add(environmentId);
343+
}
344+
}
345+
return supported;
346+
}, [serverConfigs]);
337347
const pinReorderEnvironmentIds = useMemo(() => {
338348
const supported = new Set<EnvironmentId>();
339349
for (const [environmentId, config] of serverConfigs) {
@@ -766,6 +776,7 @@ function ThreadNavigationSidebarPane(
766776
onSettleThread={settleThread}
767777
snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
768778
pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
779+
autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
769780
reorderSupported={
770781
item.item.pinned
771782
? pinReorderEnvironmentIds.has(thread.environmentId)
@@ -778,6 +789,7 @@ function ThreadNavigationSidebarPane(
778789
onUnsettleThread={unsettleThread}
779790
onPinThread={pinThread}
780791
onUnpinThread={unpinThread}
792+
onSetThreadAutoSettle={setThreadAutoSettle}
781793
onMoveThread={moveThread}
782794
onSwipeableClose={handleSwipeableClose}
783795
onSwipeableWillOpen={handleSwipeableWillOpen}
@@ -829,6 +841,8 @@ function ThreadNavigationSidebarPane(
829841
pinReorderEnvironmentIds,
830842
pinThread,
831843
pinningEnvironmentIds,
844+
autoSettleOptOutEnvironmentIds,
845+
setThreadAutoSettle,
832846
projectByKey,
833847
projectTitleByProjectKey,
834848
regenerateThreadTitle,

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,16 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
493493
readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
494494
readonly onPinThread: (thread: EnvironmentThreadShell) => void;
495495
readonly onUnpinThread: (thread: EnvironmentThreadShell) => void;
496+
readonly onSetThreadAutoSettle: (thread: EnvironmentThreadShell, enabled: boolean) => void;
496497
/** False on environments whose server predates thread.settle/unsettle:
497498
swipe + menu fall back to Archive instead of failing on use. */
498499
readonly settlementSupported: boolean;
499500
/** False on servers that predate thread.snooze/unsnooze. */
500501
readonly snoozeSupported: boolean;
501502
/** False on servers that predate thread.pin/unpin. */
502503
readonly pinningSupported: boolean;
504+
/** False on servers that predate thread.auto-settle.set. */
505+
readonly autoSettleOptOutSupported: boolean;
503506
/** False on servers that predate thread title regeneration. */
504507
readonly titleRegenerationSupported: boolean;
505508
/** Server supports reordering this card's section. */
@@ -536,6 +539,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
536539
onArchiveThread,
537540
onPinThread,
538541
onUnpinThread,
542+
onSetThreadAutoSettle,
539543
onMoveThread,
540544
} = props;
541545
const snoozedRow = props.snoozed === true;
@@ -583,6 +587,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
583587
const handleUnsettle = useCallback(() => onUnsettleThread(thread), [onUnsettleThread, thread]);
584588
const handlePin = useCallback(() => onPinThread(thread), [onPinThread, thread]);
585589
const handleUnpin = useCallback(() => onUnpinThread(thread), [onUnpinThread, thread]);
590+
const handleSetAutoSettle = useCallback(
591+
(enabled: boolean) => onSetThreadAutoSettle(thread, enabled),
592+
[onSetThreadAutoSettle, thread],
593+
);
586594
const handleMoveUp = useCallback(() => onMoveThread?.(thread, "up"), [onMoveThread, thread]);
587595
const handleMoveDown = useCallback(() => onMoveThread?.(thread, "down"), [onMoveThread, thread]);
588596
const handleArchive = useCallback(() => onArchiveThread(thread), [onArchiveThread, thread]);
@@ -661,6 +669,33 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
661669
variant,
662670
],
663671
);
672+
// A submenu with the current option checked, matching web. This is a
673+
// per-thread setting, not a lifecycle verb.
674+
const autoSettleMenuItems = useMemo<MenuAction[]>(
675+
() =>
676+
props.autoSettleOptOutSupported
677+
? [
678+
{
679+
id: "auto-settle",
680+
title: "Auto-settle behavior",
681+
image: "timer",
682+
subactions: [
683+
{
684+
id: "auto-settle:enabled",
685+
title: "Enabled",
686+
state: thread.autoSettleDisabledAt == null ? "on" : "off",
687+
},
688+
{
689+
id: "auto-settle:disabled",
690+
title: "Disabled",
691+
state: thread.autoSettleDisabledAt == null ? "off" : "on",
692+
},
693+
],
694+
} satisfies MenuAction,
695+
]
696+
: [],
697+
[props.autoSettleOptOutSupported, thread.autoSettleDisabledAt],
698+
);
664699
const titleMenuItems = useMemo<MenuAction[]>(
665700
() => [
666701
{ id: "rename", title: "Rename", image: "square.and.pencil" },
@@ -682,33 +717,43 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
682717
},
683718
...arrangementMenuItems,
684719
...titleMenuItems,
720+
...autoSettleMenuItems,
685721
{ id: "delete", title: "Delete", image: "trash", attributes: { destructive: true } },
686722
],
687-
[arrangementMenuItems, snoozePresetActions, titleMenuItems],
723+
[arrangementMenuItems, autoSettleMenuItems, snoozePresetActions, titleMenuItems],
688724
);
689725
const cardMenuActions = useMemo<MenuAction[]>(
690726
() => [
691727
CARD_MENU_ACTIONS[0]!,
692728
...arrangementMenuItems,
693729
...titleMenuItems,
730+
...autoSettleMenuItems,
694731
...CARD_MENU_ACTIONS.slice(1),
695732
],
696-
[arrangementMenuItems, titleMenuItems],
733+
[arrangementMenuItems, autoSettleMenuItems, titleMenuItems],
697734
);
735+
// Settled and snoozed rows keep the setting too, matching web where every
736+
// row shares one menu builder.
698737
const slimMenuActions = useMemo<MenuAction[]>(
699738
() => [
700739
SLIM_MENU_ACTIONS[0]!,
701740
...arrangementMenuItems.filter(
702741
(action) => action.id !== "move-up" && action.id !== "move-down",
703742
),
704743
...titleMenuItems,
744+
...autoSettleMenuItems,
705745
SLIM_MENU_ACTIONS[1]!,
706746
],
707-
[arrangementMenuItems, titleMenuItems],
747+
[arrangementMenuItems, autoSettleMenuItems, titleMenuItems],
708748
);
709749
const snoozedMenuActions = useMemo<MenuAction[]>(
710-
() => [SNOOZED_MENU_ACTIONS[0]!, ...titleMenuItems, SNOOZED_MENU_ACTIONS[1]!],
711-
[titleMenuItems],
750+
() => [
751+
SNOOZED_MENU_ACTIONS[0]!,
752+
...titleMenuItems,
753+
...autoSettleMenuItems,
754+
SNOOZED_MENU_ACTIONS[1]!,
755+
],
756+
[autoSettleMenuItems, titleMenuItems],
712757
);
713758
const legacyMenuActions = useMemo<MenuAction[]>(
714759
() => [
@@ -727,6 +772,8 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
727772
if (nativeEvent.event === "unsnooze") handleUnsnooze();
728773
if (nativeEvent.event === "pin") handlePin();
729774
if (nativeEvent.event === "unpin") handleUnpin();
775+
if (nativeEvent.event === "auto-settle:enabled") handleSetAutoSettle(true);
776+
if (nativeEvent.event === "auto-settle:disabled") handleSetAutoSettle(false);
730777
if (nativeEvent.event === "arrange") appAtomRegistry.set(threadArrangementOpenAtom, true);
731778
if (nativeEvent.event === "move-up") handleMoveUp();
732779
if (nativeEvent.event === "move-down") handleMoveDown();
@@ -764,6 +811,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
764811
handlePin,
765812
handleSettle,
766813
handleSnooze,
814+
handleSetAutoSettle,
767815
handleUnpin,
768816
handleUnsettle,
769817
handleUnsnooze,

‎apps/mobile/src/state/use-thread-selection.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function threadDetailToShell(
7474
settledAt: thread.settledAt,
7575
unsettledAt: thread.unsettledAt,
7676
activeOrderKey: thread.activeOrderKey,
77+
autoSettleDisabledAt: thread.autoSettleDisabledAt,
7778
pinnedAt: thread.pinnedAt,
7879
pinOrderKey: thread.pinOrderKey,
7980
snoozedUntil: thread.snoozedUntil ?? null,

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export const make = Effect.gen(function* () {
236236
threadPinning: true,
237237
threadPinReorder: true,
238238
threadActiveReorder: true,
239+
threadAutoSettleOptOut: true,
239240
threadTitleRegeneration: true,
240241
threadPullRequests: true,
241242
pullRequestStackActions: true,

0 commit comments

Comments
 (0)