mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-09 11:34:16 +00:00
refactor(imessage): share direct chat normalization
This commit is contained in:
@@ -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" }>,
|
||||
|
||||
@@ -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;-;"]) {
|
||||
|
||||
Reference in New Issue
Block a user