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
@ -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-Encoding", if method == Method::GET { "gzip" } else { "identity" })
|
||||||
.header("Accept-Language", "en-US,en;q=0.5")
|
.header("Accept-Language", "en-US,en;q=0.5")
|
||||||
.header("Connection", "keep-alive")
|
.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());
|
.body(Body::empty());
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
|
@ -210,9 +210,9 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
|
|
||||||
// Process error.
|
// Process error.
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
if msg == "quarantined" {
|
if msg == "quarantined" || msg == "gated" {
|
||||||
let sub = req.param("sub").unwrap_or_default();
|
let sub = req.param("sub").unwrap_or_default();
|
||||||
quarantine(req, sub)
|
quarantine(req, sub, msg)
|
||||||
} else {
|
} else {
|
||||||
error(req, msg).await
|
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
|
// If the Reddit API returns an error, exit and send error page to user
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
if msg == "quarantined" {
|
if msg == "quarantined" || msg == "gated" {
|
||||||
let sub = req.param("sub").unwrap_or_default();
|
let sub = req.param("sub").unwrap_or_default();
|
||||||
quarantine(req, sub)
|
quarantine(req, sub, msg)
|
||||||
} else {
|
} else {
|
||||||
error(req, msg).await
|
error(req, msg).await
|
||||||
}
|
}
|
||||||
|
@ -145,9 +145,9 @@ pub async fn find(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
if msg == "quarantined" {
|
if msg == "quarantined" || msg == "gated" {
|
||||||
let sub = req.param("sub").unwrap_or_default();
|
let sub = req.param("sub").unwrap_or_default();
|
||||||
quarantine(req, sub)
|
quarantine(req, sub, msg)
|
||||||
} else {
|
} else {
|
||||||
error(req, msg).await
|
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() {
|
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,
|
"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,
|
"banned" => error(req, format!("r/{} has been banned from Reddit", sub_name)).await,
|
||||||
_ => error(req, msg).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 {
|
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(),
|
msg: "Please click the button below to continue to this subreddit.".to_string(),
|
||||||
url: req.uri().to_string(),
|
url: req.uri().to_string(),
|
||||||
sub,
|
sub,
|
||||||
@ -323,8 +323,8 @@ pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
url,
|
url,
|
||||||
}),
|
}),
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
if msg == "quarantined" {
|
if msg == "quarantined" || msg == "gated" {
|
||||||
quarantine(req, sub)
|
quarantine(req, sub, msg)
|
||||||
} else {
|
} else {
|
||||||
error(req, msg).await
|
error(req, msg).await
|
||||||
}
|
}
|
||||||
@ -361,8 +361,8 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
url,
|
url,
|
||||||
}),
|
}),
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
if msg == "quarantined" {
|
if msg == "quarantined" || msg == "gated" {
|
||||||
quarantine(req, sub)
|
quarantine(req, sub, msg)
|
||||||
} else {
|
} else {
|
||||||
error(req, msg).await
|
error(req, msg).await
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user