Ignore errors while fetching subreddit names in subscriptions_filters()
If we can't retrieve subreddit name, just use the user-supplied name. This fixes banned subreddits being impossible to to unfilter or unsubscribe from. A drawback of such approach is that it might be possible to subscribe to a subreddit twice with different casing, however the chance of this is extremely low.
This commit is contained in:
parent
51cdf574f7
commit
741613e27f
1 changed files with 23 additions and 15 deletions
|
@ -211,8 +211,10 @@ 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;
|
||||||
|
let display_lookup: Vec<(String, &str)> = match &posts {
|
||||||
|
Ok(posts) => posts["data"]["children"]
|
||||||
.as_array()
|
.as_array()
|
||||||
.map(|list| {
|
.map(|list| {
|
||||||
list
|
list
|
||||||
|
@ -223,7 +225,9 @@ pub async fn subscriptions_filters(req: Request<Body>) -> Result<Response<Body>,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.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 != &"") {
|
||||||
|
@ -237,8 +241,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 a new issue