diff --git a/Cargo.toml b/Cargo.toml index 45b5d57..5c52375 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.9.0" +version = "0.10.0" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/src/subreddit.rs b/src/subreddit.rs index c8763e5..c26abdc 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -35,18 +35,19 @@ pub async fn community(req: Request) -> Result, String> { let post_sort = req.cookie("post_sort").map_or_else(|| "hot".to_string(), |c| c.value().to_string()); let sort = req.param("sort").unwrap_or_else(|| req.param("id").unwrap_or(post_sort)); - let sub = req.param("sub").map_or( - if front_page == "default" || front_page.is_empty() { - if subscribed.is_empty() { - "popular".to_string() - } else { - subscribed.to_owned() - } + let sub = req.param("sub").unwrap_or(if front_page == "default" || front_page.is_empty() { + if subscribed.is_empty() { + "popular".to_string() } else { - front_page.to_owned() - }, - String::from, - ); + subscribed.to_owned() + } + } else { + front_page.to_owned() + }); + + if req.param("sub").is_some() && sub.starts_with("u_") { + return Ok(redirect(["/user/", &sub[2..]].concat())); + } let path = format!("/r/{}/{}.json?{}&raw_json=1", sub, sort, req.uri().query().unwrap_or_default()); diff --git a/static/style.css b/static/style.css index 056d698..7f421d4 100644 --- a/static/style.css +++ b/static/style.css @@ -307,7 +307,7 @@ aside { /* Subscriptions */ -#sub_subscription { +#sub_subscription, #user_subscription { margin-top: 20px; } diff --git a/templates/settings.html b/templates/settings.html index 0038c0d..c6df265 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -57,10 +57,10 @@ {% if prefs.subscriptions.len() > 0 %}
-

Subscribed Subreddits

+

Subscribed Feeds

{% for sub in prefs.subscriptions %}
- {{ sub }} + {% if sub.starts_with("u_") -%}{{ format!("u/{}", &sub[2..]) }}{% else -%}{{ format!("r/{}", sub) }}{% endif -%}
diff --git a/templates/user.html b/templates/user.html index 28411c1..26ab719 100644 --- a/templates/user.html +++ b/templates/user.html @@ -75,6 +75,18 @@
{{ user.karma }}
{{ user.created }}
+
+ {% let name = ["u_", user.name.as_str()].join("") %} + {% if prefs.subscriptions.contains(name) %} +
+ +
+ {% else %} +
+ +
+ {% endif %} +
diff --git a/templates/utils.html b/templates/utils.html index 5d23902..f9c41af 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -58,7 +58,13 @@ {% macro post_in_list(post) -%}

- r/{{ post.community }} + {% let community -%} + {% if post.community.starts_with("u_") -%} + {% let community = format!("u/{}", &post.community[2..]) -%} + {% else -%} + {% let community = format!("r/{}", post.community) -%} + {% endif -%} + {{ community }}