Skip to content

Commit 592dd35

Browse files
committed
refactor: share directory config helpers
1 parent b6b5e5c commit 592dd35

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

src/channels/plugins/directory-config-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function resolveDirectoryLimit(limit?: number | null): number | undefined {
88
return typeof limit === "number" && limit > 0 ? limit : undefined;
99
}
1010

11-
function applyDirectoryQueryAndLimit(
11+
export function applyDirectoryQueryAndLimit(
1212
ids: string[],
1313
params: { query?: string | null; limit?: number | null },
1414
): string[] {
@@ -18,7 +18,7 @@ function applyDirectoryQueryAndLimit(
1818
return typeof limit === "number" ? filtered.slice(0, limit) : filtered;
1919
}
2020

21-
function toDirectoryEntries(kind: "user" | "group", ids: string[]): ChannelDirectoryEntry[] {
21+
export function toDirectoryEntries(kind: "user" | "group", ids: string[]): ChannelDirectoryEntry[] {
2222
return ids.map((id) => ({ kind, id }) as const);
2323
}
2424

src/channels/plugins/directory-config.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { inspectSlackAccount } from "../../slack/account-inspect.js";
55
import { inspectTelegramAccount } from "../../telegram/account-inspect.js";
66
import { resolveWhatsAppAccount } from "../../web/accounts.js";
77
import { isWhatsAppGroupJid, normalizeWhatsAppTarget } from "../../whatsapp/normalize.js";
8+
import { applyDirectoryQueryAndLimit, toDirectoryEntries } from "./directory-config-helpers.js";
89
import { normalizeSlackMessagingTarget } from "./normalize/slack.js";
910
import type { ChannelDirectoryEntry } from "./types.js";
1011

@@ -54,25 +55,6 @@ function normalizeTrimmedSet(
5455
.filter((id): id is string => Boolean(id));
5556
}
5657

57-
function resolveDirectoryQuery(query?: string | null): string {
58-
return query?.trim().toLowerCase() || "";
59-
}
60-
61-
function resolveDirectoryLimit(limit?: number | null): number | undefined {
62-
return typeof limit === "number" && limit > 0 ? limit : undefined;
63-
}
64-
65-
function applyDirectoryQueryAndLimit(ids: string[], params: DirectoryConfigParams): string[] {
66-
const q = resolveDirectoryQuery(params.query);
67-
const limit = resolveDirectoryLimit(params.limit);
68-
const filtered = ids.filter((id) => (q ? id.toLowerCase().includes(q) : true));
69-
return typeof limit === "number" ? filtered.slice(0, limit) : filtered;
70-
}
71-
72-
function toDirectoryEntries(kind: "user" | "group", ids: string[]): ChannelDirectoryEntry[] {
73-
return ids.map((id) => ({ kind, id }) as const);
74-
}
75-
7658
export async function listSlackDirectoryPeersFromConfig(
7759
params: DirectoryConfigParams,
7860
): Promise<ChannelDirectoryEntry[]> {

0 commit comments

Comments
 (0)