Files
buzz/mobile/lib/shared/me/solo_chat_seed.dart
Tom Brow 0ac71eaf95 feat(mobile): start a Solo chat from a message or inbox row (#9251)
Adds **Start Solo chat** to the message long-press sheet and the inbox
row menu, analogous to buzz-app desktop's action.

## Behavior

- Opens an unsent New chat draft (no channel is created until the first
send), with the composer expanded and focused.
- **Open channel messages** (public stream or forum) are seeded with the
message's `buzz://` link, as desktop does, so the agent can open it.
- **DMs, private channels, Solo chats and unknown channels** are seeded
with the message excerpted as a Markdown block quote, because the agent
usually can't read them. A long quote is cut at 6 KB so the first
message stays under the 8 KB limit.
- Starting again from the same message returns to the same draft (keyed
`new-solo:<messageId>`).
- Unlike desktop, it's available on your own messages too.
- In the sheet it's a list row under **Copy text**; in the inbox menu
it's under **Open conversation**, for message items with content.
- The draft title skips a leading block quote and uses the prompt after
it (or the quote text when there's no prompt).

## Notes

- A seeded draft left unsent stays in the inbox Drafts list, as an
unsent New chat draft already does.
- Conflicts with #9142 (inbox row menu follow and remind actions), which
reindents `_showRowActions`. Whichever lands second needs a small
rebase.

## Demo

Public channel message (linked), private channel message (quoted), then
a public channel inbox item (linked) and a DM inbox item (quoted). Test
data only.


https://github.com/user-attachments/assets/91d2de7f-d35d-4907-bcf6-ec904327f06c

## Before / after

| | Before | After |
|---|---|---|
| Message long-press sheet | <img
src="https://github.com/user-attachments/assets/da79ae08-68a0-4396-9a63-f01af9ceb3a3"
width="260"> | <img
src="https://github.com/user-attachments/assets/88ee6ff1-66d6-42fe-8b78-ab7f4e6cbcfa"
width="260"> |
| Inbox row menu | <img
src="https://github.com/user-attachments/assets/5c6f551c-63f5-40ab-b0a3-08778472d964"
width="260"> | <img
src="https://github.com/user-attachments/assets/25f9fa30-ac52-4b78-85fb-5679ca336495"
width="260"> |

Where it lands (new, unsent New chat draft):

| Public message | Private message | Public inbox item | DM inbox item |
|---|---|---|---|
| <img
src="https://github.com/user-attachments/assets/245204d3-0a56-4029-a2a6-e9d054ee6e0e"
width="190"> | <img
src="https://github.com/user-attachments/assets/3d5a100b-5ae5-470e-b945-8c9b24ac1db0"
width="190"> | <img
src="https://github.com/user-attachments/assets/8deea67e-07f4-4fc8-93d8-981fbe848c1d"
width="190"> | <img
src="https://github.com/user-attachments/assets/0f4b62c9-81ba-4d08-a77c-8298f3b46718"
width="190"> |

## Validation

- Automated simulator run (iOS 27 sim, Remote Agents Pilot): sheet on
own message in a public channel seeds the link chip; sheet on a private
channel message seeds a quote; inbox public channel item seeds the link;
inbox DM item seeds a quote. Recorded as the demo above.
- New `solo_chat_seed_test.dart` table test (link, thread link, quote
trimming, multi-line quote) and two new title cases in
`me_chat_creation_test.dart`.
- `flutter test`: all pass except the 4 `right drag starting on/beside a
link replies` cases in `channel_detail_page_test.dart`, which fail
identically on clean `main`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 04:12:00 -08:00

55 lines
1.7 KiB
Dart

import 'dart:convert';
import '../deeplink/deep_link.dart';
/// Largest quoted excerpt, in UTF-8 bytes. A first Solo message may be 8 KB,
/// so this leaves room for the prompt the user adds below the quote.
const soloChatQuoteMaxBytes = 6144;
/// The unsent first message for a Solo chat started from another message.
///
/// An open channel's message is linked, as desktop's Start Solo chat does: the
/// agent can open it there. A DM, private channel or Solo chat is usually
/// closed to the agent, so the message is excerpted as a block quote instead.
String soloChatSeed({
required bool linkable,
required String channelId,
required String messageId,
required String? threadRootId,
required String content,
}) {
if (linkable) {
final link = buildMessageLink(
channelId: channelId,
messageId: messageId,
threadRootId: threadRootId,
);
return '$link\n\n';
}
final quote = content
.trim()
.split('\n')
.map((line) => line.isEmpty ? '>' : '> $line')
.join('\n');
return '${_capQuote(quote)}\n\n';
}
String _capQuote(String quote) {
if (utf8.encode(quote).length <= soloChatQuoteMaxBytes) return quote;
const ellipsis = '…';
final budget = soloChatQuoteMaxBytes - utf8.encode(ellipsis).length;
final kept = StringBuffer();
var bytes = 0;
for (final rune in quote.runes) {
final char = String.fromCharCode(rune);
bytes += utf8.encode(char).length;
if (bytes > budget) break;
kept.write(char);
}
return '${kept.toString().trimRight()}$ellipsis';
}
/// One draft per source message: starting again from it returns to the
/// unsent prompt instead of stranding it.
String soloChatSeedDraftKey(String messageId) => 'new-solo:$messageId';