Update routes/sendnotifications.py
Browse files
routes/sendnotifications.py
CHANGED
@@ -79,7 +79,7 @@ def format_name(full_name: str) -> str:
|
|
79 |
return f"{parts[0]} {parts[1][0].upper()}."
|
80 |
|
81 |
async def get_user_info(user_id: str):
|
82 |
-
users = await fetch_supabase("User", "name,token_fcm", {"id": user_id})
|
83 |
if not users:
|
84 |
return None
|
85 |
return users[0]
|
@@ -192,6 +192,10 @@ async def send_notification(
|
|
192 |
if not target_user or not target_user.get("token_fcm"):
|
193 |
raise HTTPException(status_code=404, detail="Target user or FCM token not found")
|
194 |
|
|
|
|
|
|
|
|
|
195 |
actor_info = await get_user_info(sender_id)
|
196 |
if not actor_info or not actor_info.get("name"):
|
197 |
raise HTTPException(status_code=404, detail="User not found")
|
|
|
79 |
return f"{parts[0]} {parts[1][0].upper()}."
|
80 |
|
81 |
async def get_user_info(user_id: str):
|
82 |
+
users = await fetch_supabase("User", "name,token_fcm,notifications", {"id": user_id})
|
83 |
if not users:
|
84 |
return None
|
85 |
return users[0]
|
|
|
192 |
if not target_user or not target_user.get("token_fcm"):
|
193 |
raise HTTPException(status_code=404, detail="Target user or FCM token not found")
|
194 |
|
195 |
+
# 🔔 Check if target user has notifications enabled
|
196 |
+
if not target_user.get("notifications", True): # Default to True if field doesn't exist
|
197 |
+
return {"detail": "Target user has notifications disabled, notification not sent"}
|
198 |
+
|
199 |
actor_info = await get_user_info(sender_id)
|
200 |
if not actor_info or not actor_info.get("name"):
|
201 |
raise HTTPException(status_code=404, detail="User not found")
|