From 8bcbc983c381d8318aeb85fabfacd29563332f14 Mon Sep 17 00:00:00 2001
From: Marcel <mtrnord1@gmail.com>
Date: Thu, 9 Apr 2020 21:11:21 +0200
Subject: [PATCH] Change and add Comments to the profile endpoints Add missing
 docs

Took 9 minutes
---
 src/main.rs | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index aee2d47c..e85d90b3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -299,7 +299,7 @@ fn set_displayname_route(
 ) -> MatrixResult<set_display_name::Response> {
     let user_id = body.user_id.clone().expect("user is authenticated");
 
-    // Send error on None and accept Some("") as valid username
+    // Send error on None
     // Synapse returns a parsing error but the spec doesn't require this
     if body.displayname.is_none() {
         debug!("Request was missing the displayname payload.");
@@ -311,6 +311,7 @@ fn set_displayname_route(
     }
 
     if let Some(displayname) = body.displayname {
+        // Some("") will clear the displayname
         if displayname == "" {
             data.displayname_remove(&user_id);
         } else {
@@ -338,7 +339,7 @@ fn get_displayname_route(
         debug!("Profile was not found.");
         MatrixResult(Err(Error {
             kind: ErrorKind::NotFound,
-            message: "Profile was not found".to_owned(),
+            message: "Profile was not found.".to_owned(),
             status_code: http::StatusCode::NOT_FOUND,
         }))
     }
@@ -348,6 +349,7 @@ fn get_displayname_route(
         }));
     }
 
+    // The user has no displayname
     MatrixResult(Ok(get_display_name::Response { displayname: None }))
 }
 
@@ -394,7 +396,7 @@ fn get_avatar_url_route(
         debug!("Profile was not found.");
         MatrixResult(Err(Error {
             kind: ErrorKind::NotFound,
-            message: "Profile was not found".to_owned(),
+            message: "Profile was not found.".to_owned(),
             status_code: http::StatusCode::NOT_FOUND,
         }))
     }
@@ -404,6 +406,7 @@ fn get_avatar_url_route(
         }));
     }
 
+    // The user has no avatar
     MatrixResult(Ok(get_avatar_url::Response { avatar_url: None }))
 }
 
@@ -428,7 +431,7 @@ fn get_profile_route(
     debug!("Profile was not found.");
     MatrixResult(Err(Error {
         kind: ErrorKind::NotFound,
-        message: "Profile was not found".to_owned(),
+        message: "Profile was not found.".to_owned(),
         status_code: http::StatusCode::NOT_FOUND,
     }))
 }