Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desktop/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default defineConfig({
"**/channel-shared-header-backdrop.spec.ts",
"**/badge.spec.ts",
"**/channel-browser.spec.ts",
"**/channel-add-screenshots.spec.ts",
"**/messaging.spec.ts",
"**/custom-emoji.spec.ts",
"**/profile-custom-emoji-status.spec.ts",
Expand Down
134 changes: 85 additions & 49 deletions desktop/src/app/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import { useRelayAutoHeal } from "@/shared/api/useRelayAutoHeal";
import { useDeferredStartup } from "@/shared/hooks/useDeferredStartup";
import { useWebviewScrollBoundaryLock } from "@/shared/hooks/useWebviewScrollBoundaryLock";
import { joinChannel } from "@/shared/api/tauri";
import type { SearchHit } from "@/shared/api/types";
import type { ChannelVisibility, SearchHit } from "@/shared/api/types";
import { ChannelNavigationProvider } from "@/shared/context/ChannelNavigationContext";
import { MainInsetProvider } from "@/shared/layout/MainInsetContext";
import { chromeCssVarDefaults } from "@/shared/layout/chromeLayout";
Expand Down Expand Up @@ -441,6 +441,83 @@ export function AppShell() {
[queryClient],
);

const handleCreateChannel = React.useCallback(
async ({
description,
name,
visibility,
ttlSeconds,
templateId,
}: {
name: string;
description?: string;
visibility: ChannelVisibility;
ttlSeconds?: number;
templateId?: string;
}) => {
const createdChannel = await createChannelMutation.mutateAsync({
name,
description,
channelType: "stream",
visibility,
ttlSeconds,
});

await applyCanvas(templateId, createdChannel.id, name);
await goChannel(createdChannel.id);
void applyAgents(templateId, createdChannel.id);
},
[applyAgents, applyCanvas, createChannelMutation, goChannel],
);

const handleCreateForum = React.useCallback(
async ({
description,
name,
visibility,
ttlSeconds,
templateId,
}: {
name: string;
description?: string;
visibility: ChannelVisibility;
ttlSeconds?: number;
templateId?: string;
}) => {
const createdForum = await createForumMutation.mutateAsync({
name,
description,
channelType: "forum",
visibility,
ttlSeconds,
});

await applyCanvas(templateId, createdForum.id, name);
await goChannel(createdForum.id);
void applyAgents(templateId, createdForum.id);
},
[applyAgents, applyCanvas, createForumMutation, goChannel],
);

// The channel browser can create either a stream or a forum depending on
// which section opened it. Route to the matching handler.
const handleBrowseChannelCreate = React.useCallback(
async (input: {
name: string;
description?: string;
visibility: ChannelVisibility;
ttlSeconds?: number;
templateId?: string;
}) => {
if (browseDialogType === "forum") {
await handleCreateForum(input);
} else {
await handleCreateChannel(input);
}
},
[browseDialogType, handleCreateChannel, handleCreateForum],
);

const handleHideDm = React.useCallback(
async (channelId: string) => {
try {
Expand Down Expand Up @@ -779,54 +856,8 @@ export function AppShell() {
onCreateAgent={() => requestOpenCreateAgent()}
selfPresenceStatus={presenceSession.currentStatus}
communities={communitiesHook.communities}
onCreateChannel={async ({
description,
name,
visibility,
ttlSeconds,
templateId,
}) => {
const createdChannel =
await createChannelMutation.mutateAsync({
name,
description,
channelType: "stream",
visibility,
ttlSeconds,
});

await applyCanvas(
templateId,
createdChannel.id,
name,
);
await goChannel(createdChannel.id);
void applyAgents(templateId, createdChannel.id);
}}
onCreateForum={async ({
description,
name,
visibility,
ttlSeconds,
templateId,
}) => {
const createdForum =
await createForumMutation.mutateAsync({
name,
description,
channelType: "forum",
visibility,
ttlSeconds,
});

await applyCanvas(
templateId,
createdForum.id,
name,
);
await goChannel(createdForum.id);
void applyAgents(templateId, createdForum.id);
}}
onCreateChannel={handleCreateChannel}
onCreateForum={handleCreateForum}
onHideDm={handleHideDm}
onMarkAllChannelsRead={markAllChannelsRead}
onMarkChannelRead={markChannelRead}
Expand Down Expand Up @@ -913,7 +944,12 @@ export function AppShell() {
channels={channels}
currentPubkey={identityQuery.data?.pubkey}
isChannelManagementOpen={isChannelManagementOpen}
isCreatingBrowseChannel={
createChannelMutation.isPending ||
createForumMutation.isPending
}
onBrowseChannelJoin={handleBrowseChannelJoin}
onBrowseChannelCreate={handleBrowseChannelCreate}
onBrowseDialogOpenChange={handleBrowseDialogOpenChange}
onChannelManagementOpenChange={(open) => {
setIsChannelManagementOpen(open);
Expand Down
7 changes: 7 additions & 0 deletions desktop/src/app/AppShellOverlays.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react";

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

const ChannelBrowserDialog = React.lazy(async () => {
Expand All @@ -21,7 +22,9 @@ type AppShellOverlaysProps = {
channels: Channel[];
currentPubkey?: string;
isChannelManagementOpen: boolean;
isCreatingBrowseChannel?: boolean;
onBrowseChannelJoin: (channelId: string) => Promise<void>;
onBrowseChannelCreate?: (input: CreateChannelInput) => Promise<void>;
onBrowseDialogOpenChange: (open: boolean) => void;
onChannelManagementOpenChange: (open: boolean) => void;
onDeleteActiveChannel: () => void;
Expand All @@ -34,7 +37,9 @@ export function AppShellOverlays({
channels,
currentPubkey,
isChannelManagementOpen,
isCreatingBrowseChannel,
onBrowseChannelJoin,
onBrowseChannelCreate,
onBrowseDialogOpenChange,
onChannelManagementOpenChange,
onDeleteActiveChannel,
Expand Down Expand Up @@ -67,6 +72,8 @@ export function AppShellOverlays({
<ChannelBrowserDialog
channels={channels}
channelTypeFilter={renderedBrowseDialogType ?? browseDialogType}
isCreatingChannel={isCreatingBrowseChannel}
onCreateChannel={onBrowseChannelCreate}
onJoinChannel={onBrowseChannelJoin}
onOpenChange={onBrowseDialogOpenChange}
onSelectChannel={onSelectChannel}
Expand Down
113 changes: 113 additions & 0 deletions desktop/src/features/channels/lib/channelSearchScore.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import assert from "node:assert/strict";
import test from "node:test";

import { scoreChannelMatch, scoreChannelName } from "./channelSearchScore.ts";

test("scoreChannelName: empty query matches everything at top score", () => {
assert.equal(scoreChannelName("release-notes", ""), 0);
});

test("scoreChannelName: exact name beats prefix beats word matches", () => {
const exact = scoreChannelName("general", "general");
const prefix = scoreChannelName("general-chat", "general");
const wordExact = scoreChannelName("team-general", "general");
assert.ok(exact < prefix, "exact should rank above prefix");
assert.ok(prefix < wordExact, "prefix should rank above later-word match");
});

test("scoreChannelName: matches a later whole word", () => {
// "notes" is the second word of "release-notes"
assert.notEqual(scoreChannelName("release-notes", "notes"), null);
});

test("scoreChannelName: matches a later word prefix", () => {
assert.notEqual(scoreChannelName("release-notes", "not"), null);
});

test("scoreChannelName: plain substring still matches", () => {
assert.notEqual(scoreChannelName("release-notes", "ease"), null);
});

test("scoreChannelName: collapsing separators matches 'releasenotes'", () => {
// The core pain point: dropping the dash should still find the channel.
const score = scoreChannelName("release-notes", "releasenotes");
assert.notEqual(score, null);
});

test("scoreChannelName: partial across the separator ('releasenot')", () => {
assert.notEqual(scoreChannelName("release-notes", "releasenot"), null);
});

test("scoreChannelName: subsequence matches 'reln'", () => {
// r-e-l...n appears in order inside "release-notes"
assert.notEqual(scoreChannelName("release-notes", "reln"), null);
});

test("scoreChannelName: subsequence works across underscores and dots", () => {
assert.notEqual(scoreChannelName("build_and_deploy", "bd"), null);
assert.notEqual(scoreChannelName("v1.2.release", "vrel"), null);
});

test("scoreChannelName: single-char subsequence noise is rejected", () => {
// A lone char that isn't a prefix/substring should NOT fuzzy-match, or every
// channel containing that letter would show up.
assert.equal(scoreChannelName("release-notes", "z"), null);
// "x" doesn't appear at all
assert.equal(scoreChannelName("release-notes", "x"), null);
});

test("scoreChannelName: unrelated query returns null", () => {
assert.equal(scoreChannelName("release-notes", "budget"), null);
});

test("scoreChannelName: subsequence requires correct order", () => {
// "sn" — 's' then 'n' — is NOT in order in "release-notes" (n comes... yes it
// is: relea-s-e-n-otes). Use a genuinely out-of-order example instead.
assert.equal(scoreChannelName("abc", "ca"), null);
});

test("scoreChannelName: better matches score lower than fuzzier ones", () => {
const prefix = scoreChannelName("release-notes", "release");
const collapsed = scoreChannelName("release-notes", "releasenotes");
const subsequence = scoreChannelName("release-notes", "reln");
assert.ok(prefix < collapsed, "prefix beats collapsed-separator match");
assert.ok(collapsed < subsequence, "collapsed beats subsequence match");
});

test("scoreChannelMatch: name match outranks description match", () => {
const nameHit = scoreChannelMatch(
{ name: "release-notes", description: "" },
"release",
);
const descHit = scoreChannelMatch(
{ name: "random", description: "release coordination" },
"release",
);
assert.ok(
nameHit !== null && descHit !== null && nameHit < descHit,
"a name match should rank above a description-only match",
);
});

test("scoreChannelMatch: description only does plain substring, not fuzzy", () => {
// "reln" should not fuzzy-match the description.
assert.equal(
scoreChannelMatch({ name: "random", description: "release notes" }, "reln"),
null,
);
// But a real substring in the description matches.
assert.notEqual(
scoreChannelMatch(
{ name: "random", description: "release notes" },
"notes",
),
null,
);
});

test("scoreChannelMatch: no match anywhere returns null", () => {
assert.equal(
scoreChannelMatch({ name: "general", description: "chat" }, "budget"),
null,
);
});
Loading