Keep unsent notification batches pending and retain seen history

This commit is contained in:
2026-09-06 13:00:12 +03:00
parent d2d66c8e9d
commit 4c4ba0c4c8
5 changed files with 82 additions and 23 deletions
+15 -8
View File
@@ -147,6 +147,7 @@ export function list(email) {
konular: (() => { try { return JSON.parse(r.konular || '[]'); } catch { return []; } })(),
aktif: Boolean(r.aktif),
sonGonderim: r.sonGonderim,
initialized: r.sonGorulenler !== null,
sonGorulenler: (() => { try { return JSON.parse(r.sonGorulenler || '[]'); } catch { return []; } })(),
}));
} finally {
@@ -165,13 +166,19 @@ export function remove(id, email) {
}
}
export function markSent(id, ihaleIdleri) {
const db = open({ create: false });
if (!db) return;
function recordSeen(id,ihaleIdleri,sent) {
const db=open({create:false});
if(!db)throw new Error('Bildirim deposu kullanılamıyor');
try {
db.prepare('UPDATE abonelikler SET sonGonderim=?, sonGorulenler=? WHERE id=?')
.run(new Date().toISOString(), JSON.stringify(ihaleIdleri.slice(0, 400)), id);
} finally {
db.close();
}
db.exec('BEGIN IMMEDIATE');
const row=db.prepare('SELECT sonGorulenler FROM abonelikler WHERE id=?').get(id);
if(!row)throw new Error('Abonelik artık yok.');
const seen=[...new Set([...JSON.parse(row.sonGorulenler || '[]'),...ihaleIdleri])];
db.prepare('UPDATE abonelikler SET sonGorulenler=?,sonGonderim=CASE WHEN ? THEN ? ELSE sonGonderim END WHERE id=?')
.run(JSON.stringify(seen),sent?1:0,new Date().toISOString(),id);
db.exec('COMMIT');
}catch(error){try{db.exec('ROLLBACK');}catch{}throw error;}
finally{db.close();}
}
export const markSent=(id,ids)=>recordSeen(id,ids,true);
export const markBaseline=(id,ids)=>recordSeen(id,ids,false);