Skip to content

Commit d0bc08a

Browse files
tyler6204steipete
authored andcommitted
fix: reduce redundant envelope formatting for iMessage and Signal
1 parent 64d21f5 commit d0bc08a

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

src/auto-reply/reply/inbound-sender-meta.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function hasSenderMetaLine(body: string, ctx: MsgContext): boolean {
3333
if (candidates.length === 0) return false;
3434
return candidates.some((candidate) => {
3535
const escaped = escapeRegExp(candidate);
36-
const pattern = new RegExp(`(^|\\n)${escaped}:\\s`, "i");
36+
// Check for sender at start of line OR after envelope header bracket
37+
const pattern = new RegExp(`(^|\\n|\\]\\s*)${escaped}:\\s`, "i");
3738
return pattern.test(body);
3839
});
3940
}

src/imessage/monitor.skips-group-messages-without-mention-by-default.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,9 @@ describe("monitorIMessageProvider", () => {
381381
expect(replyMock).toHaveBeenCalledOnce();
382382
const ctx = replyMock.mock.calls[0]?.[0] as { Body?: string; ChatType?: string };
383383
expect(ctx.ChatType).toBe("group");
384-
expect(String(ctx.Body ?? "")).toContain("[from:");
385-
expect(String(ctx.Body ?? "")).toContain("+15550002222");
384+
// Sender should appear as prefix in group messages (no redundant [from:] suffix)
385+
expect(String(ctx.Body ?? "")).toContain("+15550002222:");
386+
expect(String(ctx.Body ?? "")).not.toContain("[from:");
386387

387388
expect(sendMock).toHaveBeenCalledWith(
388389
"chat_id:42",

src/imessage/monitor/monitor-provider.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,8 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
165165
async function handleMessageNow(message: IMessagePayload) {
166166
const senderRaw = message.sender ?? "";
167167
const sender = senderRaw.trim();
168-
if (!sender) {
169-
logVerbose(`imessage: skipping message (no sender), chat_id=${message.chat_id}`);
170-
return;
171-
}
168+
if (!sender) return;
172169
const senderNormalized = normalizeIMessageHandle(sender);
173-
if (!senderNormalized) {
174-
logVerbose(
175-
`imessage: sender normalized to empty, raw="${sender}", chat_id=${message.chat_id}`,
176-
);
177-
}
178170
if (message.is_from_me) return;
179171

180172
const chatId = message.chat_id ?? undefined;
@@ -391,14 +383,13 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
391383
}
392384

393385
const chatTarget = formatIMessageChatTarget(chatId);
386+
// For groups: use chat name or just "Group" (channel "iMessage" is already shown)
387+
// For DMs: show sender, only add id: suffix if raw differs from normalized
394388
const fromLabel = isGroup
395-
? `${message.chat_name || "iMessage Group"} id:${chatId ?? "unknown"}`
396-
: `${senderNormalized} id:${sender}`;
397-
if (isGroup && !senderNormalized) {
398-
logVerbose(
399-
`imessage: group message missing normalized sender, raw="${sender}", chat_id=${chatId}`,
400-
);
401-
}
389+
? `${message.chat_name || "Group"} id:${chatId ?? "unknown"}`
390+
: senderNormalized === sender
391+
? senderNormalized
392+
: `${senderNormalized} id:${sender}`;
402393
const body = formatInboundEnvelope({
403394
channel: "iMessage",
404395
from: fromLabel,

src/signal/monitor/event-handler.inbound-contract.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ describe("signal createSignalEventHandler inbound contract", () => {
6060

6161
expect(capturedCtx).toBeTruthy();
6262
expectInboundContextContract(capturedCtx!);
63-
expect(String(capturedCtx?.Body ?? "")).toContain("[from:");
63+
// Sender should appear as prefix in group messages (no redundant [from:] suffix)
6464
expect(String(capturedCtx?.Body ?? "")).toContain("Alice");
65+
expect(String(capturedCtx?.Body ?? "")).toMatch(/Alice.*:/);
66+
expect(String(capturedCtx?.Body ?? "")).not.toContain("[from:");
6567
});
6668
});

src/signal/monitor/event-handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ export function createSignalEventHandler(deps: SignalEventHandlerDeps) {
6565
};
6666

6767
async function handleSignalInboundMessage(entry: SignalInboundEntry) {
68+
// For groups: use group name or just "Group" (channel "Signal" is already shown)
69+
// For DMs: show sender, only add id: suffix if display differs from name
6870
const fromLabel = entry.isGroup
69-
? `${entry.groupName ?? "Signal Group"} id:${entry.groupId}`
70-
: `${entry.senderName} id:${entry.senderDisplay}`;
71+
? `${entry.groupName || "Group"} id:${entry.groupId}`
72+
: entry.senderName === entry.senderDisplay
73+
? entry.senderName
74+
: `${entry.senderName} id:${entry.senderDisplay}`;
7175
const body = formatInboundEnvelope({
7276
channel: "Signal",
7377
from: fromLabel,

0 commit comments

Comments
 (0)