mirror of
https://github.com/redlib-org/redlib.git
synced 2025-05-15 14:32:50 +00:00
Fix bug with subreddit subscription case & RTL languages (#214)
* Fixed subreddit subscription case issues * Fixed formatting * Fixed flair RTL language issue (#132) * Convert display_lookup to Vec Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
This commit is contained in:
parent
1211d781d0
commit
242ffab0da
2 changed files with 21 additions and 1 deletions
|
@ -99,8 +99,27 @@ pub async fn subscriptions(req: Request<Body>) -> Result<Response<Body>, String>
|
|||
|
||||
let mut sub_list = Preferences::new(req).subscriptions;
|
||||
|
||||
// Retrieve list of posts for these subreddits to extract display names
|
||||
let display = json(format!("/r/{}/hot.json?raw_json=1", sub)).await?;
|
||||
let display_lookup: Vec<(String, &str)> = display["data"]["children"].as_array().unwrap().iter().map(|post| {
|
||||
let display_name = post["data"]["subreddit"].as_str().unwrap();
|
||||
(display_name.to_lowercase(), display_name)
|
||||
}).collect();
|
||||
|
||||
// Find each subreddit name (separated by '+') in sub parameter
|
||||
for part in sub.split('+') {
|
||||
// Retrieve display name for the subreddit
|
||||
let display;
|
||||
let part = if let Some(&(_, display)) = display_lookup.iter().find(|x| x.0 == part.to_lowercase()) {
|
||||
// This is already known, doesn't require seperate request
|
||||
display
|
||||
} else {
|
||||
// This subreddit display name isn't known, retrieve it
|
||||
let path: String = format!("/r/{}/about.json?raw_json=1", part);
|
||||
display = json(path).await?;
|
||||
display["data"]["display_name"].as_str().ok_or_else(|| "Failed to query subreddit name".to_string())?
|
||||
};
|
||||
|
||||
// Modify sub list based on action
|
||||
if action.contains(&"subscribe".to_string()) && !sub_list.contains(&part.to_owned()) {
|
||||
// Add each sub name to the subscribed list
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue