From 6c5b5a53142b74472f539506fb613fc8af0fdaba Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 3 Jul 2022 04:43:49 +0200 Subject: [PATCH] add a "subscribed" tab in ur profile page to show posts u subscribed to --- files/classes/user.py | 41 +++++++++---------------- files/routes/users.py | 24 +++++++++++++++ files/templates/home.html | 2 ++ files/templates/submission_listing.html | 6 ++-- files/templates/userpage.html | 17 +++++----- files/templates/userpage_comments.html | 17 +++++----- 6 files changed, 64 insertions(+), 43 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index eb6882d86..9e05f8d2c 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -697,10 +697,6 @@ class User(Base): return "never" return str(time.strftime("%Y-%m-%d %H:%M:%SZ", time.gmtime(self.last_active))) - @lazy - def subscribed_idlist(self, page=1): - posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all() - return [x[0] for x in posts] @property @lazy @@ -709,41 +705,34 @@ class User(Base): @lazy def saved_idlist(self, page=1): - - saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).all()] - - if not saved: return [] - - posts = g.db.query(Submission.id).filter(Submission.id.in_(saved), Submission.is_banned == False, Submission.deleted_utc == 0) - - if self.admin_level < 2: - posts = posts.filter(Submission.author_id.notin_(self.userblocks)) - - return [x[0] for x in posts.order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).all()] + posts = g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).offset(25 * (page - 1)).all() + return [x[0] for x in posts] @lazy def saved_comment_idlist(self, page=1): + comments = g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).offset(25 * (page - 1)).all() + return [x[0] for x in comments] - saved = [x[0] for x in g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).all()] + @lazy + def subscribed_idlist(self, page=1): + posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id) + return [x[0] for x in posts] - if not saved: return [] - - comments = g.db.query(Comment.id).filter(Comment.id.in_(saved), Comment.is_banned == False, Comment.deleted_utc == 0) - - if self.admin_level < 2: - comments = comments.filter(Comment.author_id.notin_(self.userblocks)) - - return [x[0] for x in comments.order_by(Comment.id.desc()).offset(25 * (page - 1)).all()] @property @lazy def saved_count(self): - return len(self.saved_idlist()) + return g.db.query(SaveRelationship).filter_by(user_id=self.id).count() @property @lazy def saved_comment_count(self): - return len(self.saved_comment_idlist()) + return g.db.query(CommentSaveRelationship).filter_by(user_id=self.id).count() + + @property + @lazy + def subscribed_count(self): + return g.db.query(Subscription).filter_by(user_id=self.id).count() @property @lazy diff --git a/files/routes/users.py b/files/routes/users.py index 3209d45c5..44a8523bf 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1208,6 +1208,30 @@ def saved_comments(v, username): next_exists=next_exists, standalone=True) +@app.get("/@/subscribed/posts") +@auth_required +def subscribed_posts(v, username): + + page=int(request.values.get("page",1)) + + ids=v.subscribed_idlist(page=page) + + next_exists=len(ids)>25 + + ids=ids[:25] + + listing = get_posts(ids, v=v) + + if request.headers.get("Authorization"): return {"data": [x.json for x in listing]} + return render_template("userpage.html", + u=v, + v=v, + listing=listing, + page=page, + next_exists=next_exists, + ) + + @app.post("/fp/") @auth_required diff --git a/files/templates/home.html b/files/templates/home.html index c132d52a8..a35c7e8ee 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -101,6 +101,7 @@ diff --git a/files/templates/userpage.html b/files/templates/userpage.html index e14fcec41..77ac5b1c2 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -669,19 +669,22 @@ Comments ({{u.comment_count}}) {% if u.id == v.id %} - - + + + {% endif %} -{% if not "saved" in request.full_path %} +{% if "/saved/" not in request.path and '/subscribed/' not in request.path %}
diff --git a/files/templates/userpage_comments.html b/files/templates/userpage_comments.html index 521299ee3..5d228e28b 100644 --- a/files/templates/userpage_comments.html +++ b/files/templates/userpage_comments.html @@ -13,19 +13,22 @@ Comments ({{u.comment_count}}) {% if u.id == v.id %} - - + + + {% endif %}
-{% if not "saved" in request.full_path %} +{% if "/saved/" not in request.path and "/subscribed/" not in request.path %}