fix: retain server notifications when local alerts arrive

This commit is contained in:
2026-09-06 14:56:21 +03:00
parent 120657758c
commit 2353170c40
4 changed files with 36 additions and 5 deletions
+8 -1
View File
@@ -1,8 +1,15 @@
const keepRecentLocal = rows => {
let localCount=0;
return rows.filter(row=>row.serverId || ++localCount<=30);
};
export function addLocalNotification(current,title,text) {
return keepRecentLocal([{id:'n-'+crypto.randomUUID(),title,text,time:'az önce',read:false},...current]);
}
export function mergeServerNotifications(current,rows) {
if(!Array.isArray(rows)||rows.some(row=>typeof row?.id!=='string'||typeof row.baslik!=='string'||typeof row.metin!=='string'))throw new Error('Bildirim listesi geçersiz.');
const remote=rows.map(row=>({id:'server:'+row.id,serverId:row.id,title:row.baslik,text:row.metin,
time:new Date(row.zaman).toLocaleString('tr-TR'),read:!!row.okundu,ikn:row.ikn}));
return [...remote,...current.filter(row=>!row.serverId)].slice(0,80);
return keepRecentLocal([...remote,...current.filter(row=>!row.serverId)]);
}
export async function acknowledgeNotifications(snapshot,request) {
const unread=snapshot.filter(row=>!row.read),ids=unread.filter(row=>row.serverId).map(row=>row.serverId);