refactor: prune legacy group targets
This commit is contained in:
@@ -21,7 +21,6 @@ describe("resolveTelegramTargetChatType", () => {
|
||||
|
||||
it("handles tg/group prefixes and topic suffixes", () => {
|
||||
expect(resolveTelegramTargetChatType("tg:5232990709")).toBe("direct");
|
||||
expect(resolveTelegramTargetChatType("group:-123456789")).toBe("group");
|
||||
expect(resolveTelegramTargetChatType("telegram:group:-1001234567890")).toBe("group");
|
||||
expect(resolveTelegramTargetChatType("telegram:group:-1001234567890:topic:456")).toBe("group");
|
||||
expect(resolveTelegramTargetChatType("-1001234567890:456")).toBe("group");
|
||||
|
||||
@@ -11,6 +11,10 @@ describe("stripTelegramInternalPrefixes", () => {
|
||||
expect(stripTelegramInternalPrefixes("telegram:group:-100123")).toBe("-100123");
|
||||
});
|
||||
|
||||
it("does not strip group prefix without telegram prefix", () => {
|
||||
expect(stripTelegramInternalPrefixes("group:-100123")).toBe("group:-100123");
|
||||
});
|
||||
|
||||
it("is idempotent", () => {
|
||||
expect(stripTelegramInternalPrefixes("@mychannel")).toBe("@mychannel");
|
||||
});
|
||||
|
||||
@@ -5,8 +5,19 @@ export type TelegramTarget = {
|
||||
|
||||
export function stripTelegramInternalPrefixes(to: string): string {
|
||||
let trimmed = to.trim();
|
||||
let strippedTelegramPrefix = false;
|
||||
while (true) {
|
||||
const next = trimmed.replace(/^(telegram|tg|group):/i, "").trim();
|
||||
const next = (() => {
|
||||
if (/^(telegram|tg):/i.test(trimmed)) {
|
||||
strippedTelegramPrefix = true;
|
||||
return trimmed.replace(/^(telegram|tg):/i, "").trim();
|
||||
}
|
||||
// Legacy internal form: `telegram:group:<id>` (still emitted by session keys).
|
||||
if (strippedTelegramPrefix && /^group:/i.test(trimmed)) {
|
||||
return trimmed.replace(/^group:/i, "").trim();
|
||||
}
|
||||
return trimmed;
|
||||
})();
|
||||
if (next === trimmed) return trimmed;
|
||||
trimmed = next;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user