Merge remote-tracking branch 'origin/pull/746'
This commit is contained in:
commit
fc4b686607
@ -212,19 +212,23 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>,
|
|||||||
let mut filters = preferences.filters;
|
let mut filters = preferences.filters;
|
||||||
|
|
||||||
// Retrieve list of posts for these subreddits to extract display names
|
// Retrieve list of posts for these subreddits to extract display names
|
||||||
let posts = json(format!("/r/{}/hot.json?raw_json=1", sub), true).await?;
|
|
||||||
let display_lookup: Vec<(String, &str)> = posts["data"]["children"]
|
let posts = json(format!("/r/{}/hot.json?raw_json=1", sub), true).await;
|
||||||
.as_array()
|
let display_lookup: Vec<(String, &str)> = match &posts {
|
||||||
.map(|list| {
|
Ok(posts) => posts["data"]["children"]
|
||||||
list
|
.as_array()
|
||||||
.iter()
|
.map(|list| {
|
||||||
.map(|post| {
|
list
|
||||||
let display_name = post["data"]["subreddit"].as_str().unwrap_or_default();
|
.iter()
|
||||||
(display_name.to_lowercase(), display_name)
|
.map(|post| {
|
||||||
})
|
let display_name = post["data"]["subreddit"].as_str().unwrap_or_default();
|
||||||
.collect::<Vec<_>>()
|
(display_name.to_lowercase(), display_name)
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.unwrap_or_default(),
|
||||||
|
Err(_) => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
// Find each subreddit name (separated by '+') in sub parameter
|
// Find each subreddit name (separated by '+') in sub parameter
|
||||||
for part in sub.split('+').filter(|x| x != &"") {
|
for part in sub.split('+').filter(|x| x != &"") {
|
||||||
@ -238,8 +242,12 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>,
|
|||||||
} else {
|
} else {
|
||||||
// This subreddit display name isn't known, retrieve it
|
// This subreddit display name isn't known, retrieve it
|
||||||
let path: String = format!("/r/{}/about.json?raw_json=1", part);
|
let path: String = format!("/r/{}/about.json?raw_json=1", part);
|
||||||
display = json(path, true).await?;
|
display = json(path, true).await;
|
||||||
display["data"]["display_name"].as_str().ok_or_else(|| "Failed to query subreddit name".to_string())?
|
match &display {
|
||||||
|
Ok(display) => display["data"]["display_name"].as_str(),
|
||||||
|
Err(_) => None,
|
||||||
|
}
|
||||||
|
.unwrap_or(part)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Modify sub list based on action
|
// Modify sub list based on action
|
||||||
|
Loading…
Reference in New Issue
Block a user