Skip to content

Commit 3dd236e

Browse files
unify channel add + search into one entry point (#1964)
1 parent 6c2d667 commit 3dd236e

14 files changed

Lines changed: 1597 additions & 626 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default defineConfig({
2525
"**/channel-shared-header-backdrop.spec.ts",
2626
"**/badge.spec.ts",
2727
"**/channel-browser.spec.ts",
28+
"**/channel-add-screenshots.spec.ts",
2829
"**/messaging.spec.ts",
2930
"**/custom-emoji.spec.ts",
3031
"**/profile-custom-emoji-status.spec.ts",

‎desktop/src/app/AppShell.tsx‎

Lines changed: 85 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import { useRelayAutoHeal } from "@/shared/api/useRelayAutoHeal";
8080
import { useDeferredStartup } from "@/shared/hooks/useDeferredStartup";
8181
import { useWebviewScrollBoundaryLock } from "@/shared/hooks/useWebviewScrollBoundaryLock";
8282
import { joinChannel } from "@/shared/api/tauri";
83-
import type { SearchHit } from "@/shared/api/types";
83+
import type { ChannelVisibility, SearchHit } from "@/shared/api/types";
8484
import { ChannelNavigationProvider } from "@/shared/context/ChannelNavigationContext";
8585
import { MainInsetProvider } from "@/shared/layout/MainInsetContext";
8686
import { chromeCssVarDefaults } from "@/shared/layout/chromeLayout";
@@ -441,6 +441,83 @@ export function AppShell() {
441441
[queryClient],
442442
);
443443

444+
const handleCreateChannel = React.useCallback(
445+
async ({
446+
description,
447+
name,
448+
visibility,
449+
ttlSeconds,
450+
templateId,
451+
}: {
452+
name: string;
453+
description?: string;
454+
visibility: ChannelVisibility;
455+
ttlSeconds?: number;
456+
templateId?: string;
457+
}) => {
458+
const createdChannel = await createChannelMutation.mutateAsync({
459+
name,
460+
description,
461+
channelType: "stream",
462+
visibility,
463+
ttlSeconds,
464+
});
465+
466+
await applyCanvas(templateId, createdChannel.id, name);
467+
await goChannel(createdChannel.id);
468+
void applyAgents(templateId, createdChannel.id);
469+
},
470+
[applyAgents, applyCanvas, createChannelMutation, goChannel],
471+
);
472+
473+
const handleCreateForum = React.useCallback(
474+
async ({
475+
description,
476+
name,
477+
visibility,
478+
ttlSeconds,
479+
templateId,
480+
}: {
481+
name: string;
482+
description?: string;
483+
visibility: ChannelVisibility;
484+
ttlSeconds?: number;
485+
templateId?: string;
486+
}) => {
487+
const createdForum = await createForumMutation.mutateAsync({
488+
name,
489+
description,
490+
channelType: "forum",
491+
visibility,
492+
ttlSeconds,
493+
});
494+
495+
await applyCanvas(templateId, createdForum.id, name);
496+
await goChannel(createdForum.id);
497+
void applyAgents(templateId, createdForum.id);
498+
},
499+
[applyAgents, applyCanvas, createForumMutation, goChannel],
500+
);
501+
502+
// The channel browser can create either a stream or a forum depending on
503+
// which section opened it. Route to the matching handler.
504+
const handleBrowseChannelCreate = React.useCallback(
505+
async (input: {
506+
name: string;
507+
description?: string;
508+
visibility: ChannelVisibility;
509+
ttlSeconds?: number;
510+
templateId?: string;
511+
}) => {
512+
if (browseDialogType === "forum") {
513+
await handleCreateForum(input);
514+
} else {
515+
await handleCreateChannel(input);
516+
}
517+
},
518+
[browseDialogType, handleCreateChannel, handleCreateForum],
519+
);
520+
444521
const handleHideDm = React.useCallback(
445522
async (channelId: string) => {
446523
try {
@@ -779,54 +856,8 @@ export function AppShell() {
779856
onCreateAgent={() => requestOpenCreateAgent()}
780857
selfPresenceStatus={presenceSession.currentStatus}
781858
communities={communitiesHook.communities}
782-
onCreateChannel={async ({
783-
description,
784-
name,
785-
visibility,
786-
ttlSeconds,
787-
templateId,
788-
}) => {
789-
const createdChannel =
790-
await createChannelMutation.mutateAsync({
791-
name,
792-
description,
793-
channelType: "stream",
794-
visibility,
795-
ttlSeconds,
796-
});
797-
798-
await applyCanvas(
799-
templateId,
800-
createdChannel.id,
801-
name,
802-
);
803-
await goChannel(createdChannel.id);
804-
void applyAgents(templateId, createdChannel.id);
805-
}}
806-
onCreateForum={async ({
807-
description,
808-
name,
809-
visibility,
810-
ttlSeconds,
811-
templateId,
812-
}) => {
813-
const createdForum =
814-
await createForumMutation.mutateAsync({
815-
name,
816-
description,
817-
channelType: "forum",
818-
visibility,
819-
ttlSeconds,
820-
});
821-
822-
await applyCanvas(
823-
templateId,
824-
createdForum.id,
825-
name,
826-
);
827-
await goChannel(createdForum.id);
828-
void applyAgents(templateId, createdForum.id);
829-
}}
859+
onCreateChannel={handleCreateChannel}
860+
onCreateForum={handleCreateForum}
830861
onHideDm={handleHideDm}
831862
onMarkAllChannelsRead={markAllChannelsRead}
832863
onMarkChannelRead={markChannelRead}
@@ -913,7 +944,12 @@ export function AppShell() {
913944
channels={channels}
914945
currentPubkey={identityQuery.data?.pubkey}
915946
isChannelManagementOpen={isChannelManagementOpen}
947+
isCreatingBrowseChannel={
948+
createChannelMutation.isPending ||
949+
createForumMutation.isPending
950+
}
916951
onBrowseChannelJoin={handleBrowseChannelJoin}
952+
onBrowseChannelCreate={handleBrowseChannelCreate}
917953
onBrowseDialogOpenChange={handleBrowseDialogOpenChange}
918954
onChannelManagementOpenChange={(open) => {
919955
setIsChannelManagementOpen(open);

‎desktop/src/app/AppShellOverlays.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from "react";
22

33
import type { Channel } from "@/shared/api/types";
4+
import type { CreateChannelInput } from "@/features/sidebar/lib/useCreateChannelForm";
45
import { useDeferredModalOpen } from "@/shared/ui/deferredModalOpen";
56

67
const ChannelBrowserDialog = React.lazy(async () => {
@@ -21,7 +22,9 @@ type AppShellOverlaysProps = {
2122
channels: Channel[];
2223
currentPubkey?: string;
2324
isChannelManagementOpen: boolean;
25+
isCreatingBrowseChannel?: boolean;
2426
onBrowseChannelJoin: (channelId: string) => Promise<void>;
27+
onBrowseChannelCreate?: (input: CreateChannelInput) => Promise<void>;
2528
onBrowseDialogOpenChange: (open: boolean) => void;
2629
onChannelManagementOpenChange: (open: boolean) => void;
2730
onDeleteActiveChannel: () => void;
@@ -34,7 +37,9 @@ export function AppShellOverlays({
3437
channels,
3538
currentPubkey,
3639
isChannelManagementOpen,
40+
isCreatingBrowseChannel,
3741
onBrowseChannelJoin,
42+
onBrowseChannelCreate,
3843
onBrowseDialogOpenChange,
3944
onChannelManagementOpenChange,
4045
onDeleteActiveChannel,
@@ -67,6 +72,8 @@ export function AppShellOverlays({
6772
<ChannelBrowserDialog
6873
channels={channels}
6974
channelTypeFilter={renderedBrowseDialogType ?? browseDialogType}
75+
isCreatingChannel={isCreatingBrowseChannel}
76+
onCreateChannel={onBrowseChannelCreate}
7077
onJoinChannel={onBrowseChannelJoin}
7178
onOpenChange={onBrowseDialogOpenChange}
7279
onSelectChannel={onSelectChannel}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import { scoreChannelMatch, scoreChannelName } from "./channelSearchScore.ts";
5+
6+
test("scoreChannelName: empty query matches everything at top score", () => {
7+
assert.equal(scoreChannelName("release-notes", ""), 0);
8+
});
9+
10+
test("scoreChannelName: exact name beats prefix beats word matches", () => {
11+
const exact = scoreChannelName("general", "general");
12+
const prefix = scoreChannelName("general-chat", "general");
13+
const wordExact = scoreChannelName("team-general", "general");
14+
assert.ok(exact < prefix, "exact should rank above prefix");
15+
assert.ok(prefix < wordExact, "prefix should rank above later-word match");
16+
});
17+
18+
test("scoreChannelName: matches a later whole word", () => {
19+
// "notes" is the second word of "release-notes"
20+
assert.notEqual(scoreChannelName("release-notes", "notes"), null);
21+
});
22+
23+
test("scoreChannelName: matches a later word prefix", () => {
24+
assert.notEqual(scoreChannelName("release-notes", "not"), null);
25+
});
26+
27+
test("scoreChannelName: plain substring still matches", () => {
28+
assert.notEqual(scoreChannelName("release-notes", "ease"), null);
29+
});
30+
31+
test("scoreChannelName: collapsing separators matches 'releasenotes'", () => {
32+
// The core pain point: dropping the dash should still find the channel.
33+
const score = scoreChannelName("release-notes", "releasenotes");
34+
assert.notEqual(score, null);
35+
});
36+
37+
test("scoreChannelName: partial across the separator ('releasenot')", () => {
38+
assert.notEqual(scoreChannelName("release-notes", "releasenot"), null);
39+
});
40+
41+
test("scoreChannelName: subsequence matches 'reln'", () => {
42+
// r-e-l...n appears in order inside "release-notes"
43+
assert.notEqual(scoreChannelName("release-notes", "reln"), null);
44+
});
45+
46+
test("scoreChannelName: subsequence works across underscores and dots", () => {
47+
assert.notEqual(scoreChannelName("build_and_deploy", "bd"), null);
48+
assert.notEqual(scoreChannelName("v1.2.release", "vrel"), null);
49+
});
50+
51+
test("scoreChannelName: single-char subsequence noise is rejected", () => {
52+
// A lone char that isn't a prefix/substring should NOT fuzzy-match, or every
53+
// channel containing that letter would show up.
54+
assert.equal(scoreChannelName("release-notes", "z"), null);
55+
// "x" doesn't appear at all
56+
assert.equal(scoreChannelName("release-notes", "x"), null);
57+
});
58+
59+
test("scoreChannelName: unrelated query returns null", () => {
60+
assert.equal(scoreChannelName("release-notes", "budget"), null);
61+
});
62+
63+
test("scoreChannelName: subsequence requires correct order", () => {
64+
// "sn" — 's' then 'n' — is NOT in order in "release-notes" (n comes... yes it
65+
// is: relea-s-e-n-otes). Use a genuinely out-of-order example instead.
66+
assert.equal(scoreChannelName("abc", "ca"), null);
67+
});
68+
69+
test("scoreChannelName: better matches score lower than fuzzier ones", () => {
70+
const prefix = scoreChannelName("release-notes", "release");
71+
const collapsed = scoreChannelName("release-notes", "releasenotes");
72+
const subsequence = scoreChannelName("release-notes", "reln");
73+
assert.ok(prefix < collapsed, "prefix beats collapsed-separator match");
74+
assert.ok(collapsed < subsequence, "collapsed beats subsequence match");
75+
});
76+
77+
test("scoreChannelMatch: name match outranks description match", () => {
78+
const nameHit = scoreChannelMatch(
79+
{ name: "release-notes", description: "" },
80+
"release",
81+
);
82+
const descHit = scoreChannelMatch(
83+
{ name: "random", description: "release coordination" },
84+
"release",
85+
);
86+
assert.ok(
87+
nameHit !== null && descHit !== null && nameHit < descHit,
88+
"a name match should rank above a description-only match",
89+
);
90+
});
91+
92+
test("scoreChannelMatch: description only does plain substring, not fuzzy", () => {
93+
// "reln" should not fuzzy-match the description.
94+
assert.equal(
95+
scoreChannelMatch({ name: "random", description: "release notes" }, "reln"),
96+
null,
97+
);
98+
// But a real substring in the description matches.
99+
assert.notEqual(
100+
scoreChannelMatch(
101+
{ name: "random", description: "release notes" },
102+
"notes",
103+
),
104+
null,
105+
);
106+
});
107+
108+
test("scoreChannelMatch: no match anywhere returns null", () => {
109+
assert.equal(
110+
scoreChannelMatch({ name: "general", description: "chat" }, "budget"),
111+
null,
112+
);
113+
});

0 commit comments

Comments
 (0)