fix: preserve complete weekly brief content and date bounds
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { splitBriefText } from './brief-content.mjs';
|
||||
|
||||
/** Delivery accounting shared by scheduled and administrator-triggered briefs. */
|
||||
export function createBriefSender({ store, buildBrief, text, html, telegramConfigured, sendTelegram, emailConfigured, sendEmail, warn = console.warn }) {
|
||||
return async function sendBrief(tenderGetir) {
|
||||
@@ -14,16 +16,20 @@ export function createBriefSender({ store, buildBrief, text, html, telegramConfi
|
||||
if (brief.bos) { r.bos++; continue; }
|
||||
const channels = [];
|
||||
const telegram = store.getData(user.email, 'telegram');
|
||||
if (telegramConfigured() && telegram?.chatId) channels.push({
|
||||
name:'telegram', send:() => sendTelegram(telegram.chatId, text(brief).slice(0,3900)),
|
||||
valid:receipt => receipt === true,
|
||||
});
|
||||
if (telegramConfigured() && telegram?.chatId) {
|
||||
for (const part of splitBriefText(text(brief))) channels.push({
|
||||
name:'telegram', send:() => sendTelegram(telegram.chatId, part, { parseMode:null }),
|
||||
valid:receipt => receipt === true,
|
||||
});
|
||||
}
|
||||
if (emailConfigured()) channels.push({
|
||||
name:'email', send:() => sendEmail({ to:user.email, subject:`İhaleist — Haftalık Brief (${brief.hafta})`, html:html(brief), text:text(brief) }),
|
||||
valid:receipt => typeof receipt?.id === 'string' && Boolean(receipt.id.trim()),
|
||||
});
|
||||
if (!channels.length) r.kanalsiz++;
|
||||
const failedChannels = new Set();
|
||||
for (const channel of channels) {
|
||||
if (failedChannels.has(channel.name)) continue;
|
||||
// An earlier channel can await the network while the user disables briefs.
|
||||
if (store.getData(user.email, 'brief')?.kapali) { r.kapali++; break; }
|
||||
const counts = r.kanallar[channel.name];
|
||||
@@ -35,6 +41,7 @@ export function createBriefSender({ store, buildBrief, text, html, telegramConfi
|
||||
accepted = true;
|
||||
} catch (error) {
|
||||
counts.hata++;
|
||||
failedChannels.add(channel.name);
|
||||
failed = true;
|
||||
warn('[brief]', user.email, channel.name, error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user