refactor(imessage): share direct chat normalization

This commit is contained in:
Vincent Koc
2026-06-22 13:55:36 +08:00
parent 0111afe9e2
commit cc89e155c3
2 changed files with 6 additions and 14 deletions

View File

@@ -12,7 +12,10 @@ import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
import { appendIMessageCliStderrTail, appendIMessageCliStdout } from "./cli-output.js";
import { createIMessageRpcClient } from "./client.js";
import { extractMarkdownFormatRuns } from "./markdown-format.js";
import { resolveIMessageMessageId as resolveIMessageMessageIdImpl } from "./monitor-reply-cache.js";
import {
normalizeDirectChatIdentifier,
resolveIMessageMessageId as resolveIMessageMessageIdImpl,
} from "./monitor-reply-cache.js";
import type { IMessageTarget } from "./targets.js";
type CliRunOptions = {
@@ -115,7 +118,7 @@ function chatListCacheSet(
* forms — the action surface synthesizes `iMessage;-;<phone>` from a
* handle target, while imsg's chats.list returns `identifier: <phone>`
* and `guid: any;-;<phone>`. Comparing the raw strings would falsely
* miss the match. Mirror of the same helper in monitor-reply-cache.ts.
* miss the match.
*/
export function normalizeDirectChatIdentifierForTest(raw: string): string {
return normalizeDirectChatIdentifier(raw);
@@ -128,17 +131,6 @@ export function findChatGuidForTest(
return findChatGuid(chats, target);
}
function normalizeDirectChatIdentifier(raw: string): string {
const trimmed = raw.trim();
const lowered = trimmed.toLowerCase();
for (const prefix of ["imessage;-;", "sms;-;", "any;-;"]) {
if (lowered.startsWith(prefix)) {
return trimmed.slice(prefix.length);
}
}
return trimmed;
}
function findChatGuid(
chats: readonly Record<string, unknown>[],
target: Extract<IMessageTarget, { kind: "chat_id" | "chat_identifier" }>,

View File

@@ -256,7 +256,7 @@ function hasChatScope(ctx?: IMessageChatContext): boolean {
* so comparing the raw strings would falsely flag the same chat as a
* cross-chat target. Normalize both sides to the bare suffix.
*/
function normalizeDirectChatIdentifier(raw: string): string {
export function normalizeDirectChatIdentifier(raw: string): string {
const trimmed = raw.trim();
const lowered = trimmed.toLowerCase();
for (const prefix of ["imessage;-;", "sms;-;", "any;-;"]) {