






















@@ -59,6 +59,10 @@ import type { MattermostConfig } from "./types.js";
59596060const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime.js"));
616162+type MattermostDirectoryListParams = Parameters<
63+NonNullable<NonNullable<ChannelPlugin["directory"]>["listGroups"]>
64+>[0];
65+6266const mattermostSecurityAdapter = createRestrictSendersChannelSecurity<ResolvedMattermostAccount>({
6367channelKey: "mattermost",
6468resolveDmPolicy: (account) => account.config.dmPolicy,
@@ -110,6 +114,34 @@ function describeMattermostMessageTool({
110114};
111115}
112116117+function hasConfiguredMattermostDirectoryAccount({
118+ cfg,
119+ accountId,
120+}: Pick<MattermostDirectoryListParams, "cfg" | "accountId">): boolean {
121+const accounts = accountId
122+ ? [resolveMattermostAccount({ cfg, accountId })]
123+ : listMattermostAccountIds(cfg).map((listedAccountId) =>
124+resolveMattermostAccount({ cfg, accountId: listedAccountId }),
125+);
126+return accounts.some((account) =>
127+Boolean(account.enabled && account.botToken?.trim() && account.baseUrl?.trim()),
128+);
129+}
130+131+async function listMattermostDirectoryGroups(params: MattermostDirectoryListParams) {
132+if (!hasConfiguredMattermostDirectoryAccount(params)) {
133+return [];
134+}
135+return (await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params);
136+}
137+138+async function listMattermostDirectoryPeers(params: MattermostDirectoryListParams) {
139+if (!hasConfiguredMattermostDirectoryAccount(params)) {
140+return [];
141+}
142+return (await loadMattermostChannelRuntime()).listMattermostDirectoryPeers(params);
143+}
144+113145const mattermostMessageActions: ChannelMessageActionAdapter = {
114146describeMessageTool: describeMattermostMessageTool,
115147supportsAction: ({ action }) => {
@@ -379,14 +411,10 @@ export const mattermostPlugin: ChannelPlugin<ResolvedMattermostAccount> = create
379411 collectRuntimeConfigAssignments,
380412},
381413directory: createChannelDirectoryAdapter({
382-listGroups: async (params) =>
383-(await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params),
384-listGroupsLive: async (params) =>
385-(await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params),
386-listPeers: async (params) =>
387-(await loadMattermostChannelRuntime()).listMattermostDirectoryPeers(params),
388-listPeersLive: async (params) =>
389-(await loadMattermostChannelRuntime()).listMattermostDirectoryPeers(params),
414+listGroups: listMattermostDirectoryGroups,
415+listGroupsLive: listMattermostDirectoryGroups,
416+listPeers: listMattermostDirectoryPeers,
417+listPeersLive: listMattermostDirectoryPeers,
390418}),
391419messaging: {
392420targetPrefixes: ["mattermost"],
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。