haha
This commit is contained in:
31
backend/apps/notifications/utils.py
Normal file
31
backend/apps/notifications/utils.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
Notification helpers for preference checks.
|
||||
"""
|
||||
from typing import Optional
|
||||
|
||||
from .models import Notification, NotificationPreference
|
||||
|
||||
|
||||
def get_notification_preference(user) -> Optional[NotificationPreference]:
|
||||
if not user:
|
||||
return None
|
||||
preference, _ = NotificationPreference.objects.get_or_create(user=user)
|
||||
return preference
|
||||
|
||||
|
||||
def should_notify(user, notification_type: str) -> bool:
|
||||
"""Check if user has enabled notification type."""
|
||||
preference = get_notification_preference(user)
|
||||
if not preference:
|
||||
return False
|
||||
if notification_type == Notification.Type.PRICE_ALERT:
|
||||
return preference.enable_price_alert
|
||||
if notification_type in (
|
||||
Notification.Type.BOUNTY_ACCEPTED,
|
||||
Notification.Type.BOUNTY_COMPLETED,
|
||||
Notification.Type.NEW_COMMENT,
|
||||
):
|
||||
return preference.enable_bounty
|
||||
if notification_type == Notification.Type.SYSTEM:
|
||||
return preference.enable_system
|
||||
return True
|
||||
Reference in New Issue
Block a user