From 9e5ddcbd921d97f0d96c3a04cf79250ab6e93d9e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 19 Aug 2022 23:31:26 +0200 Subject: [PATCH] large commit: stealth mode, SubJoin, chudtopia dont read if u value ur sanity --- files/assets/css/main.css | 6 +- files/classes/__init__.py | 3 +- files/classes/sub.py | 1 + files/classes/sub_join.py | 10 ++++ files/classes/user.py | 9 ++- files/routes/front.py | 5 +- files/routes/posts.py | 2 +- files/routes/subs.py | 74 +++++++++++++++++++++---- files/templates/comments.html | 6 +- files/templates/home.html | 18 ++++-- files/templates/sidebar_PCM.html | 2 - files/templates/sidebar_WPD.html | 10 +--- files/templates/sidebar_rDrama.html | 2 - files/templates/sub/settings.html | 12 ++++ files/templates/sub/subs.html | 10 +--- files/templates/submission_listing.html | 2 +- files/templates/util/assetcache.html | 2 +- 17 files changed, 127 insertions(+), 47 deletions(-) create mode 100644 files/classes/sub_join.py diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 2f96b7f96..5e3929e0e 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -744,8 +744,6 @@ input[type=submit].btn-block, input[type=reset].btn-block, input[type=button].bt .btn-follow { display: block; width: 100%; -} -.btn-follow + .btn-follow { margin-top: 0.5rem; } input[type=submit].btn-follow, input[type=reset].btn-follow, input[type=button].btn-follow { @@ -6243,4 +6241,8 @@ g { .desktop-expanded-image-modal::-webkit-scrollbar { -ms-overflow-style: none; scrollbar-width: none; +} + +.text-stealth { + color: #a4f5f3 !important; } \ No newline at end of file diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 1fd0f795c..f92478124 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -17,8 +17,9 @@ from .award import * from .marsey import * from .sub_block import * from .sub_subscription import * +from .sub_join import * from .saves import * from .views import * from .notifications import * from .follows import * -from .lottery import * +from .lottery import * \ No newline at end of file diff --git a/files/classes/sub.py b/files/classes/sub.py index 764657ad6..8236c2bb8 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -19,6 +19,7 @@ class Sub(Base): sidebarurl = Column(String) bannerurl = Column(String) css = Column(String) + stealth = Column(Boolean) blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name") followers = relationship("SubSubscription", primaryjoin="SubSubscription.sub==Sub.name") diff --git a/files/classes/sub_join.py b/files/classes/sub_join.py new file mode 100644 index 000000000..7bb60780f --- /dev/null +++ b/files/classes/sub_join.py @@ -0,0 +1,10 @@ +from sqlalchemy import * +from files.__main__ import Base + +class SubJoin(Base): + __tablename__ = "sub_joins" + user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) + sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) + + def __repr__(self): + return f"" \ No newline at end of file diff --git a/files/classes/user.py b/files/classes/user.py index 8a440f1e3..ab1e95172 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -19,6 +19,7 @@ from .mod import * from .exiles import * from .sub_block import * from .sub_subscription import * +from .sub_join import * from files.__main__ import Base, cache from files.helpers.security import * from copy import deepcopy @@ -173,12 +174,18 @@ class User(Base): @property @lazy def all_blocks(self): - return ['smuggies','braincels'] + [x[0] for x in g.db.query(SubBlock.sub).filter_by(user_id=self.id).all()] + stealth = set([x[0] for x in g.db.query(Sub.name).filter_by(stealth=True).all()]) - set([x[0] for x in g.db.query(SubJoin.sub).filter_by(user_id=self.id).all()]) + + return list(stealth) + [x[0] for x in g.db.query(SubBlock.sub).filter_by(user_id=self.id).all()] @lazy def blocks(self, sub): return g.db.query(SubBlock).filter_by(user_id=self.id, sub=sub).one_or_none() + @lazy + def subscribes(self, sub): + return g.db.query(SubJoin).filter_by(user_id=self.id, sub=sub).one_or_none() + @property @lazy def all_follows(self): diff --git a/files/routes/front.py b/files/routes/front.py index 0dccc3930..5fc3b092d 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -27,7 +27,10 @@ def front_all(v, sub=None, subdomain=None): if not redir.startswith('/'): redir = f'/{redir}' return redirect(redir) - if sub: sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() + if sub: + sub = sub.strip().lower() + if sub == 'chudtopia' and not (v and v.truecoins >= 20000): abort(403) + sub = g.db.query(Sub).filter_by(name=sub).one_or_none() if (request.path.startswith('/h/') or request.path.startswith('/s/')) and not sub: abort(404) diff --git a/files/routes/posts.py b/files/routes/posts.py index 8e5b25516..22cd3b410 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1074,7 +1074,7 @@ def submit_post(v, sub=None): post.downvotes += 1 g.db.add(post) - if SITE == 'rdrama.net' and post.sub and post.sub not in ('dankchristianmemes','fatpeoplehate','braincels','truth','smuggies') and v.id != AEVANN_ID: + if SITE == 'rdrama.net' and post.sub and post.sub not in ('dankchristianmemes','fatpeoplehate','braincels','truth','smuggies','chudtopia') and v.id != AEVANN_ID: g.db.flush() autovote = Vote( user_id=AEVANN_ID, diff --git a/files/routes/subs.py b/files/routes/subs.py index b7f659efc..629ac4be7 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -95,8 +95,6 @@ def block_sub(v, sub): if not sub: abort(404) sub = sub.name - if v.mods(sub): return {"error": f"You can't block {HOLE_NAME}s you mod!"} - existing = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub).one_or_none() if not existing: @@ -104,7 +102,7 @@ def block_sub(v, sub): g.db.add(block) cache.delete_memoized(frontlist) - return {"message": f"{HOLE_NAME.capitalize()} blocked successfully!"} + return {"message": "Action successful!"} @app.post("/h//unblock") @@ -120,7 +118,39 @@ def unblock_sub(v, sub): g.db.delete(block) cache.delete_memoized(frontlist) - return {"message": f"{HOLE_NAME.capitalize()} unblocked successfully!"} + return {"message": "Action successful!"} + + +@app.post("/h//subscribe") +@auth_required +def subscribe_sub(v, sub): + sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() + if not sub: abort(404) + sub = sub.name + + existing = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none() + + if not existing: + subscribe = SubJoin(user_id=v.id, sub=sub) + g.db.add(subscribe) + cache.delete_memoized(frontlist) + + return {"message": "Action successful!"} + +@app.post("/h//unsubscribe") +@auth_required +def unsubscribe_sub(v, sub): + sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() + if not sub: abort(404) + sub = sub.name + + subscribe = g.db.query(SubJoin).filter_by(user_id=v.id, sub=sub).one_or_none() + + if subscribe: + g.db.delete(subscribe) + cache.delete_memoized(frontlist) + + return {"message": "Action successful!"} @app.post("/h//follow") @auth_required @@ -128,13 +158,14 @@ def follow_sub(v, sub): sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() if not sub: abort(404) - existing = g.db.query(SubSubscription) \ - .filter_by(user_id=v.id, sub=sub.name).one_or_none() + existing = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none() + if not existing: subscription = SubSubscription(user_id=v.id, sub=sub.name) g.db.add(subscription) + cache.delete_memoized(frontlist) - return {"message": f"{HOLE_NAME.capitalize()} followed successfully!"} + return {"message": f"Action successful!"} @app.post("/h//unfollow") @auth_required @@ -142,12 +173,13 @@ def unfollow_sub(v, sub): sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() if not sub: abort(404) - subscription = g.db.query(SubSubscription) \ - .filter_by(user_id=v.id, sub=sub.name).one_or_none() + subscription = g.db.query(SubSubscription).filter_by(user_id=v.id, sub=sub.name).one_or_none() + if subscription: g.db.delete(subscription) + cache.delete_memoized(frontlist) - return {"message": f"{HOLE_NAME.capitalize()} unfollowed successfully!"} + return {"message": f"Action successful!"} @app.get("/h//mods") @auth_required @@ -291,6 +323,7 @@ def create_sub2(v): sub = Sub(name=name) g.db.add(sub) + g.db.flush() mod = Mod(user_id=v.id, sub=sub.name) g.db.add(mod) @@ -476,4 +509,23 @@ def hole_unpin(v, pid): message = f"@{v.username} (Mod) has unpinned your [post]({p.shortlink}) in /h/{p.sub}" send_repeatable_notification(p.author_id, message) - return {"message": f"Post unpinned from /h/{p.sub}"} \ No newline at end of file + return {"message": f"Post unpinned from /h/{p.sub}"} + + +@app.post('/h//stealth') +@is_not_permabanned +def sub_stealth(v, sub): + sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() + if not sub: abort(404) + + if not v.mods(sub.name): abort(403) + + sub.stealth = not sub.stealth + g.db.add(sub) + + cache.delete_memoized(frontlist) + + if sub.stealth: + return {"message": f"Stealth mode enabled!"} + else: + return {"message": f"Stealth mode disabled!"} \ No newline at end of file diff --git a/files/templates/comments.html b/files/templates/comments.html index 42c188f0c..4e6a57484 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -90,7 +90,7 @@ {% if render_replies %} {% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %}
- {% for reply in replies %} + {% for reply in replies if not reply.parent_submission or reply.post.sub != 'chudtopia' or (v and v.truecoins >= 20000) %} {{single_comment(reply, level=level+1)}} {% endfor %}
@@ -601,7 +601,7 @@ {% if render_replies %} {% if level<9 or request.path.startswith('/notifications') or request.headers.get("xhr") %}
- {% for reply in replies %} + {% for reply in replies if not reply.parent_submission or reply.post.sub != 'chudtopia' or (v and v.truecoins >= 20000) %} {{single_comment(reply, level=level+1)}} {% endfor %}
@@ -785,7 +785,7 @@ {% endmacro %} -{% for comment in comments %} +{% for comment in comments if not comment.parent_submission or comment.post.sub != 'chudtopia' or (v and v.truecoins >= 20000) %} {{single_comment(comment)}} diff --git a/files/templates/home.html b/files/templates/home.html index cda950423..c9790c706 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -52,14 +52,20 @@ {% endif %} diff --git a/files/templates/sidebar_PCM.html b/files/templates/sidebar_PCM.html index 80ff630b2..94a819dfe 100644 --- a/files/templates/sidebar_PCM.html +++ b/files/templates/sidebar_PCM.html @@ -16,8 +16,6 @@ {% endif %} {{HOLE_NAME|upper}} MODS {{HOLE_NAME|upper}} EXILEES - {{HOLE_NAME|upper}} FOLLOWERS - {{HOLE_NAME|upper}} BLOCKERS {% endif %} {% if v and v.can_create_hole -%} diff --git a/files/templates/sidebar_WPD.html b/files/templates/sidebar_WPD.html index 085616ed5..b1134bdae 100644 --- a/files/templates/sidebar_WPD.html +++ b/files/templates/sidebar_WPD.html @@ -17,14 +17,8 @@

- {% if sub %} - {% if sub.sidebar_html %} -
{{sub.sidebar_html|safe}}
- {% endif %} - {% if v and v.mods(sub.name) %} - {{HOLE_NAME|upper}} FOLLOWERS - {{HOLE_NAME|upper}} BLOCKERS - {% endif %} + {% if sub and sub.sidebar_html %} +
{{sub.sidebar_html|safe}}
{% endif %} {% endif %} + +
+ +
+
+
+ + +
+ Hide posts in this hole from the main feed for non-subscribers. +
+

Sidebar Picture

diff --git a/files/templates/sub/subs.html b/files/templates/sub/subs.html index cdae0aef8..d0f24be8f 100644 --- a/files/templates/sub/subs.html +++ b/files/templates/sub/subs.html @@ -13,18 +13,14 @@ # Name Posts - Followers - Blockers {% for sub, count in subs %} - {{loop.index}} - {{sub.name}} - {{count}} - {{sub.follow_num}} - {{sub.block_num}} + {{loop.index}} + {{sub.name}} + {{count}} {% endfor %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 9ffc1ebe5..079ca7016 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -58,7 +58,7 @@
-{% for p in listing %} +{% for p in listing if p.sub != 'chudtopia' or (v and v.truecoins >= 20000) %} {% set ups=p.upvotes %} {% set downs=p.downvotes %} diff --git a/files/templates/util/assetcache.html b/files/templates/util/assetcache.html index 6debda65f..e26a5ab13 100644 --- a/files/templates/util/assetcache.html +++ b/files/templates/util/assetcache.html @@ -1,6 +1,6 @@ {%- set CACHE_VER = { - 'css/main.css': 461, + 'css/main.css': 464, 'css/catalog.css': 2, 'css/4chan.css': 61,