fix(telegram): add initial message debounce for better push notifications (#18147)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 5e2285b6a0
Co-authored-by: Marvae <11957602+Marvae@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
Hongwei Ma
2026-02-17 13:51:49 +08:00
committed by GitHub
parent 2e375a5498
commit 7ffc8f9f7c
6 changed files with 261 additions and 32 deletions

View File

@@ -9,11 +9,11 @@ export type DraftStreamLoop = {
export function createDraftStreamLoop(params: {
throttleMs: number;
isStopped: () => boolean;
sendOrEditStreamMessage: (text: string) => Promise<void>;
sendOrEditStreamMessage: (text: string) => Promise<void | boolean>;
}): DraftStreamLoop {
let lastSentAt = 0;
let pendingText = "";
let inFlightPromise: Promise<void> | undefined;
let inFlightPromise: Promise<void | boolean> | undefined;
let timer: ReturnType<typeof setTimeout> | undefined;
const flush = async () => {
@@ -32,14 +32,18 @@ export function createDraftStreamLoop(params: {
return;
}
pendingText = "";
lastSentAt = Date.now();
const current = params.sendOrEditStreamMessage(text).finally(() => {
if (inFlightPromise === current) {
inFlightPromise = undefined;
}
});
inFlightPromise = current;
await current;
const sent = await current;
if (sent === false) {
pendingText = text;
return;
}
lastSentAt = Date.now();
if (!pendingText) {
return;
}