mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-12 11:10:44 +02:00
Add read_only parameter to notification clearing API
Updated the `api_clear_notifications` function to include a `read_only` parameter, allowing conditional clearing of notifications based on their read status. Modified the filtering logic in the `NotificationService` to retain notifications that match the specified category, are newer than a cutoff date, or are unread when `read_only` is true. This enhances the granularity of the notification clearing process.
This commit is contained in:
parent
f7b2e550f6
commit
9337dd49d3
4
App.py
4
App.py
@ -1158,10 +1158,12 @@ def api_clear_notifications():
|
|||||||
"""API endpoint to clear notifications."""
|
"""API endpoint to clear notifications."""
|
||||||
category = request.json.get('category')
|
category = request.json.get('category')
|
||||||
older_than_days = request.json.get('older_than_days')
|
older_than_days = request.json.get('older_than_days')
|
||||||
|
read_only = request.json.get('read_only', False) # Get the read_only parameter with default False
|
||||||
|
|
||||||
cleared_count = notification_service.clear_notifications(
|
cleared_count = notification_service.clear_notifications(
|
||||||
category=category,
|
category=category,
|
||||||
older_than_days=older_than_days
|
older_than_days=older_than_days,
|
||||||
|
read_only=read_only # Pass the parameter to the method
|
||||||
)
|
)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
@ -330,12 +330,12 @@ class NotificationService:
|
|||||||
if older_than_days:
|
if older_than_days:
|
||||||
cutoff_date = self._get_current_time() - timedelta(days=older_than_days)
|
cutoff_date = self._get_current_time() - timedelta(days=older_than_days)
|
||||||
|
|
||||||
# Apply filters in a single pass
|
# Apply filters to KEEP notifications that should NOT be cleared
|
||||||
self.notifications = [
|
self.notifications = [
|
||||||
n for n in self.notifications
|
n for n in self.notifications
|
||||||
if (not category or n.get("category") != category) and
|
if (category and n.get("category") != category) or # Keep if we're filtering by category and this isn't that category
|
||||||
(not cutoff_date or self._parse_timestamp(n.get("timestamp", self._get_current_time().isoformat())) >= cutoff_date) and
|
(cutoff_date and self._parse_timestamp(n.get("timestamp", self._get_current_time().isoformat())) >= cutoff_date) or # Keep if newer than cutoff
|
||||||
(not read_only or n.get("read", False) == False) # Keep unread notifications when read_only=True
|
(read_only and not n.get("read", False)) # Keep if we're only clearing read notifications and this is unread
|
||||||
]
|
]
|
||||||
|
|
||||||
cleared_count = original_count - len(self.notifications)
|
cleared_count = original_count - len(self.notifications)
|
||||||
|
Loading…
Reference in New Issue
Block a user