feat: unify main session and icon cues
This commit is contained in:
@@ -23,6 +23,7 @@ export type SessionConfig = {
|
||||
sessionIntro?: string;
|
||||
typingIntervalSeconds?: number;
|
||||
heartbeatMinutes?: number;
|
||||
mainKey?: string;
|
||||
};
|
||||
|
||||
export type LoggingConfig = {
|
||||
@@ -135,6 +136,7 @@ const ReplySchema = z
|
||||
sendSystemOnce: z.boolean().optional(),
|
||||
sessionIntro: z.string().optional(),
|
||||
typingIntervalSeconds: z.number().int().positive().optional(),
|
||||
mainKey: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
heartbeatMinutes: z.number().int().nonnegative().optional(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { deriveSessionKey } from "./sessions.js";
|
||||
import { deriveSessionKey, resolveSessionKey } from "./sessions.js";
|
||||
|
||||
describe("sessions", () => {
|
||||
it("returns normalized per-sender key", () => {
|
||||
@@ -22,4 +22,16 @@ describe("sessions", () => {
|
||||
"group:12345-678@g.us",
|
||||
);
|
||||
});
|
||||
|
||||
it("maps direct chats to main key when provided", () => {
|
||||
expect(
|
||||
resolveSessionKey("per-sender", { From: "whatsapp:+1555" }, "main"),
|
||||
).toBe("main");
|
||||
});
|
||||
|
||||
it("leaves groups untouched even with main key", () => {
|
||||
expect(
|
||||
resolveSessionKey("per-sender", { From: "12345-678@g.us" }, "main"),
|
||||
).toBe("group:12345-678@g.us");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -77,3 +77,20 @@ export function deriveSessionKey(scope: SessionScope, ctx: MsgContext) {
|
||||
}
|
||||
return from || "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the session key with an optional canonical direct-chat key (e.g., "main").
|
||||
* All non-group direct chats collapse to `mainKey` when provided, keeping group isolation.
|
||||
*/
|
||||
export function resolveSessionKey(
|
||||
scope: SessionScope,
|
||||
ctx: MsgContext,
|
||||
mainKey?: string,
|
||||
) {
|
||||
const raw = deriveSessionKey(scope, ctx);
|
||||
if (scope === "global") return raw;
|
||||
const canonical = (mainKey ?? "").trim();
|
||||
const isGroup = raw.startsWith("group:") || raw.includes("@g.us");
|
||||
if (!isGroup && canonical) return canonical;
|
||||
return raw;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user