From eb07a2ce7cdffc6c2aa45cae84396df0325d60f9 Mon Sep 17 00:00:00 2001 From: domve Date: Sun, 26 Feb 2023 08:40:32 +0100 Subject: [PATCH] Make gated subreddits accessible by treating them as quarantined (#722) * Fix gated communities being unviewable by treating them as quarantined * Show restriction reason in quarantine template * Add `gated` checks for other requests --- src/client.rs | 2 +- src/duplicates.rs | 4 ++-- src/post.rs | 4 ++-- src/search.rs | 4 ++-- src/subreddit.rs | 14 +++++++------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/client.rs b/src/client.rs index c947ac3..b1d15a6 100644 --- a/src/client.rs +++ b/src/client.rs @@ -142,7 +142,7 @@ fn request(method: &'static Method, path: String, redirect: bool, quarantine: bo .header("Accept-Encoding", if method == Method::GET { "gzip" } else { "identity" }) .header("Accept-Language", "en-US,en;q=0.5") .header("Connection", "keep-alive") - .header("Cookie", if quarantine { "_options=%7B%22pref_quarantine_optin%22%3A%20true%7D" } else { "" }) + .header("Cookie", if quarantine { "_options=%7B%22pref_quarantine_optin%22%3A%20true%2C%20%22pref_gated_sr_optin%22%3A%20true%7D" } else { "" }) .body(Body::empty()); async move { diff --git a/src/duplicates.rs b/src/duplicates.rs index 93f4df6..d747d46 100644 --- a/src/duplicates.rs +++ b/src/duplicates.rs @@ -210,9 +210,9 @@ pub async fn item(req: Request) -> Result, String> { // Process error. Err(msg) => { - if msg == "quarantined" { + if msg == "quarantined" || msg == "gated" { let sub = req.param("sub").unwrap_or_default(); - quarantine(req, sub) + quarantine(req, sub, msg) } else { error(req, msg).await } diff --git a/src/post.rs b/src/post.rs index 3031000..aba692e 100644 --- a/src/post.rs +++ b/src/post.rs @@ -78,9 +78,9 @@ pub async fn item(req: Request) -> Result, String> { } // If the Reddit API returns an error, exit and send error page to user Err(msg) => { - if msg == "quarantined" { + if msg == "quarantined" || msg == "gated" { let sub = req.param("sub").unwrap_or_default(); - quarantine(req, sub) + quarantine(req, sub, msg) } else { error(req, msg).await } diff --git a/src/search.rs b/src/search.rs index a8ac55f..35c0f96 100644 --- a/src/search.rs +++ b/src/search.rs @@ -145,9 +145,9 @@ pub async fn find(req: Request) -> Result, String> { }) } Err(msg) => { - if msg == "quarantined" { + if msg == "quarantined" || msg == "gated" { let sub = req.param("sub").unwrap_or_default(); - quarantine(req, sub) + quarantine(req, sub, msg) } else { error(req, msg).await } diff --git a/src/subreddit.rs b/src/subreddit.rs index 71692c4..e253885 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -144,7 +144,7 @@ pub async fn community(req: Request) -> Result, String> { }) } Err(msg) => match msg.as_str() { - "quarantined" => quarantine(req, sub_name), + "quarantined" | "gated" => quarantine(req, sub_name, msg), "private" => error(req, format!("r/{} is a private community", sub_name)).await, "banned" => error(req, format!("r/{} has been banned from Reddit", sub_name)).await, _ => error(req, msg).await, @@ -153,9 +153,9 @@ pub async fn community(req: Request) -> Result, String> { } } -pub fn quarantine(req: Request, sub: String) -> Result, String> { +pub fn quarantine(req: Request, sub: String, restriction: String) -> Result, String> { let wall = WallTemplate { - title: format!("r/{} is quarantined", sub), + title: format!("r/{} is {}", sub, restriction), msg: "Please click the button below to continue to this subreddit.".to_string(), url: req.uri().to_string(), sub, @@ -323,8 +323,8 @@ pub async fn wiki(req: Request) -> Result, String> { url, }), Err(msg) => { - if msg == "quarantined" { - quarantine(req, sub) + if msg == "quarantined" || msg == "gated" { + quarantine(req, sub, msg) } else { error(req, msg).await } @@ -361,8 +361,8 @@ pub async fn sidebar(req: Request) -> Result, String> { url, }), Err(msg) => { - if msg == "quarantined" { - quarantine(req, sub) + if msg == "quarantined" || msg == "gated" { + quarantine(req, sub, msg) } else { error(req, msg).await }