From 1f28d5b81d658e5fa047e972e0c706a75956da6a Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 16 Nov 2021 01:13:29 +0200 Subject: [PATCH] fdsfds --- files/classes/comment.py | 6 +-- files/routes/admin.py | 15 +++++-- files/routes/comments.py | 23 +++++----- files/routes/users.py | 42 ++++++++++++++++++- files/templates/comments.html | 14 +++---- files/templates/userpage.html | 4 +- .../templates/{upvoters.html => voters.html} | 2 +- 7 files changed, 77 insertions(+), 29 deletions(-) rename files/templates/{upvoters.html => voters.html} (90%) diff --git a/files/classes/comment.py b/files/classes/comment.py index bc8a1bb6f..27f7dd826 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -212,10 +212,10 @@ class Comment(Base): @property @lazy def permalink(self): - if self.post and self.post.club: return f"/comment/{self.id}/" + if self.post and self.post.club: return f"/comment/{self.id}?context=9#context" - if self.post: return f"{self.post.permalink}/{self.id}/" - else: return f"/comment/{self.id}/" + if self.post: return f"{self.post.permalink}/{self.id}?context=9#context" + else: return f"/comment/{self.id}?context=9#context" @property @lazy diff --git a/files/routes/admin.py b/files/routes/admin.py index 720f2b565..4624da32a 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -993,9 +993,18 @@ def api_sticky_post(post_id, v): cache.delete_memoized(frontlist) - g.db.commit() - if post.stickied: return {"message": "Post pinned!"} - else: return {"message": "Post unpinned!"} + if post.stickied: + message = f"@{v.username} has pinned your [post](/post/{post_id})!" + existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message).first() + if not existing: send_notification(post.author_id, message) + g.db.commit() + return {"message": "Post pinned!"} + else: + message = f"@{v.username} has unpinned your [post](/post/{post_id})!" + existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message).first() + if not existing: send_notification(post.author_id, message) + g.db.commit() + return {"message": "Post unpinned!"} @app.post("/ban_comment/") @limiter.limit("1/second") diff --git a/files/routes/comments.py b/files/routes/comments.py index 812245bf9..df7ca3eee 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -861,8 +861,18 @@ def toggle_pin_comment(cid, v): g.db.commit() - if comment.is_pinned: return {"message": "Comment pinned!"} - else: return {"message": "Comment unpinned!"} + if comment.is_pinned: + message = f"@{v.username} has pinned your [comment]({comment.permalink})!" + existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message).first() + if not existing: send_notification(comment.author_id, message) + g.db.commit() + return {"message": "Comment pinned!"} + else: + message = f"@{v.username} has unpinned your [comment]({comment.permalink})!" + existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message).first() + if not existing: send_notification(comment.author_id, message) + g.db.commit() + return {"message": "Comment unpinned!"} @app.post("/save_comment/") @@ -879,10 +889,6 @@ def save_comment(cid, v): new_save=SaveRelationship(user_id=v.id, comment_id=comment.id, type=2) g.db.add(new_save) - # message = f"@{v.username} has saved your [comment](/comment/{cid})!" - # existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message).first() - # if not existing: send_notification(comment.author_id, message) - try: g.db.commit() except: g.db.rollback() @@ -900,11 +906,6 @@ def unsave_comment(cid, v): if save: g.db.delete(save) - - # message = f"@{v.username} has unsaved your [comment](/comment/{cid})!" - # existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message).first() - # if not existing: send_notification(comment.author_id, message) - g.db.commit() return {"message": "Comment unsaved!"} diff --git a/files/routes/users.py b/files/routes/users.py index e46e0d53f..451dd6716 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -34,7 +34,7 @@ def upvoters(v, username): users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] - return render_template("upvoters.html", v=v, users=users, username=username, name='Up', name2='simps') + return render_template("voters.html", v=v, users=users, username=username, name='Up', name2='@{v.username} biggest simps') @app.get("/@/downvoters") @auth_desired @@ -53,7 +53,45 @@ def downvoters(v, username): users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] - return render_template("upvoters.html", v=v, users=users, username=username, name='Down', name2='haters') + return render_template("voters.html", v=v, users=users, username=username, name='Down', name2='@{v.username} biggest haters') + +@app.get("/@/upvoting") +@auth_desired +def upvoting(v, username): + id = get_user(username).id + + votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==1, Vote.user_id==id).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).limit(25).all() + + votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==1, CommentVote.user_id==id).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).limit(25).all() + + votes = Counter(dict(votes)) + Counter(dict(votes2)) + + users = g.db.query(User).filter(User.id.in_(votes.keys())).all() + users2 = [] + for user in users: users2.append((user, votes[user.id])) + + users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] + + return render_template("voters.html", v=v, users=users, username=username, name='Up', name2=f'Who @{v.username} simps for') + +@app.get("/@/downvoting") +@auth_desired +def downvoting(v, username): + id = get_user(username).id + + votes = g.db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1, Vote.user_id==id).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).limit(25).all() + + votes2 = g.db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1, CommentVote.user_id==id).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).limit(25).all() + + votes = Counter(dict(votes)) + Counter(dict(votes2)) + + users = g.db.query(User).filter(User.id.in_(votes.keys())).all() + users2 = [] + for user in users: users2.append((user, votes[user.id])) + + users = sorted(users2, key=lambda x: x[1], reverse=True)[:25] + + return render_template("voters.html", v=v, users=users, username=username, name='Down', name2=f'Who @{v.username} hates') @app.post("/pay_rent") @limiter.limit("1/second") diff --git a/files/templates/comments.html b/files/templates/comments.html index b8dedd273..860465a15 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -215,11 +215,11 @@ {% endfor %} {% elif replies %} {% endif %} {% endif %} @@ -443,8 +443,8 @@ Reply {% endif %} - Context - Copy link + Context + Copy link {% if v %} Report {% endif %} @@ -575,7 +575,7 @@ {% endfor %} {% elif replies %}
@@ -608,9 +608,9 @@ Unsave {% endif %} - Copy link + Copy link - Context + Context Report diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 97a333212..45403a85c 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -159,7 +159,7 @@ {% else %}

 				{% endif %}
 
-				
+				
 
 				
{{u.coins}} @@ -441,7 +441,7 @@

 				{% endif %}
 
-				
+				
 				
 				
{{u.coins}} diff --git a/files/templates/upvoters.html b/files/templates/voters.html similarity index 90% rename from files/templates/upvoters.html rename to files/templates/voters.html index 309fa9ed6..9dd4d049b 100644 --- a/files/templates/upvoters.html +++ b/files/templates/voters.html @@ -4,7 +4,7 @@ -
@{{username}}'s biggest {{name2}}
+
{{name2}}