def notifications_read_api(request): """ API for marking notifications as read Takes JSON in the "notifications" parameter of an array of notifcation ids as strings. """ if request.method == "POST": notifications = request.POST.get("notifications") if not notifications: return jsonResponse({"error": "'notifications' post parameter missing."}) notifications = json.loads(notifications) for id in notifications: notification = Notification(_id=id) if notification.uid != request.user.id: # Only allow expiring your own notifications continue notification.mark_read().save() return jsonResponse({"status": "ok"}) else: return jsonResponse({"error": "Unsupported HTTP method."})