diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 3265b5b01..6723e92a2 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -15,6 +15,7 @@ from .mod_logs import * from .award import * from .marsey import * from .sub_block import * +from .sub_subscription import * from .saves import * from .views import * from .notifications import * diff --git a/files/classes/sub.py b/files/classes/sub.py index ca65feee2..5851dfe7c 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -4,6 +4,7 @@ from files.__main__ import Base from files.helpers.lazy import lazy from os import environ from .sub_block import * +from .sub_subscription import * SITE_NAME = environ.get("SITE_NAME", '').strip() SITE = environ.get("DOMAIN", '').strip() diff --git a/files/classes/sub_block.py b/files/classes/sub_block.py index 6fd57e86a..cfdcad141 100644 --- a/files/classes/sub_block.py +++ b/files/classes/sub_block.py @@ -1,5 +1,4 @@ from sqlalchemy import * -from sqlalchemy.orm import relationship from files.__main__ import Base class SubBlock(Base): @@ -8,13 +7,4 @@ class SubBlock(Base): sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) def __repr__(self): - 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"" - + return f"" \ No newline at end of file diff --git a/files/classes/sub_subscription.py b/files/classes/sub_subscription.py new file mode 100644 index 000000000..a82ffc885 --- /dev/null +++ b/files/classes/sub_subscription.py @@ -0,0 +1,10 @@ +from sqlalchemy import * +from files.__main__ import Base + +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"" \ No newline at end of file diff --git a/files/classes/user.py b/files/classes/user.py index 34c8fcb91..4d33d0b38 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -17,6 +17,7 @@ from .mod_logs import * from .mod import * from .exiles import * from .sub_block import * +from .sub_subscription import * from .submission import sort_posts from files.__main__ import Base, cache from files.helpers.security import * @@ -450,9 +451,14 @@ class User(Base): @property @lazy - def following_ids(self): + def followed_users(self): return [x[0] for x in g.db.query(Follow.target_id).filter_by(user_id=self.id).all()] + @property + @lazy + def followed_subs(self): + return [x[0] for x in g.db.query(SubSubscription.sub).filter_by(user_id=self.id).all()] + @property @lazy def notifications_count(self): @@ -476,7 +482,16 @@ class User(Base): @property @lazy def post_notifications_count(self): - return g.db.query(Submission).filter(Submission.author_id.in_(self.following_ids), Submission.created_utc > self.last_viewed_post_notifs, Submission.deleted_utc == 0, Submission.is_banned == False).count() + return g.db.query(Submission).filter( + or_( + Submission.author_id.in_(self.followed_users), + Submission.sub.in_(self.followed_subs) + ), + Submission.created_utc > self.last_viewed_post_notifs, + Submission.deleted_utc == 0, + Submission.is_banned == False, + Submission.private == False + ).count() @property @lazy @@ -486,7 +501,7 @@ class User(Base): Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0, Comment.body_html.like(f'%

{NOTIF_MODACTION_PREFIX}%'), - Comment.parent_submission == None, Comment.author_id == NOTIFICATIONS_ID).count() + Comment.parent_submission == None, Comment.author_id == AUTOJANNY_ID).count() @property @lazy @@ -496,7 +511,7 @@ class User(Base): Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0, Comment.body_html.like('%

New site mention: %' - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.parent_submission == None, Comment.body_html.like(search_html)).first() + existing = g.db.query(Comment.id).filter(Comment.author_id == AUTOJANNY_ID, Comment.parent_submission == None, Comment.body_html.like(search_html)).first() if existing: return existing[0] else: @@ -122,11 +98,12 @@ def NOTIFY_USERS(text, v): def notify_mod_action(by_id, msg): body_html = sanitize(NOTIF_MODACTION_PREFIX + msg) new_comment = Comment( - author_id=NOTIFICATIONS_ID, + author_id=AUTOJANNY_ID, parent_submission=None, level=1, body_html=body_html, - distinguish_level=6) + distinguish_level=6, + is_bot=True) g.db.add(new_comment) g.db.flush() new_comment.top_comment_id = new_comment.id @@ -164,24 +141,4 @@ if PUSHER_ID != 'blahblahblah': } }, ) - stdout.flush() - - - -def on_post_hole_entered(post, v=None): - if not post.sub or not post.subr: - return - hole = post.subr.name - author = post.author - - # Notify hole followers - if not post.ghost and not post.private and not author.shadowbanned: - text = f"/h/{hole} has a new " \ - + f"post: [{post.title}]({post.shortlink}) by @{author.username}" - cid = notif_comment(text, autojanny=True) - for follow in post.subr.followers: - if follow.user_id == author.id or (v and follow.user_id == v.id): - continue - user = get_account(follow.user_id) - if post.club and not user.paid_dues: continue - add_notif(cid, user.id) \ No newline at end of file + stdout.flush() \ No newline at end of file diff --git a/files/helpers/const.py b/files/helpers/const.py index efb8992ab..352739a8e 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -157,11 +157,10 @@ PIN_LIMIT = 3 POST_RATE_LIMIT = '1/second;2/minute;10/hour;50/day' LOGGEDIN_ACTIVE_TIME = 15 * 60 -NOTIFICATIONS_ID = 1 -AUTOJANNY_ID = 2 -SNAPPY_ID = 3 -LONGPOSTBOT_ID = 4 -ZOZBOT_ID = 5 +AUTOJANNY_ID = 1 +SNAPPY_ID = 2 +LONGPOSTBOT_ID = 3 +ZOZBOT_ID = 4 BASEDBOT_ID = 0 SCHIZO_ID = 0 @@ -201,8 +200,7 @@ if SITE in {'rdrama.net', 'devrama.xyz'}: HOLE_COST = 50000 HOLE_INACTIVITY_DELETION = True - NOTIFICATIONS_ID = 1046 - AUTOJANNY_ID = 2360 + AUTOJANNY_ID = 1046 SNAPPY_ID = 261 LONGPOSTBOT_ID = 1832 ZOZBOT_ID = 1833 @@ -249,8 +247,7 @@ elif SITE == 'pcmemes.net': HOLE_COST = 2000 PIN_LIMIT = 6 POST_RATE_LIMIT = '1/second;4/minute;20/hour;100/day' - NOTIFICATIONS_ID = 1046 - AUTOJANNY_ID = 1050 + AUTOJANNY_ID = 1046 SNAPPY_ID = 261 LONGPOSTBOT_ID = 1832 ZOZBOT_ID = 1833 @@ -314,7 +311,7 @@ elif SITE == 'lgbdropthet.com': else: # localhost or testing environment implied pass -bots = {NOTIFICATIONS_ID, AUTOJANNY_ID, SNAPPY_ID, LONGPOSTBOT_ID, ZOZBOT_ID, BASEDBOT_ID} +bots = {AUTOJANNY_ID, SNAPPY_ID, LONGPOSTBOT_ID, ZOZBOT_ID, BASEDBOT_ID} IMGUR_KEY = environ.get("IMGUR_KEY").strip() PUSHER_ID = environ.get("PUSHER_ID", "").strip() diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 20fae946b..fb0945d3f 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -66,7 +66,7 @@ def give_monthly_marseybux_task(): if u.admin_level or u.id == A_ID or (u.email and u.email.lower() in emails): procoins = procoins_li[u.patron] u.procoins += procoins - send_repeatable_notification(u.id, f"@Snappy has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).") + send_repeatable_notification(u.id, f"@AutoJanny has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).") else: u.patron = 0 ma = ModAction( diff --git a/files/helpers/get.py b/files/helpers/get.py index c4ba3fbf4..fbc44fb34 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -23,7 +23,7 @@ def get_id(username, v=None, graceful=False): return user[0] -def get_user(username, v=None, graceful=False): +def get_user(username, v=None, graceful=False, rendered=False): if not username: if not graceful: abort(404) diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 0051f63ff..aefa4417e 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -51,7 +51,7 @@ def timestamp(timestamp): @app.context_processor def inject_constants(): return {"environ":environ, "SITE":SITE, "SITE_NAME":SITE_NAME, "SITE_FULL":SITE_FULL, - "AUTOJANNY_ID":AUTOJANNY_ID, "NOTIFICATIONS_ID":NOTIFICATIONS_ID, "PUSHER_ID":PUSHER_ID, + "AUTOJANNY_ID":AUTOJANNY_ID, "PUSHER_ID":PUSHER_ID, "CC":CC, "CC_TITLE":CC_TITLE, "listdir":listdir, "MOOSE_ID":MOOSE_ID, "AEVANN_ID":AEVANN_ID, "PIZZASHILL_ID":PIZZASHILL_ID, "DEFAULT_COLOR":DEFAULT_COLOR, "COLORS":COLORS, "ADMIGGERS":ADMIGGERS, "datetime":datetime, "time":time, diff --git a/files/helpers/offsitementions.py b/files/helpers/offsitementions.py index d02fbe0c6..4eb295a62 100644 --- a/files/helpers/offsitementions.py +++ b/files/helpers/offsitementions.py @@ -72,13 +72,13 @@ def notify_mentions(send_to, mentions, mention_str='site mention'): f'https://old.reddit.com{permalink}?context=89

{text}' \ existing_comment = g.db.query(Comment.id).filter_by( - author_id=const.NOTIFICATIONS_ID, + author_id=const.AUTOJANNY_ID, parent_submission=None, body_html=notif_text).one_or_none() if existing_comment: continue new_comment = Comment( - author_id=const.NOTIFICATIONS_ID, + author_id=const.AUTOJANNY_ID, parent_submission=None, body_html=notif_text, distinguish_level=6) diff --git a/files/helpers/stats.py b/files/helpers/stats.py index f642e71ce..d8ba3490f 100644 --- a/files/helpers/stats.py +++ b/files/helpers/stats.py @@ -57,7 +57,7 @@ def chart(kind, site): Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1], Comment.is_banned == False, - Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count() + Comment.author_id != AUTOJANNY_ID).count() for i in range(len(day_cutoffs) - 1)][::-1] plt.rcParams['figure.figsize'] = (chart_width, 20) @@ -114,11 +114,11 @@ def stats(site=None): "removed posts (by admins)": g.db.query(Submission).filter_by(is_banned=True).count(), "deleted posts (by author)": g.db.query(Submission).filter(Submission.deleted_utc > 0).count(), "posts last 24h": g.db.query(Submission).filter(Submission.created_utc > day).count(), - "total comments": g.db.query(Comment).filter(Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(), + "total comments": g.db.query(Comment).filter(Comment.author_id != AUTOJANNY_ID).count(), "commenting users": g.db.query(Comment.author_id).distinct().count(), "removed comments (by admins)": g.db.query(Comment).filter_by(is_banned=True).count(), "deleted comments (by author)": g.db.query(Comment).filter(Comment.deleted_utc > 0).count(), - "comments last_24h": g.db.query(Comment).filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(), + "comments last_24h": g.db.query(Comment).filter(Comment.created_utc > day, Comment.author_id != AUTOJANNY_ID).count(), "post votes": g.db.query(Vote).count(), "post voting users": g.db.query(Vote.user_id).distinct().count(), "comment votes": g.db.query(CommentVote).count(), diff --git a/files/routes/comments.py b/files/routes/comments.py index 4b6885a38..4c3e34f57 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -430,7 +430,7 @@ def api_comment(v): - c_jannied = Comment(author_id=NOTIFICATIONS_ID, + c_jannied = Comment(author_id=AUTOJANNY_ID, parent_submission=parent_submission, distinguish_level=6, parent_comment_id=c.id, @@ -747,7 +747,7 @@ def edit_comment(cid, v): - c_jannied = Comment(author_id=NOTIFICATIONS_ID, + c_jannied = Comment(author_id=AUTOJANNY_ID, parent_submission=c.parent_submission, distinguish_level=6, parent_comment_id=c.id, diff --git a/files/routes/front.py b/files/routes/front.py index 4445d716a..afb7317fe 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -335,7 +335,7 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", gt=0, lt=0, @auth_required def transfers(v): - comments = g.db.query(Comment).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.parent_submission == None, Comment.body_html.like("% has transferred %")).order_by(Comment.id.desc()) + comments = g.db.query(Comment).filter(Comment.author_id == AUTOJANNY_ID, Comment.parent_submission == None, Comment.body_html.like("% has transferred %")).order_by(Comment.id.desc()) if request.headers.get("Authorization"): return {"data": [x.json for x in comments.all()]} diff --git a/files/routes/login.py b/files/routes/login.py index 1e1485f81..66b891d83 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -11,7 +11,7 @@ import requests @auth_desired def login_get(v): - redir = request.values.get("redirect") + redir = request.values.get("redirect", "/") if redir: redir = redir.replace("/logged_out", "").strip() if not is_site_url(redir): redir = None @@ -306,7 +306,7 @@ def sign_up_post(v): ref_id = int(request.values.get("referred_by", 0)) users_count = g.db.query(User).count() - if users_count == 5: + if users_count == 4: admin_level=3 session["history"] = [] else: admin_level=0 diff --git a/files/routes/notifications.py b/files/routes/notifications.py index 5e22c7fa5..53d58ef5d 100644 --- a/files/routes/notifications.py +++ b/files/routes/notifications.py @@ -22,7 +22,6 @@ def unread(v): Notification.user_id == v.id, Comment.is_banned == False, Comment.deleted_utc == 0, - Comment.author_id != AUTOJANNY_ID, ).order_by(Notification.created_utc.desc()).all() for n, c in listing: @@ -89,9 +88,14 @@ def notifications_posts(v): except: page = 1 listing = [x[0] for x in g.db.query(Submission.id).filter( - Submission.author_id.in_(v.following_ids), + or_( + Submission.author_id.in_(self.followed_users), + Submission.sub.in_(self.followed_subs) + ), + Submission.created_utc > self.last_viewed_post_notifs, Submission.deleted_utc == 0, - Submission.is_banned == False + Submission.is_banned == False, + Submission.private == False ).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()] next_exists = (len(listing) > 25) @@ -126,7 +130,7 @@ def notifications_modactions(v): .join(Notification.comment) \ .filter(Notification.user_id == v.id, Comment.body_html.like(f'%

{NOTIF_MODACTION_PREFIX}%'), - Comment.parent_submission == None, Comment.author_id == NOTIFICATIONS_ID) \ + Comment.parent_submission == None, Comment.author_id == AUTOJANNY_ID) \ .order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all() listing = [] @@ -163,7 +167,7 @@ def notifications_reddit(v): if not v.can_view_offsitementions: abort(403) - notifications = g.db.query(Notification, Comment).join(Notification.comment).filter(Notification.user_id == v.id, Comment.body_html.like('%

New site mention: New site mention: /h/{post.sub}" - - cid = notif_comment(text, autojanny=True) - for follow in v.followers: - user = get_account(follow.user_id) - if post.club and not user.paid_dues: continue - add_notif(cid, user.id) - - if post.sub: - on_post_hole_entered(post, v) - cache.delete_memoized(frontlist) cache.delete_memoized(User.userpagelisting) @@ -468,7 +455,7 @@ def edit_post(pid, v): body_jannied_html = AGENDAPOSTER_MSG_HTML.format(id=v.id, username=v.username, type='post', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE) - c_jannied = Comment(author_id=NOTIFICATIONS_ID, + c_jannied = Comment(author_id=AUTOJANNY_ID, parent_submission=p.id, level=1, over_18=False, @@ -1016,19 +1003,6 @@ def submit_post(v, sub=None): for x in notify_users: add_notif(cid, x) - if (request.values.get('followers') or is_bot) and v.followers: - text = f"@{v.username} has made a new post: [{post.title}]({post.shortlink})" - if post.sub: text += f" in /h/{post.sub}" - - cid = notif_comment(text, autojanny=True) - for follow in v.followers: - user = get_account(follow.user_id) - if post.club and not user.paid_dues: continue - add_notif(cid, user.id) - - if post.sub: - on_post_hole_entered(post, v) - if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in f'{post.body}{post.title}'.lower(): post.is_banned = True post.ban_reason = "AutoJanny" @@ -1038,7 +1012,7 @@ def submit_post(v, sub=None): body_jannied_html = AGENDAPOSTER_MSG_HTML.format(id=v.id, username=v.username, type='post', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE) - c_jannied = Comment(author_id=NOTIFICATIONS_ID, + c_jannied = Comment(author_id=AUTOJANNY_ID, parent_submission=post.id, level=1, over_18=False, diff --git a/files/routes/reporting.py b/files/routes/reporting.py index eb295f2de..a8560a37a 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -64,8 +64,6 @@ def api_flag_post(pid, v): ) g.db.add(ma) - on_post_hole_entered(post, v) - return {"message": f"Post moved to /h/{post.sub}"} else: flag = Flag(post_id=post.id, user_id=v.id, reason=reason) diff --git a/files/routes/settings.py b/files/routes/settings.py index ab95150d6..4a22528ee 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -639,7 +639,7 @@ def settings_block_user(v): if v.has_blocked(user): return {"error": f"You have already blocked @{user.username}."}, 409 - if user.id == NOTIFICATIONS_ID: + if user.id == AUTOJANNY_ID: return {"error": "You can't block this user."}, 409 new_block = UserBlock(user_id=v.id, diff --git a/files/routes/users.py b/files/routes/users.py index 09e2f37bb..65cc0bee3 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -873,7 +873,7 @@ def u_username(username, v=None): if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}") if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','')) - u = get_user(username, v=v) + u = get_user(username, v=v, rendered=True) if v and username == v.username: is_following = False @@ -969,7 +969,7 @@ def u_username_comments(username, v=None): if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}") if v and request.path.startswith('/logged_out'): return redirect(request.full_path.replace('/logged_out','')) - user = get_user(username, v=v) + user = get_user(username, v=v, rendered=True) if v and username == v.username: is_following = False diff --git a/files/templates/comments.html b/files/templates/comments.html index 3d2053b78..76a848fa5 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -133,8 +133,8 @@ {% if c.post.sub %} in /h/{{c.post.sub}} {% endif %} - {% elif c.author_id==NOTIFICATIONS_ID or c.author_id==AUTOJANNY_ID %} - Notification + {% elif c.author_id==AUTOJANNY_ID %} + Notification {% else %} {% if c.sentto == 2 %} Sent to admins @@ -596,7 +596,7 @@ {% endif %} - {% if request.path == '/notifications' and c.level == 1 and c.sentto and not c.parent_submission and c.author_id not in (NOTIFICATIONS_ID, AUTOJANNY_ID) %} + {% if request.path == '/notifications' and c.level == 1 and c.sentto and not c.parent_submission and c.author_id != AUTOJANNY_ID %} Reply