parameters: (request)
docstring: API for posting user to user messages
docstring_summary: API for posting user to user messages
docstring_tokens: API for posting user to user messages
function: def messages_api(request):
      """
      API for posting user to user messages
      """
      if not request.user.is_authenticated:
          return jsonResponse({"error": "You must be logged in to access your messages."})
  
      if request.method == "POST":
          j = request.POST.get("json")
          if not j:
              return jsonResponse({"error": "No post JSON."})
          j = json.loads(j)
  
          Notification({"uid": j["recipient"]}).make_message(sender_id=request.user.id, message=j["message"]).save()
          return jsonResponse({"status": "ok"})
  
      elif request.method == "GET":
          return jsonResponse({"error": "Unsupported HTTP method."})
function_tokens: def messages_api ( request ) : if not request . user . is_authenticated : return jsonResponse ( { "error" : "You must be logged in to access your messages." } ) if request . method == "POST" : j = request . POST . get ( "json" ) if not j : return jsonResponse ( { "error" : "No post JSON." } ) j = json . loads ( j ) Notification ( { "uid" : j [ "recipient" ] } ) . make_message ( sender_id = request . user . id , message = j [ "message" ] ) . save ( ) return jsonResponse ( { "status" : "ok" } ) elif request . method == "GET" : return jsonResponse ( { "error" : "Unsupported HTTP method." } )