notifications....again
This commit is contained in:
parent
51138c9d50
commit
2ad7c34157
@ -227,16 +227,29 @@ def send_test_notification_route(username: str, password: str) -> Response:
|
||||
data = request.get_json()
|
||||
message = data.get("message", "Ktv Test") if data else "Ktv Test"
|
||||
|
||||
try:
|
||||
subscriptions = get_push_subscriptions() # Get all subscriptions
|
||||
except Exception as e:
|
||||
print(f"Error getting push subscriptions: {e}")
|
||||
return jsonify({"error": "Could not retrieve push subscriptions from the database."}), 500
|
||||
|
||||
if not subscriptions:
|
||||
return jsonify({"message": "No push subscriptions found."}), 404
|
||||
|
||||
message_body = json.dumps({"title": "KTVManager", "body": message})
|
||||
success_count = 0
|
||||
failure_count = 0
|
||||
|
||||
for sub in subscriptions:
|
||||
try:
|
||||
send_notification(json.loads(sub['subscription_json']), message_body)
|
||||
success_count += 1
|
||||
except Exception as e:
|
||||
print(f"Error sending notification to subscription ID {sub.get('id', 'N/A')}: {e}")
|
||||
failure_count += 1
|
||||
|
||||
return jsonify({"message": f"Test notification sent to {len(subscriptions)} subscription(s)."})
|
||||
return jsonify({
|
||||
"message": f"Test notification sending process completed.",
|
||||
"sent": success_count,
|
||||
"failed": failure_count
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user