Keep unsent notification batches pending and retain seen history
This commit is contained in:
+15
-8
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user