import type { ChannelId } from "../channels/plugins/channel-id.types.js" ;
export type ChannelDirection = "inbound" | "outbound" ;
type ActivityEntry = {
inboundAt: number | null ;
outboundAt: number | null ;
};
const activity = new Map<string, ActivityEntry>();
function keyFor(channel: ChannelId, accountId: string) {
return `${channel}:${accountId || "default" }`;
}
function ensureEntry(channel: ChannelId, accountId: string): ActivityEntry {
const key = keyFor(channel, accountId);
const existing = activity.get(key);
if (existing) {
return existing;
}
const created: ActivityEntry = { inboundAt: null , outboundAt: null };
activity.set(key, created);
return created;
}
export function recordChannelActivity(params: {
channel: ChannelId;
accountId?: string | null ;
direction: ChannelDirection;
at?: number;
}) {
const at = typeof params.at === "number" ? params.at : Date.now();
const accountId = params.accountId?.trim() || "default" ;
const entry = ensureEntry(params.channel, accountId);
if (params.direction === "inbound" ) {
entry.inboundAt = at;
}
if (params.direction === "outbound" ) {
entry.outboundAt = at;
}
}
export function getChannelActivity(params: {
channel: ChannelId;
accountId?: string | null ;
}): ActivityEntry {
const accountId = params.accountId?.trim() || "default" ;
return (
activity.get(keyFor(params.channel, accountId)) ?? {
inboundAt: null ,
outboundAt: null ,
}
);
}
export function resetChannelActivityForTest() {
activity.clear();
}
Messung V0.5 in Prozent C=100 H=100 G=100
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-09)
¤
*© Formatika GbR, Deutschland