Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Represent "restricted" subreddits as private & code cleanup #76

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

MaxDeVos
Copy link

@MaxDeVos MaxDeVos commented Jun 12, 2023

I have implemented a system to detect subreddits that are not accepting submissions and mark them as private accordingly by taking advantage of the details provided at /r/<subreddit>/about.json. This strategy allows us to use the same number of requests as the current system to achieve this. Thank you to @DavidCano98 for pointing out the existence of about.json, as it is far more elegant than the xpath-scraping solution I had created beforehand.

Many subreddits are opting to restrict submissions instead of privating the subreddit to allow their "protest" mod posts to reach the front page. Many large subreddits are doing this, such as r/Pics, so this fixes an enormous gap in representation.

This pull request also includes a lot of code cleanup, additional comments, and standardization which will make contribution more approachable to others.

The crux of the restriction identification system can be seen in this excerpt:

const resp = JSON.parse(data);

let isPrivate = resp["error"] === 403       // this case occurs when subreddit is private
let isRestricted = resp["data"] !== undefined &&
    resp["data"]["subreddit_type"] === "restricted"  // when subreddit is restricted
let effectivelyPrivate = isPrivate || isRestricted; // if either is true, it's participating

let subredditPreviouslyPrivate = subreddits[section][subreddit].status === "private";

if (resp['error'] === 500) {
    console.log("We're probably getting blocked... (500) - " + resp);
    return;
}

// If previously public subreddit has become private
if (effectivelyPrivate && !subredditPreviouslyPrivate) {
    subreddits[section][subreddit].status = "private";
    if (!firstCheck)
        io.emit("update", subreddits[section][subreddit]);
    else
        io.emit("updatenew", subreddits[section][subreddit]);
    console.log(`PRIVATE: ${subreddits[section][subreddit].name}`)
    // console.log(resp);

// if subreddit status was private and is now public
} else if (!effectivelyPrivate && subredditPreviouslyPrivate) {
    console.log(`PUBLIC: ${subreddits[section][subreddit].name}`)
    // console.log(resp);
    subreddits[section][subreddit].status = "public";
    io.emit("updatenew", subreddits[section][subreddit]);
}

@MaxDeVos
Copy link
Author

@DavidCano98 kindly pointed out to me that there is a way to access the subreddit status trivially through a GET request. I will be updating this pull request accordingly.

@MaxDeVos
Copy link
Author

I have updated the original pull request message to match the new code. It is ready to be merged.

@MaxDeVos
Copy link
Author

I see a number of changes have been made to the main branch, breaking this PR's ability to merge. I am working on catching it up to date.

@MaxDeVos
Copy link
Author

I have locally merged my code with the latest code on origin/main. @Tanza3D, please consider merging this in, it would be an enormous leap in functionality for the site.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant