Skip to content

Commit ddeb799

Browse files
klopez4212Terp
andauthored
Add queued follow-ups to the mobile Solo composer (#10018)
## Summary Adds a **Follow-up behavior** setting for Solo chats on mobile. **Send immediately** is the default. Choosing **Queue** holds follow-ups while the agent works and releases the next one when the open chat observes completion or the agent goes quiet. Queued messages persist locally across app restarts. Tap a queued message to return it to the composer. Submitting again uses the current send rules. On send, the pill fills with the outgoing color, fades its controls and hands its bounds to the composer’s timeline animation. The ellipsis offers **Send now**, **Edit**, and **Cancel**. ### Related work #9910 covers offline sends. This change handles follow-ups to a busy Solo agent. ### Testing Preview installed on iPhone Air. Flutter widget coverage exercises immediate and queued submission, editing, menu actions, scrolling and composer alignment. Regression coverage includes a missed completion, silence after sending, and release after a stale heartbeat. Both Send controls use the chat accent. ### Queue snapshots Phone-width Flutter renders in light and dark appearance. ![Light appearance](https://github.com/user-attachments/assets/6dae5e4e-8846-4a3e-b1f5-cf239598e23b) ![Dark appearance](https://github.com/user-attachments/assets/3414de56-e164-4661-8a62-ebc7dca5033c) ### Open review findings The draft needs delivery and persistence fixes before merge. In particular, an ambiguous relay acknowledgement can duplicate a manual retry, and editing can preserve a removed mention or lose draft text if interrupted during submission. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
1 parent 79beb12 commit ddeb799

24 files changed

Lines changed: 2123 additions & 126 deletions

‎mobile/lib/features/channels/channel_detail_page.dart‎

Lines changed: 96 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'solo_follow_ups.dart';
2+
import 'solo_queue_store.dart';
13
import '../../shared/widgets/app_list.dart';
24
import 'package:duo_kit/duo_kit.dart';
35

@@ -738,6 +740,83 @@ class _ResolvedChannelDetailPage extends HookConsumerWidget {
738740
relaySummaries: timeline.summaries,
739741
);
740742

743+
Future<void> submit(
744+
String content,
745+
List<String> mentionPubkeys, {
746+
List<List<String>> mediaTags = const [],
747+
}) async {
748+
if (!placementKnown) {
749+
ref.invalidate(meGroupsProvider);
750+
throw StateError('Reconnect to verify this chat before sending.');
751+
}
752+
var recipients = mentionPubkeys;
753+
if (personalChat) {
754+
if (!resolvedChannel.isPersonalChat(
755+
ref.read(myPubkeyProvider),
756+
mePlacement?.asData?.value.channels ?? const [],
757+
)) {
758+
throw StateError('Refresh Solo before sending to this chat.');
759+
}
760+
recipients = await meRecipients(
761+
ref,
762+
channel.id,
763+
assistant.selected,
764+
mentionPubkeys,
765+
);
766+
}
767+
final donate = activeShareSuggestionDonor(ref);
768+
final displayName = resolvedChannel.displayLabel(
769+
currentPubkey: ref.read(myPubkeyProvider),
770+
);
771+
await sendMessage.call(
772+
channelId: channel.id,
773+
content: content,
774+
mentionPubkeys: recipients,
775+
channel: resolvedChannel,
776+
mediaTags: mediaTags,
777+
);
778+
donate(
779+
channelId: channel.id,
780+
displayName: displayName,
781+
recipientCount: resolvedChannel.memberCount - 1,
782+
);
783+
}
784+
785+
final queueScope =
786+
'${ref.watch(relayConfigProvider).baseUrl}/$currentPubkey/${channel.id}';
787+
Widget composer(
788+
ComposeBarOnSend submit, [
789+
String? editText,
790+
Widget? queue,
791+
ValueChanged<String>? onEditChanged,
792+
VoidCallback? removeEmptyEdit,
793+
]) => ComposeBar(
794+
onQueuedEditChanged: onEditChanged,
795+
removeEmptyEdit: removeEmptyEdit,
796+
queuedEditText: editText,
797+
queuedBindings: editText == null
798+
? const []
799+
: ref.read(soloQueueStore(queueScope)).editing?['bindings']
800+
as List? ??
801+
const [],
802+
onQueuedBindingsChanged: editText == null
803+
? null
804+
: (bindings) {
805+
final store = ref.read(soloQueueStore(queueScope));
806+
store.editing?['bindings'] = bindings;
807+
},
808+
aboveComposer: queue,
809+
channelId: channel.id,
810+
focusNode: editText == null ? composerFocusNode : null,
811+
prefillScopeMessages: personalChat || resolvedChannel.isDm
812+
? null
813+
: [for (final entry in timelineEntries) entry.message],
814+
onFocusRestorerChanged: editText != null
815+
? null
816+
: (restoreFocus) => restoreComposerFocus.value = restoreFocus,
817+
channelName: resolvedChannel.isDm ? '' : resolvedChannel.name,
818+
onSend: submit,
819+
);
741820
return FrostedScaffold(
742821
extendHeaderUnderRail: true,
743822
foreground:
@@ -993,69 +1072,23 @@ class _ResolvedChannelDetailPage extends HookConsumerWidget {
9931072
?refreshNotice,
9941073
BestieTranscriptionStatus(channelId: channel.id),
9951074
?assistant.pendingNotice,
996-
ComposeBar(
997-
channelId: channel.id,
998-
focusNode: composerFocusNode,
999-
prefillScopeMessages:
1000-
personalChat || resolvedChannel.isDm
1001-
? null
1002-
: [
1003-
for (final entry in timelineEntries)
1004-
entry.message,
1005-
],
1006-
onFocusRestorerChanged: (restoreFocus) =>
1007-
restoreComposerFocus.value = restoreFocus,
1008-
channelName: resolvedChannel.isDm
1009-
? ''
1010-
: resolvedChannel.name,
1011-
onSend:
1012-
(
1013-
content,
1014-
mentionPubkeys, {
1015-
mediaTags = const <List<String>>[],
1016-
}) async {
1017-
if (!placementKnown) {
1018-
ref.invalidate(meGroupsProvider);
1019-
throw StateError(
1020-
'Reconnect to verify this chat before sending.',
1021-
);
1022-
}
1023-
var recipients = mentionPubkeys;
1024-
if (personalChat) {
1025-
if (!resolvedChannel.isPersonalChat(
1026-
ref.read(myPubkeyProvider),
1027-
mePlacement?.asData?.value.channels ??
1028-
const [],
1029-
)) {
1030-
throw StateError(
1031-
'Refresh Solo before sending to this chat.',
1032-
);
1033-
}
1034-
recipients = await meRecipients(
1035-
ref,
1036-
channel.id,
1037-
assistant.selected,
1038-
mentionPubkeys,
1039-
);
1040-
}
1041-
final donate = activeShareSuggestionDonor(ref);
1042-
final displayName = resolvedChannel.displayLabel(
1043-
currentPubkey: ref.read(myPubkeyProvider),
1044-
);
1045-
await sendMessage.call(
1046-
channelId: channel.id,
1047-
content: content,
1048-
mentionPubkeys: recipients,
1049-
channel: resolvedChannel,
1050-
mediaTags: mediaTags,
1051-
);
1052-
donate(
1053-
channelId: channel.id,
1054-
displayName: displayName,
1055-
recipientCount: resolvedChannel.memberCount - 1,
1056-
);
1057-
},
1058-
),
1075+
if (personalChat)
1076+
SoloFollowUps(
1077+
key: ValueKey(queueScope),
1078+
scope: queueScope,
1079+
agent: assistant.selected,
1080+
busy: typingEntries.any(
1081+
(entry) => entry.pubkey == assistant.selected,
1082+
),
1083+
connected:
1084+
placementKnown &&
1085+
sessionStatus == SessionStatus.connected,
1086+
channelId: channel.id,
1087+
send: submit,
1088+
composer: composer,
1089+
)
1090+
else
1091+
composer(submit),
10591092
],
10601093
),
10611094
),

‎mobile/lib/features/channels/compose_bar/compose_bar_widget.dart‎

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
part of '../compose_bar.dart';
22

33
class ComposeBar extends HookConsumerWidget {
4+
final Widget? aboveComposer;
5+
final VoidCallback? removeEmptyEdit;
6+
final String? queuedEditText;
7+
final List<dynamic> queuedBindings;
8+
final ValueChanged<List<Map<String, dynamic>>>? onQueuedBindingsChanged;
9+
final ValueChanged<String>? onQueuedEditChanged;
410
final String channelId;
511
final String channelName;
612
final String? hintText;
@@ -39,6 +45,12 @@ class ComposeBar extends HookConsumerWidget {
3945
const ComposeBar({
4046
super.key,
4147
required this.channelId,
48+
this.queuedEditText,
49+
this.queuedBindings = const [],
50+
this.onQueuedBindingsChanged,
51+
this.onQueuedEditChanged,
52+
this.aboveComposer,
53+
this.removeEmptyEdit,
4254
this.interactionLocked = false,
4355
this.channelName = '',
4456
this.hintText,
@@ -59,10 +71,10 @@ class ComposeBar extends HookConsumerWidget {
5971
final controller = useMemoized(_MarkdownEditingController.new);
6072
final draftText = useListenableSelector(controller, () => controller.text);
6173
useEffect(() => controller.dispose, [controller]);
62-
final draftKey = composeDraftKey(channelId, threadHeadId: threadHeadId);
74+
final draftKey = _composeEditorKey(channelId, threadHeadId, queuedEditText);
6375
final draftRevision = useRef(0);
6476
final draftIdentity = _composerDraftIdentity(ref);
65-
final isComposerExpanded = useState(false);
77+
final isComposerExpanded = useState(queuedEditText != null);
6678
final androidImeTransitionStarted = useState(
6779
defaultTargetPlatform != TargetPlatform.android,
6880
);
@@ -147,6 +159,11 @@ class ComposeBar extends HookConsumerWidget {
147159
);
148160
final prefillText = useRef<String?>(null);
149161
_useComposeDraftLifecycle(
162+
queuedEditText: queuedEditText,
163+
queuedBindings: queuedBindings,
164+
onQueuedBindingsChanged: onQueuedBindingsChanged,
165+
onQueuedEditChanged: onQueuedEditChanged,
166+
focusNode: focusNode,
150167
context: context,
151168
voiceNote: voiceNoteRef,
152169
prefillText: prefillText,
@@ -182,17 +199,7 @@ class ComposeBar extends HookConsumerWidget {
182199
isComposerExpanded.value = false;
183200
}
184201

185-
useEffect(() {
186-
void collapseWhenUnfocused() {
187-
if (!focusNode.hasFocus && !isEmojiPickerOpen.value) {
188-
collapseComposer();
189-
}
190-
}
191-
192-
focusNode.addListener(collapseWhenUnfocused);
193-
return () => focusNode.removeListener(collapseWhenUnfocused);
194-
}, [focusNode]);
195-
202+
_useCollapseWhenUnfocused(focusNode, isEmojiPickerOpen, collapseComposer);
196203
_useComposerKeyboardMetrics(
197204
context: context,
198205
focusNode: focusNode,
@@ -445,24 +452,15 @@ class ComposeBar extends HookConsumerWidget {
445452
void selectEmoji(_EmojiChoice choice) =>
446453
_selectComposerEmoji(controller, focusNode, emojiQuery, choice);
447454

448-
// Insert a selected channel into the text field.
449-
void insertChannel(Channel channel) {
450-
final start = channelStartIdx.value.clamp(0, controller.text.length);
451-
isModifyingText.value = true;
452-
try {
453-
spliceAndMoveCursor(
454-
controller,
455-
focusNode,
456-
start: start,
457-
replacement: '#${channel.name} ',
458-
);
459-
} finally {
460-
isModifyingText.value = false;
461-
}
462-
channelQuery.value = null;
463-
inputTool.value = null;
464-
unawaited(SystemChannels.textInput.invokeMethod<void>('TextInput.show'));
465-
}
455+
void insertChannel(Channel channel) => _insertChannelSuggestion(
456+
controller,
457+
focusNode,
458+
channelStartIdx.value,
459+
isModifyingText,
460+
channelQuery,
461+
inputTool,
462+
channel,
463+
);
466464

467465
// Insert `@` at the cursor to manually trigger mention mode.
468466
void triggerMention() => _insertTriggerAtCursor(controller, focusNode, '@');
@@ -516,13 +514,22 @@ class ComposeBar extends HookConsumerWidget {
516514
final mentions = controller.mentions;
517515
final code = controller._styledCodeRanges(draft);
518516
final submittedOrigin = ComposerSendOrigin.capture(sendSurfaceKey);
517+
final bindings = [
518+
for (final m in controller.bindings) m.toDraft().toJson(),
519+
];
520+
late final String wireText;
519521
Future<void> sendWithOrigin(
520522
String content,
521523
List<String> mentionPubkeys, {
522524
List<List<String>> mediaTags = const [],
523525
}) => ComposerSendOrigin.run(
524526
submittedOrigin,
525-
() => onSend(content, mentionPubkeys, mediaTags: mediaTags),
527+
() => ComposerSendOrigin.withDraft(
528+
draft,
529+
bindings,
530+
wireText,
531+
() => onSend(content, mentionPubkeys, mediaTags: mediaTags),
532+
),
526533
);
527534
final submittedDraftRevision = draftRevision.value;
528535
final cleanupStoredDraft = ref
@@ -579,6 +586,7 @@ class ComposeBar extends HookConsumerWidget {
579586
mentions,
580587
nameEnds: nameEnds,
581588
).trim();
589+
wireText = text;
582590
final outgoing = _OutgoingMentions(selectedMentions);
583591
// Read before any await. These actions belong to this community and
584592
// refuse to run after a switch, so an Invite answered after a switch
@@ -678,7 +686,7 @@ class ComposeBar extends HookConsumerWidget {
678686
final draftAttachments = List<_PendingAttachment>.of(attachments.value);
679687
final draftMentions = controller.bindings;
680688
final draftMentionsInvalid = controller.mentionsInvalid;
681-
clearComposer();
689+
if (queuedEditText == null) clearComposer();
682690
final clearedDraftRevision = draftRevision.value;
683691
uploadingCount.value += 1;
684692
uploadProgress.value = 0;
@@ -1100,6 +1108,7 @@ class ComposeBar extends HookConsumerWidget {
11001108
child: Column(
11011109
mainAxisSize: MainAxisSize.min,
11021110
children: [
1111+
?aboveComposer,
11031112
_UploadProgressMotion(
11041113
visible: uploadingCount.value > 0,
11051114
progress: uploadProgress.value,
@@ -1128,6 +1137,9 @@ class ComposeBar extends HookConsumerWidget {
11281137
interactionLocked || (draftMembers != null && sending),
11291138
child: _ComposeBarLayout(
11301139
surfaceKey: sendSurfaceKey,
1140+
removeEmptyEdit: preparingAttachments.value == 0
1141+
? removeEmptyEdit
1142+
: null,
11311143
textStyle: textStyle ?? chatBodyTextStyle,
11321144
voiceNoteRecorder: voiceNote.recorder,
11331145
keyboardToolbar: defaultTargetPlatform == TargetPlatform.iOS,

0 commit comments

Comments
 (0)