From c22f4e4e9537e1c299fdd13569a9aa1653d523e0 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 1 Mar 2022 02:06:50 +0200 Subject: [PATCH] created --- files/classes/comment.py | 3 ++- files/helpers/alerts.py | 2 +- files/routes/front.py | 4 +-- files/routes/posts.py | 46 +++++++++++++++++++---------------- files/routes/settings.py | 16 ++++++------ files/templates/comments.html | 2 ++ 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 939932a68..cb594b312 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -58,7 +58,8 @@ class Comment(Base): reports = relationship("CommentFlag", viewonly=True) def __init__(self, *args, **kwargs): - if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + if "created_utc" not in kwargs: + kwargs["created_utc"] = int(time.time()) super().__init__(*args, **kwargs) def __repr__(self): diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index c3ff52007..6d8f4cb65 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -48,7 +48,7 @@ def notif_comment(text, autojanny=False): text_html = sanitize(text, alert=True) - existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body_html=text_html, created_utc=0).first() + existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body_html=text_html, created_utc=0).one_or_none() if existing: return existing[0] else: return create_comment(text_html, autojanny) diff --git a/files/routes/front.py b/files/routes/front.py index 41c20eac7..7dfe4353a 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -61,7 +61,7 @@ def notifications(v): x.read = True c.unread = True g.db.add(x) - if not c.created_utc: c.created_utc = x.created_utc + if not c.created_utc: c.notif_utc = x.notif_utc listing.append(c) g.db.commit() @@ -85,7 +85,7 @@ def notifications(v): try: c = comments[i] except: continue if not x.read: c.unread = True - if not c.created_utc: c.created_utc = x.created_utc + if not c.created_utc: c.notif_utc = x.notif_utc x.read = True g.db.add(x) i += 1 diff --git a/files/routes/posts.py b/files/routes/posts.py index 8418ef98a..71fbef174 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -97,21 +97,23 @@ def publish(pid, v): if not post.ghost: notify_users = NOTIFY_USERS(f'{post.title} {post.body}', v) - text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})" - if post.sub: text += f" in /s/{post.sub}" + if notify_users: + text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})" + if post.sub: text += f" in /s/{post.sub}" - cid = notif_comment(text) - for x in notify_users: - add_notif(cid, x) + cid = notif_comment(text) + for x in notify_users: + add_notif(cid, x) - text = f"@{v.username} has made a new post: [{post.title}]({post.shortlink})" - if post.sub: text += f" in /s/{post.sub}" + if v.followers: + text = f"@{v.username} has made a new post: [{post.title}]({post.shortlink})" + if post.sub: text += f" in /s/{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) + 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) cache.delete_memoized(frontlist) @@ -574,9 +576,10 @@ def edit_post(pid, v): if not p.private and not p.ghost: notify_users = NOTIFY_USERS(f'{title} {body}', v) - cid = notif_comment(f"@{v.username} has mentioned you: [{p.title}]({p.shortlink})") - for x in notify_users: - add_notif(cid, x) + if notify_users: + cid = notif_comment(f"@{v.username} has mentioned you: [{p.title}]({p.shortlink})") + for x in notify_users: + add_notif(cid, x) @@ -1172,14 +1175,15 @@ def submit_post(v, sub=None): notify_users = NOTIFY_USERS(f'{title} {body}', v) - text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})" - if post.sub: text += f" in /s/{post.sub}" + if notify_users: + text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})" + if post.sub: text += f" in /s/{post.sub}" - cid = notif_comment(text) - for x in notify_users: - add_notif(cid, x) + cid = notif_comment(text) + for x in notify_users: + add_notif(cid, x) - if request.values.get('followers'): + if request.values.get('followers') and v.followers: text = f"@{v.username} has made a new post: [{post.title}]({post.shortlink})" if post.sub: text += f" in /s/{post.sub}" diff --git a/files/routes/settings.py b/files/routes/settings.py index a18fe2cbd..3b7a1d7c0 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -193,10 +193,10 @@ def settings_profile_post(v): notify_users = NOTIFY_USERS(friends, v) - cid = notif_comment(f"@{v.username} has added you to their friends list!") - - for x in notify_users: - add_notif(cid, x) + if notify_users: + cid = notif_comment(f"@{v.username} has added you to their friends list!") + for x in notify_users: + add_notif(cid, x) v.friends = friends[:500] v.friends_html=friends_html @@ -229,10 +229,10 @@ def settings_profile_post(v): notify_users = NOTIFY_USERS(enemies, v) - cid = notif_comment(f"@{v.username} has added you to their enemies list!") - - for x in notify_users: - add_notif(cid, x) + if notify_users: + cid = notif_comment(f"@{v.username} has added you to their enemies list!") + for x in notify_users: + add_notif(cid, x) v.enemies = enemies[:500] v.enemies_html=enemies_html diff --git a/files/templates/comments.html b/files/templates/comments.html index ac38c2f25..61e7be4e3 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -235,6 +235,8 @@ {% if c.created_utc %}  {{c.age_string}} + {% elif c.notif_utc %} +  {{c.age_string}} {% endif %} {% if c.edited_utc %}