mirror of https://github.com/openclaw/openclaw.git
refactor: share directory config helpers
This commit is contained in:
parent
b6b5e5caac
commit
592dd35ce9
|
|
@ -8,7 +8,7 @@ function resolveDirectoryLimit(limit?: number | null): number | undefined {
|
|||
return typeof limit === "number" && limit > 0 ? limit : undefined;
|
||||
}
|
||||
|
||||
function applyDirectoryQueryAndLimit(
|
||||
export function applyDirectoryQueryAndLimit(
|
||||
ids: string[],
|
||||
params: { query?: string | null; limit?: number | null },
|
||||
): string[] {
|
||||
|
|
@ -18,7 +18,7 @@ function applyDirectoryQueryAndLimit(
|
|||
return typeof limit === "number" ? filtered.slice(0, limit) : filtered;
|
||||
}
|
||||
|
||||
function toDirectoryEntries(kind: "user" | "group", ids: string[]): ChannelDirectoryEntry[] {
|
||||
export function toDirectoryEntries(kind: "user" | "group", ids: string[]): ChannelDirectoryEntry[] {
|
||||
return ids.map((id) => ({ kind, id }) as const);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { inspectSlackAccount } from "../../slack/account-inspect.js";
|
|||
import { inspectTelegramAccount } from "../../telegram/account-inspect.js";
|
||||
import { resolveWhatsAppAccount } from "../../web/accounts.js";
|
||||
import { isWhatsAppGroupJid, normalizeWhatsAppTarget } from "../../whatsapp/normalize.js";
|
||||
import { applyDirectoryQueryAndLimit, toDirectoryEntries } from "./directory-config-helpers.js";
|
||||
import { normalizeSlackMessagingTarget } from "./normalize/slack.js";
|
||||
import type { ChannelDirectoryEntry } from "./types.js";
|
||||
|
||||
|
|
@ -54,25 +55,6 @@ function normalizeTrimmedSet(
|
|||
.filter((id): id is string => Boolean(id));
|
||||
}
|
||||
|
||||
function resolveDirectoryQuery(query?: string | null): string {
|
||||
return query?.trim().toLowerCase() || "";
|
||||
}
|
||||
|
||||
function resolveDirectoryLimit(limit?: number | null): number | undefined {
|
||||
return typeof limit === "number" && limit > 0 ? limit : undefined;
|
||||
}
|
||||
|
||||
function applyDirectoryQueryAndLimit(ids: string[], params: DirectoryConfigParams): string[] {
|
||||
const q = resolveDirectoryQuery(params.query);
|
||||
const limit = resolveDirectoryLimit(params.limit);
|
||||
const filtered = ids.filter((id) => (q ? id.toLowerCase().includes(q) : true));
|
||||
return typeof limit === "number" ? filtered.slice(0, limit) : filtered;
|
||||
}
|
||||
|
||||
function toDirectoryEntries(kind: "user" | "group", ids: string[]): ChannelDirectoryEntry[] {
|
||||
return ids.map((id) => ({ kind, id }) as const);
|
||||
}
|
||||
|
||||
export async function listSlackDirectoryPeersFromConfig(
|
||||
params: DirectoryConfigParams,
|
||||
): Promise<ChannelDirectoryEntry[]> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue