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
This commit is contained in:
parent
0b39d4f059
commit
eb07a2ce7c
5 changed files with 14 additions and 14 deletions
|
@ -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 {
|
||||
|
|
|
@ -210,9 +210,9 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, 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
|
||||
}
|
||||
|
|
|
@ -78,9 +78,9 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, 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
|
||||
}
|
||||
|
|
|
@ -145,9 +145,9 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, 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
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, 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<Body>) -> Result<Response<Body>, String> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn quarantine(req: Request<Body>, sub: String) -> Result<Response<Body>, String> {
|
||||
pub fn quarantine(req: Request<Body>, sub: String, restriction: String) -> Result<Response<Body>, 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<Body>) -> Result<Response<Body>, 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<Body>) -> Result<Response<Body>, String> {
|
|||
url,
|
||||
}),
|
||||
Err(msg) => {
|
||||
if msg == "quarantined" {
|
||||
quarantine(req, sub)
|
||||
if msg == "quarantined" || msg == "gated" {
|
||||
quarantine(req, sub, msg)
|
||||
} else {
|
||||
error(req, msg).await
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue