@@ -165,6 +165,11 @@ def actionNotificationQuery(self, to):
165165 else :
166166 count = 0
167167
168+ # Subtract dismissed count baseline so only new items show
169+ dismissed_counts = site_data .get ("notification_dismissed_count" , {})
170+ baseline = dismissed_counts .get (name , 0 )
171+ count = max (0 , count - baseline )
172+
168173 result_entry = {
169174 "site" : address ,
170175 "title" : title ,
@@ -217,24 +222,54 @@ def actionNotificationQuery(self, to):
217222 "taken" : round (time .time () - total_s , 3 )
218223 })
219224
220- # Dismiss (mark as seen) notifications for a site
221- @flag .admin
222- def actionNotificationDismiss (self , to , site_address , name ):
225+ def _dismissNotification (self , site_address , name ):
226+ """Snapshot current query count as baseline so only new items trigger alerts."""
227+ from Site import SiteManager
228+
223229 site_data = self .user .getSiteData (site_address )
224230 if "notification_dismissed" not in site_data :
225231 site_data ["notification_dismissed" ] = {}
226232 site_data ["notification_dismissed" ][name ] = int (time .time () * 1000 )
233+
234+ # Store current raw count as baseline
235+ if "notification_dismissed_count" not in site_data :
236+ site_data ["notification_dismissed_count" ] = {}
237+ subscriptions = site_data .get ("notifications" , {})
238+ query_set = subscriptions .get (name )
239+ if query_set :
240+ try :
241+ site = SiteManager .site_manager .get (site_address )
242+ if site and site .storage .has_db :
243+ query_raw , params = query_set
244+ query = query_raw
245+ if params :
246+ query_params = map (helper .sqlquote , params )
247+ query = query .replace (":params" , "," .join (query_params ))
248+ if "{xid_directory}" in query :
249+ xid_dir = self .user .getUserDirectory (site_address )
250+ if xid_dir :
251+ query = query .replace ("{xid_directory}" , xid_dir )
252+ if "{last_seen}" in query :
253+ query = query .replace ("{last_seen}" , "0" )
254+ res = site .storage .query (query )
255+ row = next (res , None )
256+ if row :
257+ row = dict (row )
258+ site_data ["notification_dismissed_count" ][name ] = row .get ("count" , row .get ("COUNT(*)" , 0 ))
259+ except Exception as err :
260+ self .log .error ("Dismiss count snapshot error: %s" % err )
261+
227262 self .user .save ()
263+
264+ # Dismiss (mark as seen) notifications for a site
265+ @flag .admin
266+ def actionNotificationDismiss (self , to , site_address , name ):
267+ self ._dismissNotification (site_address , name )
228268 self .response (to , "ok" )
229269
230270 # Dismiss own site's notifications (callable from within the site iframe, no admin needed)
231271 def actionNotificationDismissSelf (self , to , name ):
232- site_address = self .site .address
233- site_data = self .user .getSiteData (site_address )
234- if "notification_dismissed" not in site_data :
235- site_data ["notification_dismissed" ] = {}
236- site_data ["notification_dismissed" ][name ] = int (time .time () * 1000 )
237- self .user .save ()
272+ self ._dismissNotification (self .site .address , name )
238273 self .response (to , "ok" )
239274
240275
0 commit comments