refactor: share thread binding id parser

This commit is contained in:
Peter Steinberger
2026-03-07 20:04:44 +00:00
parent 95fe282a17
commit 30d091b2fb
4 changed files with 67 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { resolveThreadBindingConversationIdFromBindingId } from "../channels/thread-binding-id.js";
import { formatThreadBindingDurationLabel } from "../channels/thread-bindings-messages.js";
import { resolveStateDir } from "../config/paths.js";
import { logVerbose } from "../globals.js";
@@ -312,22 +313,6 @@ async function persistBindingsToDisk(params: {
});
}
function resolveThreadIdFromBindingId(params: {
accountId: string;
bindingId?: string;
}): string | undefined {
const bindingId = params.bindingId?.trim();
if (!bindingId) {
return undefined;
}
const prefix = `${params.accountId}:`;
if (!bindingId.startsWith(prefix)) {
return undefined;
}
const conversationId = bindingId.slice(prefix.length).trim();
return conversationId || undefined;
}
function normalizeTimestampMs(raw: unknown): number {
if (typeof raw !== "number" || !Number.isFinite(raw)) {
return Date.now();
@@ -575,7 +560,7 @@ export function createTelegramThreadBindingManager(
: null;
},
touch: (bindingId, at) => {
const conversationId = resolveThreadIdFromBindingId({
const conversationId = resolveThreadBindingConversationIdFromBindingId({
accountId,
bindingId,
});
@@ -598,7 +583,7 @@ export function createTelegramThreadBindingManager(
}),
);
}
const conversationId = resolveThreadIdFromBindingId({
const conversationId = resolveThreadBindingConversationIdFromBindingId({
accountId,
bindingId: input.bindingId,
});