about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/micropub/util.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/micropub/util.rs b/src/micropub/util.rs
index 0633ce9..9bbdcf6 100644
--- a/src/micropub/util.rs
+++ b/src/micropub/util.rs
@@ -83,7 +83,7 @@ pub fn normalize_mf2(mut body: serde_json::Value, user: &TokenData) -> (String,
             .iter()
             .map(|i| i.as_str().unwrap_or(""))
             .filter(|i| i != &"")
-            .map(|i| me.join(&((&folder).clone() + i)).unwrap().to_string())
+            .map(|i| me.join(&(folder.clone() + i)).unwrap().to_string())
             .collect::<Vec<String>>();
         let urls = body["properties"]["url"].as_array_mut().unwrap();
         new_urls.iter().for_each(|i| urls.push(json!(i)));
@@ -125,7 +125,14 @@ pub fn normalize_mf2(mut body: serde_json::Value, user: &TokenData) -> (String,
             .unwrap()
             .remove("mp-channel");
     }
-    if body["properties"]["channel"][0].as_str().is_none() {
+    // If there is no explicit channels, and the post is not marked as "unlisted",
+    // post it to one of the default channels that makes sense for the post type.
+    if body["properties"]["channel"][0].as_str().is_none() && (!body["properties"]["visibility"]
+        .as_array()
+        .map(|v| v.contains(
+            &serde_json::Value::String("unlisted".to_owned())
+        )).unwrap_or(false)
+    ) {
         match body["type"][0].as_str() {
             Some("h-entry") => {
                 // Set the channel to the main channel...
@@ -247,6 +254,27 @@ mod tests {
     }
 
     #[test]
+    fn test_unlisted_post() {
+        let mf2 = json!({
+            "type": ["h-entry"],
+            "properties": {
+                "uid": ["https://fireburn.ru/posts/test"],
+                "content": [{"html": "<p>Hello world!</p>"}],
+                "visibility": ["public", "unlisted"]
+            }
+        });
+
+        let (uid, normalized) = normalize_mf2(
+            mf2.clone(),
+            &token_data()
+        );
+        assert!(
+            normalized["properties"]["channel"].as_array().unwrap_or(&vec![]).is_empty(),
+            "Returned post was added to a channel despite the `unlisted` visibility"
+        );
+    }
+
+    #[test]
     fn test_no_replace_uid() {
         let mf2 = json!({
             "type": ["h-card"],