Skip to content

Commit 41f4887

Browse files
Merge pull request #125 from ScriptedAlchemy/t3/mobile-group-chat-mention-chips
fix(mobile): make group chat usable and draw member mentions as chips
2 parents 5846605 + 8e97d9d commit 41f4887

30 files changed

Lines changed: 555 additions & 152 deletions
1.1 KB
Loading

‎apps/mobile/scripts/sync-context-chip-icons.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const lucideIcons = [
4646
"mouse-pointer-click",
4747
"server",
4848
"terminal",
49+
"users",
4950
];
5051

5152
async function lucideSvg(name) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ComposerContextId } from "@t3tools/contracts";
33
import { useAtomValue } from "@effect/atom-react";
44
import { AsyncResult } from "effect/reactivity";
55
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
6+
import { groupMentionOccurrences } from "@t3tools/client-runtime/state/thread-group";
67
import { useEffect, useState } from "react";
78
import type { EnvironmentId } from "@t3tools/contracts";
89
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
@@ -196,6 +197,10 @@ export function ComposerEditor({
196197
onInertChipPress?.();
197198
return;
198199
}
200+
const member = groupMentionOccurrences(selection.source, props.group, {
201+
seatedOnly: true,
202+
})[0];
203+
if (member?.source === selection.source) return;
199204
const path = composerMentionPath(selection.source, draft.context);
200205
if (path && onOpenMention) {
201206
onOpenMention(path);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { groupParticipants, isGroupActive } from "@t3tools/client-runtime/state/thread-group";
1+
import { isGroupActive } from "@t3tools/client-runtime/state/thread-group";
22
import { orchestrationEnvironment } from "../../state/orchestration";
33
import { ProjectKnowledgeEntry } from "../../components/ProjectKnowledgeEntry";
44
import { useSidebarWorkspaceTabs } from "../layout/workspace/useSystemWorkspaceTabBar";
@@ -1043,10 +1043,9 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
10431043
// The save uses a draft snapshot; further typing would be discarded on success.
10441044
readOnly={isSubmissionLocked}
10451045
skills={composerMenu.skills}
1046-
groupHandles={(isGroupActive(props.selectedThread.group)
1047-
? groupParticipants(props.selectedThread.group)
1048-
: []
1049-
).map((participant) => participant.handle.toLowerCase())}
1046+
group={
1047+
isGroupActive(props.selectedThread.group) ? props.selectedThread.group : null
1048+
}
10501049
selection={composerMenu.selection}
10511050
onChangeText={(text) => {
10521051
if (!isSubmissionLocked) props.onChangeDraftMessage(text);

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
2+
groupMentionOccurrences,
23
groupRowSpeaker,
4+
sameThreadGroup,
35
isQuietPass,
46
quietPassLine,
57
type ThreadGroup,
@@ -1236,8 +1238,14 @@ function ArtifactTemplateCard(props: {
12361238
);
12371239
}
12381240

1241+
function exactGroupMention(text: string, group: ThreadGroup | null | undefined) {
1242+
const mention = groupMentionOccurrences(text, group)[0];
1243+
return mention !== undefined && mention.source === text ? mention : undefined;
1244+
}
1245+
12391246
const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
12401247
readonly markdown: string;
1248+
readonly group?: ThreadGroup | null;
12411249
readonly environmentId: EnvironmentId;
12421250
readonly markdownStyles: MarkdownStyleSet;
12431251
readonly linkHandlers: MarkdownLinkHandlers;
@@ -1273,13 +1281,15 @@ const AssistantMarkdownContent = memo(function AssistantMarkdownContent(props: {
12731281
renderImage={props.renderImage}
12741282
skills={props.skills}
12751283
models={models}
1284+
group={props.group}
12761285
/>
12771286
);
12781287
});
12791288

12801289
// Folds split first, so an artifact card inside a fold stays inside it.
12811290
function AssistantMarkdownBlocks(props: {
12821291
readonly markdown: string;
1292+
readonly group?: ThreadGroup | null;
12831293
/** The reply's reference definitions, passed down by the enclosing fold. */
12841294
readonly definitions?: ReadonlyArray<string> | undefined;
12851295
readonly markdownStyles: MarkdownStyleSet;
@@ -1335,6 +1345,7 @@ function AssistantMarkdownBlocks(props: {
13351345
)}
13361346
skills={props.skills}
13371347
models={props.models}
1348+
group={props.group}
13381349
textStyle={props.markdownStyles.nativeTextStyle}
13391350
{...props.linkHandlers}
13401351
renderImage={props.renderImage}
@@ -1534,6 +1545,7 @@ function OpenSenderThreadButton(props: {
15341545
/** Automation prompts are long, repeated runbooks; a folded bubble keeps them out of the way. */
15351546
function ThreadAutomationMessageRow(props: {
15361547
readonly environmentId: EnvironmentId;
1548+
readonly group?: ThreadGroup | null;
15371549
readonly text: string;
15381550
readonly context?: OrchestrationMessageContext;
15391551
readonly scheduledTaskId: ScheduledTaskId | undefined;
@@ -1606,6 +1618,7 @@ function ThreadAutomationMessageRow(props: {
16061618
<MarkdownImageAvailableWidthContext value={props.contentMaxWidth}>
16071619
<UserMessageContent
16081620
text={renderAssistantCitationsAsText(props.text)}
1621+
group={props.group}
16091622
environmentId={props.environmentId}
16101623
context={props.context}
16111624
markdownStyles={props.markdownStyles}
@@ -1863,6 +1876,7 @@ function renderFeedEntry(
18631876
<MarkdownImageAvailableWidthContext value={props.markdownContentWidth}>
18641877
<AssistantMarkdownContent
18651878
markdown={entry.text}
1879+
group={props.group}
18661880
environmentId={props.environmentId}
18671881
markdownStyles={markdownStyles.assistant}
18681882
linkHandlers={props.markdownLinkHandlers}
@@ -2065,6 +2079,7 @@ function renderFeedEntry(
20652079
return (
20662080
<ThreadAutomationMessageRow
20672081
environmentId={props.environmentId}
2082+
group={props.group}
20682083
text={presentation.text}
20692084
context={message.context}
20702085
scheduledTaskId={presentation.scheduledTaskId}
@@ -2306,6 +2321,7 @@ function renderFeedEntry(
23062321
>
23072322
<UserMessageContent
23082323
text={renderedText}
2324+
group={props.group}
23092325
sent={{ threadId: message.sourceThreadId, messageId: message.id }}
23102326
environmentId={props.environmentId}
23112327
context={message.context}
@@ -2430,6 +2446,7 @@ function renderFeedEntry(
24302446
<MarkdownImageAvailableWidthContext value={props.markdownContentWidth}>
24312447
<AssistantMarkdownContent
24322448
markdown={renderedText}
2449+
group={props.group}
24332450
environmentId={props.environmentId}
24342451
markdownStyles={styles}
24352452
linkHandlers={props.markdownLinkHandlers}
@@ -2553,6 +2570,7 @@ function TurnDiffStat(props: {
25532570

25542571
type UserMessageContentProps = {
25552572
readonly text: string;
2573+
readonly group?: ThreadGroup | null;
25562574
readonly sent?: { readonly threadId: ThreadId; readonly messageId: MessageId };
25572575
readonly environmentId: EnvironmentId;
25582576
readonly context?: OrchestrationMessageContext;
@@ -2693,6 +2711,7 @@ function UserMessageMarkdownContent(props: UserMessageContentProps) {
26932711
contextClipboardFragment={contextClipboardFragment}
26942712
skills={props.skills}
26952713
models={models}
2714+
group={props.group}
26962715
textStyle={props.markdownStyles.nativeTextStyle}
26972716
preserveSoftBreaks
26982717
{...props.linkHandlers}
@@ -2726,6 +2745,7 @@ function UserMessageMarkdownContent(props: UserMessageContentProps) {
27262745
contextClipboardFragment={contextClipboardFragment}
27272746
skills={props.skills}
27282747
models={models}
2748+
group={props.group}
27292749
textStyle={props.markdownStyles.nativeTextStyle}
27302750
preserveSoftBreaks
27312751
{...props.linkHandlers}
@@ -2886,6 +2906,8 @@ const THREAD_FEED_MAINTAIN_SCROLL_AT_END = {
28862906
} as const;
28872907

28882908
export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
2909+
const [group, setGroup] = useState(props.group);
2910+
if (!sameThreadGroup(group, props.group)) setGroup(props.group);
28892911
const formatMessageTime = useMessageTimeFormatter();
28902912
const { listRef, onIsAtEndChange, onHeaderMaterialVisibilityChange } = props;
28912913
const workflowOpening = useWorkflowOpening(props.detailRef);
@@ -3164,6 +3186,16 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
31643186
reply?: MarkdownLinkReply,
31653187
withGallery?: (source: FilePreviewSource) => FilePreviewSource,
31663188
) => {
3189+
const mention = exactGroupMention(href, group);
3190+
if (mention) {
3191+
if (mention.member !== "primary") {
3192+
openLinkedThread({
3193+
environmentId: String(props.environmentId),
3194+
threadId: String(mention.member),
3195+
});
3196+
}
3197+
return;
3198+
}
31673199
markdownLinkRequest.current?.abort();
31683200
const request = new AbortController();
31693201
markdownLinkRequest.current = request;
@@ -3276,6 +3308,19 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
32763308
onImagePress: (href, withGallery) => onMarkdownLinkPress(href, true, undefined, withGallery),
32773309
resolveImageSource,
32783310
fileContextMenu: (href) => {
3311+
const mention = exactGroupMention(href, group);
3312+
if (mention) {
3313+
return {
3314+
title: mention.label,
3315+
actions:
3316+
mention.member === "primary"
3317+
? [{ id: "copy-mention", title: "Copy" }]
3318+
: [
3319+
{ id: "open-member", title: "Open work" },
3320+
{ id: "copy-mention", title: "Copy" },
3321+
],
3322+
};
3323+
}
32793324
const skill = enrichedSkillReference(href, props.skills);
32803325
if (skill) {
32813326
return {
@@ -3305,6 +3350,16 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
33053350
return target ? fileChipMenu(target) : undefined;
33063351
},
33073352
onFileContextMenuAction: (href, actionId, reply) => {
3353+
const mention = exactGroupMention(href, group);
3354+
if (mention) {
3355+
if (actionId === "open-member" && mention.member !== "primary") {
3356+
openLinkedThread({
3357+
environmentId: String(props.environmentId),
3358+
threadId: String(mention.member),
3359+
});
3360+
} else if (actionId === "copy-mention") copyTextWithHaptic(mention.source);
3361+
return;
3362+
}
33083363
const skill = enrichedSkillReference(href, props.skills);
33093364
if (skill) {
33103365
const instructionsPath = enrichedSkillInstructionsPath(skill);
@@ -3499,6 +3554,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
34993554
// Include turn completion so unchanged message rows reveal their footer and spacing
35003555
// even when the final message update arrives before the turn settles.
35013556
const listAppearanceData = {
3557+
group,
35023558
disclosureLayout,
35033559
reduceMotion,
35043560
formatMessageTime,
@@ -3914,7 +3970,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
39143970
/>
39153971
) : null}
39163972
{renderFeedEntry(info, {
3917-
group: props.group,
3973+
group,
39183974
runs: structure?.projection.runs ?? [],
39193975
userMessageGrouping: info.item.userMessageGrouping,
39203976
formatMessageTime,

0 commit comments

Comments
 (0)