Spaces:
Running
Running
Update routes/notification_routes.py
Browse files327 unmodified lines328329330331332333334335336337326 unmodified lines664665666667327 unmodified linessupabase.table("admin_push_tokens").select("id,admin_id,expo_push_token,device_name,platform,is_active,created_at,updated_at").eq("is_active", True))result = execute_supabase_optional(query, "active_admin_push_tokens")return result.data if result and result.data else []def notify_admins(event_type: str,title: str,326 unmodified lines"type": "campaign_status","campaign_id": campaign_id,},)327 unmodified lines328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362326 unmodified lines689690691692327 unmodified linessupabase.table("admin_push_tokens").select("id,admin_id,expo_push_token,device_name,platform,is_active,created_at,updated_at").eq("is_active", True).order("updated_at", desc=True))result = execute_supabase_optional(query, "active_admin_push_tokens")rows = result.data if result and result.data else []latest_rows: list[dict[str, Any]] = []seen_tokens: set[str] = set()seen_devices: set[tuple[str, str, str]] = set()for row in rows:token = str(row.get("expo_push_token") or "").strip()admin_id = str(row.get("admin_id") or "").strip()device_name = str(row.get("device_name") or "").strip()platform = str(row.get("platform") or "").strip()if not token or token in seen_tokens:continue# Reinstalling the app generates a new Expo token. Only its newest token# should receive a notification for the same named device.device_key = (admin_id, device_name, platform)if device_name and device_key in seen_devices:continueseen_tokens.add(token)if device_name:seen_devices.add(device_key)latest_rows.append(row)return latest_rowsdef notify_admins(event_type: str,title: str,326 unmodified lines"type": "campaign_status","campaign_id": campaign_id,},)
routes/notification_routes.py+27-2