diff --git a/files/classes/saves.py b/files/classes/saves.py index 72803b5be..614339556 100644 --- a/files/classes/saves.py +++ b/files/classes/saves.py @@ -10,6 +10,8 @@ class SaveRelationship(Base): user_id=Column(Integer, ForeignKey("users.id"), primary_key=True) submission_id=Column(Integer, ForeignKey("submissions.id"), primary_key=True) + post = relationship("Submission", uselist=False) + def __repr__(self): return f"" @@ -21,5 +23,7 @@ class CommentSaveRelationship(Base): user_id=Column(Integer, ForeignKey("users.id"), primary_key=True) comment_id=Column(Integer, ForeignKey("comments.id"), primary_key=True) + comment = relationship("Comment", uselist=False) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/subscriptions.py b/files/classes/subscriptions.py index ff4ee040a..debdad882 100644 --- a/files/classes/subscriptions.py +++ b/files/classes/subscriptions.py @@ -8,6 +8,7 @@ class Subscription(Base): submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True) user = relationship("User", uselist=False) + post = relationship("Submission", uselist=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/files/classes/user.py b/files/classes/user.py index a574a4dfa..0da1fc304 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -693,19 +693,22 @@ class User(Base): def userblocks(self): return [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=self.id).all()] + @property @lazy - def saved_idlist(self, page=1): - posts = g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).offset(25 * (page - 1)).all() + def saved_idlist(self): + posts = g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).all() return [x[0] for x in posts] + @property @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() + def saved_comment_idlist(self): + comments = g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).all() return [x[0] for x in comments] + @property @lazy - def subscribed_idlist(self, page=1): - posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id) + def subscribed_idlist(self): + posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all() return [x[0] for x in posts] diff --git a/files/routes/users.py b/files/routes/users.py index 2911a53cd..b946144d4 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -1173,14 +1173,13 @@ def saved_posts(v, username): page=int(request.values.get("page",1)) - ids=v.saved_idlist(page=page) + ids = [x[0] for x in g.db.query(SaveRelationship.submission_id).join(SaveRelationship.post).filter(SaveRelationship.user_id == v.id).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()] next_exists=len(ids)>25 ids=ids[:25] listing = get_posts(ids, v=v) - listing.reverse() if request.headers.get("Authorization"): return {"data": [x.json for x in listing]} return render_template("userpage.html", @@ -1198,14 +1197,13 @@ def saved_comments(v, username): page=int(request.values.get("page",1)) - ids=v.saved_comment_idlist(page=page) + ids = [x[0] for x in g.db.query(CommentSaveRelationship.comment_id).join(CommentSaveRelationship.comment).filter(CommentSaveRelationship.user_id == v.id).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()] next_exists=len(ids) > 25 ids=ids[:25] listing = get_comments(ids, v=v) - listing.reverse() if request.headers.get("Authorization"): return {"data": [x.json for x in listing]} return render_template("userpage_comments.html", @@ -1222,14 +1220,13 @@ def subscribed_posts(v, username): page=int(request.values.get("page",1)) - ids=v.subscribed_idlist(page=page) + ids = [x[0] for x in g.db.query(Subscription.submission_id).join(Subscription.post).filter(Subscription.user_id == v.id).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all()] next_exists=len(ids)>25 ids=ids[:25] listing = get_posts(ids, v=v) - listing.reverse() if request.headers.get("Authorization"): return {"data": [x.json for x in listing]} return render_template("userpage.html", diff --git a/files/templates/comments.html b/files/templates/comments.html index fefd766b7..76f769341 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -122,7 +122,7 @@ Comment {{'Replies' if (replies | length)>1 else 'Reply'}}: {{c.post.realtitle(v) | safe}} {% elif c.post.author_id==v.id and c.level == 1 and is_notification_page%} Post Reply: {{c.post.realtitle(v) | safe}} - {% elif is_notification_page and c.parent_submission in v.subscribed_idlist() %} + {% elif is_notification_page and c.parent_submission in v.subscribed_idlist %} Subscribed Thread: {{c.post.realtitle(v) | safe}} {% elif is_notification_page %} Username Mention: {{c.post.realtitle(v) | safe}} @@ -450,9 +450,9 @@ - + - + {% endif %} {% if c.parent_submission %} @@ -655,9 +655,9 @@ Give Award - Save + Save - Unsave + Unsave {% if c.author_id == v.id %} Edit diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index 058343c70..0065bf95f 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -15,13 +15,13 @@ Copy link {% if v %} - Subscribe - Unsubscribe + Subscribe + Unsubscribe {% endif %} {% if v %} - Save - Unsave + Save + Unsave Report {% endif %} diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index 8b7d47e10..1dcb257f8 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -14,11 +14,11 @@ - - + + - - + + {% if p.sub and v.mods(p.sub) %}