Merge remote-tracking branch 'origin/pull/536'

This commit is contained in:
Matthew Esposito 2023-12-26 15:20:21 -05:00
commit 0eb5e18cef
No known key found for this signature in database
6 changed files with 103 additions and 32 deletions

View file

@ -572,7 +572,7 @@ pub struct Preferences {
pub hide_hls_notification: String,
pub use_hls: String,
pub autoplay_videos: String,
pub disable_visit_reddit_confirmation: String,
pub fixed_navbar: String,
pub comment_sort: String,
pub post_sort: String,
pub subscriptions: Vec<String>,
@ -607,7 +607,7 @@ impl Preferences {
use_hls: setting(&req, "use_hls"),
hide_hls_notification: setting(&req, "hide_hls_notification"),
autoplay_videos: setting(&req, "autoplay_videos"),
disable_visit_reddit_confirmation: setting(&req, "disable_visit_reddit_confirmation"),
fixed_navbar: setting_or_default(&req, "fixed_navbar", "on".to_string()),
comment_sort: setting(&req, "comment_sort"),
post_sort: setting(&req, "post_sort"),
subscriptions: setting(&req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(),
@ -769,6 +769,16 @@ pub fn setting(req: &Request<Body>, name: &str) -> String {
.to_string()
}
// Retrieve the value of a setting by name or the default value
pub fn setting_or_default(req: &Request<Body>, name: &str, default: String) -> String {
let value = setting(req, name);
if !value.is_empty() {
value
} else {
default
}
}
// Detect and redirect in the event of a random subreddit
pub async fn catch_random(sub: &str, additional: &str) -> Result<Response<Body>, String> {
if sub == "random" || sub == "randnsfw" {