fix: retain server notifications when local alerts arrive
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {validateReminderPreferences,quietNow} from '../services/reminderPreferences';
|
||||
import {validateTeam} from '../services/teamData';
|
||||
import {savedFilterCriteria} from '../services/savedFilterCriteria';
|
||||
import {mergeServerNotifications,acknowledgeNotifications} from '../services/notifications';
|
||||
import {mergeServerNotifications,acknowledgeNotifications,addLocalNotification} from '../services/notifications';
|
||||
import { searchTender } from '../services/searchTender';
|
||||
import { normalizeTenderSearch, matchingItemResults } from '../services/tenderSearch';
|
||||
import React, {createContext, useContext, useState, useEffect, useMemo, useRef } from 'react';
|
||||
@@ -579,7 +579,7 @@ export const AppProvider = ({ children }) => {
|
||||
// Gerçek bildirim: listeye ekler; sessiz saat dışında ve push açıksa tarayıcı
|
||||
// bildirimi (Notification API) da gösterir.
|
||||
const notify = (title, text) => {
|
||||
setNotifications((prev) => [{ id: 'n-' + Date.now(), title, text, time: 'az önce', read: false }, ...prev].slice(0, 30));
|
||||
setNotifications(prev=>addLocalNotification(prev,title,text));
|
||||
pushNotification(title,text);
|
||||
};
|
||||
const pushNotification=(title,text)=>{
|
||||
@@ -605,7 +605,7 @@ export const AppProvider = ({ children }) => {
|
||||
const fresh=checked.filter(row=>!row.read&&!seenServerNotifications.current.has(row.id));
|
||||
checked.forEach(row=>seenServerNotifications.current.add(row.id));
|
||||
fresh.slice(0,5).forEach(row=>pushNotification(row.title,row.text));
|
||||
setNotifications(current=>[...checked,...current.filter(row=>!row.serverId)].slice(0,80));
|
||||
setNotifications(current=>mergeServerNotifications(current,rows));
|
||||
}catch(error){if(getToken()===session&&version===notificationVersion.current)setNotificationError(error.message);}
|
||||
};
|
||||
const markNotificationsRead=async()=>{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user