diff --git a/files/classes/sub.py b/files/classes/sub.py index 31efb815ca..45c085c971 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -11,7 +11,6 @@ if SITE == "localhost": SITE_FULL = 'http://' + SITE else: SITE_FULL = 'https://' + SITE class Sub(Base): - __tablename__ = "subs" name = Column(String, primary_key=True) sidebar = Column(String) @@ -20,8 +19,10 @@ class Sub(Base): bannerurl = Column(String) css = Column(String) - blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name", viewonly=True) - + blocks = relationship("SubBlock", + primaryjoin="SubBlock.sub==Sub.name", viewonly=True) + followers = relationship("SubSubscription", + primaryjoin="SubSubscription.sub==Sub.name", viewonly=True) def __repr__(self): return f"" diff --git a/files/classes/sub_block.py b/files/classes/sub_block.py index 56ae099b1c..6fd57e86a6 100644 --- a/files/classes/sub_block.py +++ b/files/classes/sub_block.py @@ -3,10 +3,18 @@ from sqlalchemy.orm import relationship from files.__main__ import Base class SubBlock(Base): - __tablename__ = "sub_blocks" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) - sub = Column(String, ForeignKey("subs.name"), primary_key=True) + sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) def __repr__(self): - return f"" \ No newline at end of file + return f"" + +class SubSubscription(Base): + __tablename__ = "sub_subscriptions" + 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"" + diff --git a/files/classes/user.py b/files/classes/user.py index 839015367f..d547f6e3d8 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -171,6 +171,15 @@ class User(Base): def blocks(self, sub): return g.db.query(SubBlock).filter_by(user_id=self.id, sub=sub).one_or_none() + @property + @lazy + def all_follows(self): + return [x[0] for x in g.db.query(SubSubscription.sub).filter_by(user_id=self.id).all()] + + @lazy + def follows(self, sub): + return g.db.query(SubSubscription).filter_by(user_id=self.id, sub=sub).one_or_none() + @lazy def mod_date(self, sub): if self.id == AEVANN_ID: return 1 diff --git a/files/helpers/const.py b/files/helpers/const.py index 2ab1e56b73..40b859f617 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -134,7 +134,7 @@ POST_RATE_LIMIT = "1/second;2/minute;10/hour;50/day" USER_TITLE_COST = 0 if SITE in {'rdrama.net','devrama.xyz'}: - HOLE_COST = 200000 + HOLE_COST = 50000 USER_TITLE_COST = 25 NOTIFICATIONS_ID = 1046 AUTOJANNY_ID = 2360 diff --git a/files/routes/posts.py b/files/routes/posts.py index 7ee5e085ae..0dbadfbc49 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -85,6 +85,16 @@ def publish(pid, v): if post.club and not user.paid_dues: continue add_notif(cid, user.id) + if post.sub and post.subr: + sub_name = post.subr.name + text = f"/h/{sub_name} has a new " \ + + f"post: [{post.title}]({post.shortlink})" + cid = notif_comment(text, autojanny=True) + for follow in post.subr.followers: + user = get_account(follow.user_id) + if post.club and not user.paid_dues: continue + add_notif(cid, user.id) + g.db.commit() cache.delete_memoized(frontlist) @@ -1114,9 +1124,15 @@ def submit_post(v, sub=None): if post.club and not user.paid_dues: continue add_notif(cid, user.id) - - - + if post.sub and post.subr: + sub_name = post.subr.name + text = f"/h/{sub_name} has a new " \ + + f"post: [{post.title}]({post.shortlink})" + cid = notif_comment(text, autojanny=True) + for follow in post.subr.followers: + user = get_account(follow.user_id) + if post.club and not user.paid_dues: continue + add_notif(cid, user.id) if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in f'{post.body}{post.title}'.lower(): post.is_banned = True diff --git a/files/routes/subs.py b/files/routes/subs.py index 9c9a8c3168..4542ae30c6 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -121,6 +121,35 @@ def unblock_sub(v, sub): return {"message": "Sub unblocked successfully!"} +@app.post("/h//follow") +@auth_required +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() + if not existing: + subscription = SubSubscription(user_id=v.id, sub=sub.name) + g.db.add(subscription) + g.db.commit() + + return {"message": "Sub followed successfully!"} + +@app.post("/h//unfollow") +@auth_required +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() + if subscription: + g.db.delete(subscription) + g.db.commit() + + return {"message": "Sub unfollowed successfully!"} + @app.get("/h//mods") @auth_required def mods(v, sub): @@ -134,7 +163,7 @@ def mods(v, sub): @app.get("/h//exilees") @auth_required -def exilees(v, sub): +def sub_exilees(v, sub): sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() if not sub: abort(404) @@ -145,14 +174,27 @@ def exilees(v, sub): @app.get("/h//blockers") @auth_required -def blockers(v, sub): +def sub_blockers(v, sub): sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() if not sub: abort(404) users = g.db.query(User).join(SubBlock, SubBlock.user_id==User.id).filter_by(sub=sub.name).all() - return render_template("sub/blockers.html", v=v, sub=sub, users=users) + return render_template("sub/blockers.html", + v=v, sub=sub, users=users, verb="blocking") +@app.get("/h//followers") +@auth_required +def sub_followers(v, sub): + sub = g.db.query(Sub).filter_by(name=sub.strip().lower()).one_or_none() + if not sub: abort(404) + + users = g.db.query(User) \ + .join(SubSubscription, SubSubscription.user_id==User.id) \ + .filter_by(sub=sub.name).all() + + return render_template("sub/blockers.html", + v=v, sub=sub, users=users, verb="following") @app.post("/h//add_mod") diff --git a/files/templates/home.html b/files/templates/home.html index 2056c26e05..a0240b35b8 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -44,6 +44,9 @@ {% if sub %}
{% if v %} + Follow /h/{{sub.name}} + Unfollow /h/{{sub.name}} + Block /h/{{sub.name}} Unblock /h/{{sub.name}} {% else %} diff --git a/files/templates/sidebar_Cringetopia.html b/files/templates/sidebar_Cringetopia.html index 243d0c175d..9735897ee3 100644 --- a/files/templates/sidebar_Cringetopia.html +++ b/files/templates/sidebar_Cringetopia.html @@ -26,6 +26,7 @@ {% endif %} HOLE MODS HOLE EXILEES + HOLE FOLLOWERS HOLE BLOCKERS {% else %} CREATE HOLE diff --git a/files/templates/sidebar_PCM.html b/files/templates/sidebar_PCM.html index 65158edc10..32b491231a 100644 --- a/files/templates/sidebar_PCM.html +++ b/files/templates/sidebar_PCM.html @@ -15,6 +15,7 @@ {% endif %} HOLE MODS HOLE EXILEES + HOLE FOLLOWERS HOLE BLOCKERS {% endif %} diff --git a/files/templates/sidebar_WPD.html b/files/templates/sidebar_WPD.html index 2c0a7bdfe1..f0f41b832f 100644 --- a/files/templates/sidebar_WPD.html +++ b/files/templates/sidebar_WPD.html @@ -26,6 +26,7 @@ {% endif %} HOLE MODS HOLE EXILEES + HOLE FOLLOWERS HOLE BLOCKERS {% else %}
diff --git a/files/templates/sidebar_rDrama.html b/files/templates/sidebar_rDrama.html index d02cc2cc32..3af146a94f 100644 --- a/files/templates/sidebar_rDrama.html +++ b/files/templates/sidebar_rDrama.html @@ -70,6 +70,7 @@ set VISITORS_HERE_FLAVOR = [ {% endif %} HOLE MODS HOLE EXILEES + HOLE FOLLOWERS HOLE BLOCKERS {% else %} {% if v %} diff --git a/files/templates/sub/blockers.html b/files/templates/sub/blockers.html index 055c93f3a3..bc882618cb 100644 --- a/files/templates/sub/blockers.html +++ b/files/templates/sub/blockers.html @@ -4,7 +4,7 @@ -
Users blocking /h/{{sub.name}}
+
Users {{verb}} /h/{{sub.name}}

 
diff --git a/files/templates/util/assetcache.html b/files/templates/util/assetcache.html index cbe0d82ea4..04a3b5b59d 100644 --- a/files/templates/util/assetcache.html +++ b/files/templates/util/assetcache.html @@ -1,6 +1,6 @@ {%- set CACHE_VER = { - 'css/main.css': 296, + 'css/main.css': 297, 'css/4chan.css': 59, 'css/classic.css': 59,