refactor: prune legacy group targets
This commit is contained in:
@@ -55,7 +55,7 @@ describe("sessions", () => {
|
||||
expect(
|
||||
buildGroupDisplayName({
|
||||
provider: "discord",
|
||||
room: "#general",
|
||||
groupChannel: "#general",
|
||||
space: "friends-of-clawd",
|
||||
id: "123",
|
||||
key: "discord:group:123",
|
||||
|
||||
@@ -22,26 +22,26 @@ function shortenGroupId(value?: string) {
|
||||
export function buildGroupDisplayName(params: {
|
||||
provider?: string;
|
||||
subject?: string;
|
||||
room?: string;
|
||||
groupChannel?: string;
|
||||
space?: string;
|
||||
id?: string;
|
||||
key: string;
|
||||
}) {
|
||||
const providerKey = (params.provider?.trim().toLowerCase() || "group").trim();
|
||||
const room = params.room?.trim();
|
||||
const groupChannel = params.groupChannel?.trim();
|
||||
const space = params.space?.trim();
|
||||
const subject = params.subject?.trim();
|
||||
const detail =
|
||||
(room && space
|
||||
? `${space}${room.startsWith("#") ? "" : "#"}${room}`
|
||||
: room || subject || space || "") || "";
|
||||
(groupChannel && space
|
||||
? `${space}${groupChannel.startsWith("#") ? "" : "#"}${groupChannel}`
|
||||
: groupChannel || subject || space || "") || "";
|
||||
const fallbackId = params.id?.trim() || params.key;
|
||||
const rawLabel = detail || fallbackId;
|
||||
let token = normalizeGroupLabel(rawLabel);
|
||||
if (!token) {
|
||||
token = normalizeGroupLabel(shortenGroupId(rawLabel));
|
||||
}
|
||||
if (!params.room && token.startsWith("#")) {
|
||||
if (!params.groupChannel && token.startsWith("#")) {
|
||||
token = token.replace(/^#+/, "");
|
||||
}
|
||||
if (token && !/^[@#]/.test(token) && !token.startsWith("g-") && !token.includes("#")) {
|
||||
|
||||
@@ -130,6 +130,14 @@ export function loadSessionStore(
|
||||
rec.lastChannel = rec.lastProvider;
|
||||
delete rec.lastProvider;
|
||||
}
|
||||
|
||||
// Best-effort migration: legacy `room` field → `groupChannel` (keep value, prune old key).
|
||||
if (typeof rec.groupChannel !== "string" && typeof rec.room === "string") {
|
||||
rec.groupChannel = rec.room;
|
||||
delete rec.room;
|
||||
} else if ("room" in rec) {
|
||||
delete rec.room;
|
||||
}
|
||||
}
|
||||
|
||||
// Cache the result if caching is enabled
|
||||
|
||||
@@ -67,7 +67,7 @@ export type SessionEntry = {
|
||||
channel?: string;
|
||||
groupId?: string;
|
||||
subject?: string;
|
||||
room?: string;
|
||||
groupChannel?: string;
|
||||
space?: string;
|
||||
deliveryContext?: DeliveryContext;
|
||||
lastChannel?: SessionChannelId;
|
||||
|
||||
Reference in New Issue
Block a user