


















@@ -50,7 +50,44 @@ function stripProviderPrefix(raw: string, channel: string): string {
5050}
51515252function stripKindPrefix(raw: string): string {
53-return raw.replace(/^(user|channel|group|conversation|room|dm):/i, "").trim();
53+return raw.replace(/^(user|channel|group|conversation|room|dm|thread):/i, "").trim();
54+}
55+56+const FALLBACK_TARGET_KIND_PREFIXES: Array<{ kind: ChatType; pattern: RegExp }> = [
57+{ kind: "direct", pattern: /^(user:|dm:)/i },
58+{ kind: "channel", pattern: /^(channel:|conversation:|thread:)/i },
59+{ kind: "group", pattern: /^(group:|room:)/i },
60+];
61+62+function normalizeInferredPeerKind(value: ChatType | undefined): ChatType | undefined {
63+return value === "direct" || value === "group" || value === "channel" ? value : undefined;
64+}
65+66+function inferPeerKindFromPlugin(params: {
67+plugin: ReturnType<typeof resolveOutboundChannelPlugin>;
68+targets: readonly string[];
69+}): ChatType | undefined {
70+for (const target of params.targets) {
71+const inferred = normalizeInferredPeerKind(
72+params.plugin?.messaging?.parseExplicitTarget?.({ raw: target })?.chatType ??
73+params.plugin?.messaging?.inferTargetChatType?.({ to: target }),
74+);
75+if (inferred) {
76+return inferred;
77+}
78+}
79+return undefined;
80+}
81+82+function inferPeerKindFromFallbackPrefixes(targets: readonly string[]): ChatType | undefined {
83+for (const target of targets) {
84+for (const fallback of FALLBACK_TARGET_KIND_PREFIXES) {
85+if (fallback.pattern.test(target)) {
86+return fallback.kind;
87+}
88+}
89+}
90+return undefined;
5491}
55925693function inferPeerKind(params: {
@@ -81,22 +118,11 @@ function inferPeerKind(params: {
81118(target, index, values): target is string =>
82119Boolean(target) && values.indexOf(target) === index,
83120);
84-for (const target of targets) {
85-const inferred = plugin?.messaging?.inferTargetChatType?.({ to: target });
86-if (inferred === "direct" || inferred === "group" || inferred === "channel") {
87-return inferred;
88-}
89-}
90-if (targets.some((target) => /^(@|<@!?|user:|dm:|c2c:|users\/)/i.test(target))) {
91-return "direct";
92-}
93-if (targets.some((target) => /^(channel:|conversation:|thread:|channels\/)/i.test(target))) {
94-return "channel";
95-}
96-if (targets.some((target) => /^(#|group:|room:|spaces\/|groups\/|rooms\/)/i.test(target))) {
97-return "group";
98-}
99-return "direct";
121+return (
122+inferPeerKindFromPlugin({ plugin, targets }) ??
123+inferPeerKindFromFallbackPrefixes(targets) ??
124+"direct"
125+);
100126}
101127102128function resolveFallbackSession(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。