Skip to content

Commit cc89e15

Browse files
committed
refactor(imessage): share direct chat normalization
1 parent 0111afe commit cc89e15

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

extensions/imessage/src/actions.runtime.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
1212
import { appendIMessageCliStderrTail, appendIMessageCliStdout } from "./cli-output.js";
1313
import { createIMessageRpcClient } from "./client.js";
1414
import { extractMarkdownFormatRuns } from "./markdown-format.js";
15-
import { resolveIMessageMessageId as resolveIMessageMessageIdImpl } from "./monitor-reply-cache.js";
15+
import {
16+
normalizeDirectChatIdentifier,
17+
resolveIMessageMessageId as resolveIMessageMessageIdImpl,
18+
} from "./monitor-reply-cache.js";
1619
import type { IMessageTarget } from "./targets.js";
1720

1821
type CliRunOptions = {
@@ -115,7 +118,7 @@ function chatListCacheSet(
115118
* forms — the action surface synthesizes `iMessage;-;<phone>` from a
116119
* handle target, while imsg's chats.list returns `identifier: <phone>`
117120
* and `guid: any;-;<phone>`. Comparing the raw strings would falsely
118-
* miss the match. Mirror of the same helper in monitor-reply-cache.ts.
121+
* miss the match.
119122
*/
120123
export function normalizeDirectChatIdentifierForTest(raw: string): string {
121124
return normalizeDirectChatIdentifier(raw);
@@ -128,17 +131,6 @@ export function findChatGuidForTest(
128131
return findChatGuid(chats, target);
129132
}
130133

131-
function normalizeDirectChatIdentifier(raw: string): string {
132-
const trimmed = raw.trim();
133-
const lowered = trimmed.toLowerCase();
134-
for (const prefix of ["imessage;-;", "sms;-;", "any;-;"]) {
135-
if (lowered.startsWith(prefix)) {
136-
return trimmed.slice(prefix.length);
137-
}
138-
}
139-
return trimmed;
140-
}
141-
142134
function findChatGuid(
143135
chats: readonly Record<string, unknown>[],
144136
target: Extract<IMessageTarget, { kind: "chat_id" | "chat_identifier" }>,

extensions/imessage/src/monitor-reply-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function hasChatScope(ctx?: IMessageChatContext): boolean {
256256
* so comparing the raw strings would falsely flag the same chat as a
257257
* cross-chat target. Normalize both sides to the bare suffix.
258258
*/
259-
function normalizeDirectChatIdentifier(raw: string): string {
259+
export function normalizeDirectChatIdentifier(raw: string): string {
260260
const trimmed = raw.trim();
261261
const lowered = trimmed.toLowerCase();
262262
for (const prefix of ["imessage;-;", "sms;-;", "any;-;"]) {

0 commit comments

Comments
 (0)