Skip to content

Commit e1230d6

Browse files
fix(mobile): keep pending messages in the chat timeline (#10449)
1 parent 6abdf37 commit e1230d6

12 files changed

Lines changed: 469 additions & 67 deletions

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ import {
3535
} from "../../state/composer-attachment-uploads";
3636
import Animated, {
3737
FadeIn,
38-
FadeInDown,
3938
FadeOut,
40-
FadeOutDown,
4139
LinearTransition,
4240
ReduceMotion,
4341
useAnimatedStyle,
@@ -272,12 +270,7 @@ const ComposerConnectionStatusPill = memo(function ComposerConnectionStatusPill(
272270
}) {
273271
const isReconnecting = props.status.kind === "reconnecting";
274272
return (
275-
<Animated.View
276-
className="absolute inset-x-0 bottom-full items-center pb-2"
277-
entering={FadeInDown.duration(180)}
278-
exiting={FadeOutDown.duration(140)}
279-
pointerEvents="box-none"
280-
>
273+
<View className="absolute inset-x-0 bottom-full items-center pb-2" pointerEvents="box-none">
281274
<Pressable
282275
accessibilityRole="button"
283276
onPress={props.onPress}
@@ -295,7 +288,7 @@ const ComposerConnectionStatusPill = memo(function ComposerConnectionStatusPill(
295288
{props.status.label}
296289
</Text>
297290
</Pressable>
298-
</Animated.View>
291+
</View>
299292
);
300293
});
301294

@@ -891,16 +884,6 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
891884
</ComposerDictationToolbar>
892885
</Animated.View>
893886
</ComposerSurface>
894-
895-
{/* Queue count */}
896-
{props.queueCount > 0 ? (
897-
<Animated.View entering={FadeIn.duration(180)} exiting={FadeOut.duration(120)}>
898-
<Text className="pt-2 text-xs text-foreground-muted">
899-
{props.queueCount} queued message{props.queueCount === 1 ? "" : "s"} will send
900-
automatically.
901-
</Text>
902-
</Animated.View>
903-
) : null}
904887
</Animated.View>
905888

906889
<VideoPreviewModal source={previewVideo} onRequestClose={closePreview} />

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
useState,
3838
} from "react";
3939
import {
40+
Alert,
4041
AppState,
4142
Keyboard,
4243
Platform,
@@ -67,6 +68,8 @@ import type { StatusTone } from "../../components/StatusPill";
6768
import type { DraftComposerAttachment } from "../../lib/composerImages";
6869
import { CHAT_CONTENT_MAX_WIDTH, type LayoutVariant } from "../../lib/layout";
6970
import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics";
71+
import { editPendingThreadMessage } from "../../state/edit-pending-thread-message";
72+
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
7073
import { scopedThreadKey } from "../../lib/scopedEntities";
7174
import type {
7275
PendingApproval,
@@ -127,6 +130,8 @@ export interface ThreadDetailScreenProps {
127130
readonly projectWorkspaceRoot: string | null;
128131
readonly threadCwd: string | null;
129132
readonly selectedThreadQueueCount: number;
133+
readonly queuedMessages: ReadonlyArray<QueuedThreadMessage>;
134+
readonly dispatchingMessageId: MessageId | null;
130135
readonly serverConfig: T3ServerConfig | null;
131136
readonly layoutVariant?: LayoutVariant;
132137
readonly usesAutomaticContentInsets?: boolean;
@@ -348,6 +353,15 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
348353
return null;
349354
})();
350355
const showWorkingControl = floatingStatus !== null;
356+
// Connection and working status occupy the same space. Keep the feed inset
357+
// stable when reconnecting hands off to syncing and then to a running turn.
358+
const showFloatingStatus =
359+
showWorkingControl ||
360+
props.connectionStateLabel !== "connected" ||
361+
props.queuedMessages.length > 0 ||
362+
props.selectedThreadFeed.some(
363+
(entry) => "acknowledged" in entry && entry.acknowledged === true,
364+
);
351365
const selectedThreadFeed = props.selectedThreadFeed;
352366
const hasCompactableConversation =
353367
selectedThreadFeed.some(
@@ -487,14 +501,14 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
487501
const userInputInsetProgress = useSharedValue(1);
488502
const userInputCardCoverage = useSharedValue(0);
489503
const floatingControlCoverage = useSharedValue(
490-
showWorkingControl ? FLOATING_WORKING_CONTROL_COVERAGE : 0,
504+
showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0,
491505
);
492506
useEffect(() => {
493507
floatingControlCoverage.value = withTiming(
494-
showWorkingControl ? FLOATING_WORKING_CONTROL_COVERAGE : 0,
508+
showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0,
495509
{ duration: 180, reduceMotion: ReduceMotion.System },
496510
);
497-
}, [floatingControlCoverage, showWorkingControl]);
511+
}, [floatingControlCoverage, showFloatingStatus]);
498512
// Android renders the expanded card in-flow (it cannot hit-test the iOS
499513
// overlay outside the bar's bounds), so its measured overlay height already
500514
// includes the card — the coverage extra is iOS-only.
@@ -554,20 +568,20 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
554568
useEffect(() => {
555569
const previous = previousWorkingControlStateRef.current;
556570
const threadChanged = previous.threadKey !== selectedThreadKey;
557-
const visibilityChanged = previous.visible !== showWorkingControl;
571+
const visibilityChanged = previous.visible !== showFloatingStatus;
558572
previousWorkingControlStateRef.current = {
559573
threadKey: selectedThreadKey,
560-
visible: showWorkingControl,
574+
visible: showFloatingStatus,
561575
};
562-
if ((!threadChanged && !visibilityChanged) || (threadChanged && !showWorkingControl)) {
576+
if ((!threadChanged && !visibilityChanged) || (threadChanged && !showFloatingStatus)) {
563577
return;
564578
}
565579
// LegendList applies the larger inset but does not re-anchor short
566580
// followed conversations when this floating coverage changes after the
567581
// initial load. Re-pin after the finite inset transition; the callback
568582
// checks follow state again so a user who scrolled up stays put.
569583
scheduleOverlayRepin(230);
570-
}, [scheduleOverlayRepin, selectedThreadKey, showWorkingControl]);
584+
}, [scheduleOverlayRepin, selectedThreadKey, showFloatingStatus]);
571585
const handleToggleUserInputCollapsed = useCallback(() => {
572586
if (activeUserInputRequestId === null) {
573587
return;
@@ -634,11 +648,13 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
634648
useEffect(() => {
635649
if (
636650
submittedMessageId === null ||
651+
anchorMessageId !== submittedMessageId ||
637652
lastScrolledSubmittedMessageIdRef.current === submittedMessageId ||
638653
contentPresentationKind !== "ready" ||
639-
!selectedThreadFeed.some(
654+
(!selectedThreadFeed.some(
640655
(entry) => entry.type === "message" && entry.id === submittedMessageId,
641-
)
656+
) &&
657+
!props.queuedMessages.some((message) => message.messageId === submittedMessageId))
642658
) {
643659
return;
644660
}
@@ -677,9 +693,11 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
677693
});
678694
return () => cancelAnimationFrame(frame);
679695
}, [
696+
anchorMessageId,
680697
submittedMessageId,
681698
freeze,
682699
contentPresentationKind,
700+
props.queuedMessages,
683701
selectedThreadFeed,
684702
scrollMessageToEnd,
685703
selectedThreadKey,
@@ -720,6 +738,22 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
720738
selectedThreadKey,
721739
]);
722740

741+
const handleEditPendingMessage = useCallback(async (message: QueuedThreadMessage) => {
742+
try {
743+
if (
744+
(await editPendingThreadMessage(message)) &&
745+
selectedThreadKeyRef.current === scopedThreadKey(message.environmentId, message.threadId)
746+
) {
747+
composerEditorRef.current?.focus();
748+
}
749+
} catch (error) {
750+
Alert.alert(
751+
"Could not edit message",
752+
error instanceof Error ? error.message : "Please try again.",
753+
);
754+
}
755+
}, []);
756+
723757
const collapseComposer = useCallback(() => {
724758
composerEditorRef.current?.blur();
725759
}, []);
@@ -797,6 +831,9 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
797831
threadId={props.selectedThread.id}
798832
workspaceRoot={props.threadCwd}
799833
feed={props.selectedThreadFeed}
834+
queuedMessages={props.queuedMessages}
835+
dispatchingMessageId={props.dispatchingMessageId}
836+
onEditPendingMessage={handleEditPendingMessage}
800837
contentPresentation={props.contentPresentation}
801838
agentLabel={agentLabel}
802839
latestTurn={props.selectedThread.latestTurn}
@@ -808,7 +845,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
808845
contentInsetEndAdjustment={combinedContentInsetEndAdjustment}
809846
contentTopInset={0}
810847
contentBottomInset={
811-
estimatedOverlayHeight + (showWorkingControl ? FLOATING_WORKING_CONTROL_COVERAGE : 0)
848+
estimatedOverlayHeight + (showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0)
812849
}
813850
contentMaxWidth={contentMaxWidth}
814851
layoutVariant={layoutVariant}

0 commit comments

Comments
 (0)