Fix Default Comment Sorting
This commit is contained in:
parent
3444989f9a
commit
6e8cf69227
19
src/post.rs
19
src/post.rs
@ -18,14 +18,19 @@ struct PostTemplate {
|
|||||||
|
|
||||||
pub async fn item(req: HttpRequest) -> HttpResponse {
|
pub async fn item(req: HttpRequest) -> HttpResponse {
|
||||||
// Build Reddit API path
|
// Build Reddit API path
|
||||||
let path = format!("{}.json?{}&raw_json=1", req.path(), req.query_string());
|
let mut path: String = format!("{}.json?{}&raw_json=1", req.path(), req.query_string());
|
||||||
|
|
||||||
// Set sort to sort query parameter or otherwise default sort
|
// Set sort to sort query parameter
|
||||||
let sort = if param(&path, "sort").is_empty() {
|
let mut sort: String = param(&path, "sort");
|
||||||
cookie(req.to_owned(), "comment_sort")
|
|
||||||
} else {
|
// Grab default comment sort method from Cookies
|
||||||
param(&path, "sort")
|
let default_sort = cookie(req.to_owned(), "comment_sort");
|
||||||
};
|
|
||||||
|
// If there's no sort query but there's a default sort, set sort to default_sort
|
||||||
|
if sort.is_empty() && !default_sort.is_empty() {
|
||||||
|
sort = default_sort;
|
||||||
|
path = format!("{}.json?{}&sort={}&raw_json=1", req.path(), req.query_string(), sort);
|
||||||
|
}
|
||||||
|
|
||||||
// Log the post ID being fetched in debug mode
|
// Log the post ID being fetched in debug mode
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
Loading…
Reference in New Issue
Block a user