add a "subscribed" tab in ur profile page to show posts u subscribed to

master
Aevann1 2022-07-03 04:43:49 +02:00
parent ab2d9b492d
commit 6c5b5a5314
6 changed files with 64 additions and 43 deletions

View File

@ -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

View File

@ -1208,6 +1208,30 @@ def saved_comments(v, username):
next_exists=next_exists,
standalone=True)
@app.get("/@<username>/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/<fp>")
@auth_required

View File

@ -101,6 +101,7 @@
<div class="dropdown dropdown-actions ml-2">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{% if sort=="hot" %}<i class="fas fa-fire mr-2 "></i>{% endif %}
{% if sort=="warm" %}<i class="fas fa-fire mr-2 "></i>{% endif %}
{% if sort=="bump" %}<i class="fas fa-arrow-up mr-2 "></i>{% endif %}
{% if sort=="top" %}<i class="fas fa-arrow-alt-circle-up mr-2 "></i>{% endif %}
{% if sort=="bottom" %}<i class="fas fa-arrow-alt-circle-down mr-2 "></i>{% endif %}
@ -112,6 +113,7 @@
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton2" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px;">
{% if sort != "hot" %}<a class="dropdown-item" href="?sort=hot&t={{t}}&ccmode={{ccmode}}"><i class="fas fa-fire mr-2 "></i>Hot</a>{% endif %}
{% if sort != "warm" %}<a class="dropdown-item" href="?sort=warm&t={{t}}&ccmode={{ccmode}}"><i class="fas fa-fire mr-2 "></i>Warm</a>{% endif %}
{% if sort != "bump" %}<a class="dropdown-item" href="?sort=bump&t={{t}}&ccmode={{ccmode}}"><i class="fas fa-arrow-up mr-2 "></i>Bump</a>{% endif %}
{% if sort != "top" %}<a class="dropdown-item" href="?sort=top&t={{t}}&ccmode={{ccmode}}"><i class="fas fa-arrow-alt-circle-up mr-2 "></i>Top</a>{% endif %}
{% if sort != "bottom" %}<a class="dropdown-item" href="?sort=bottom&t={{t}}&ccmode={{ccmode}}"><i class="fas fa-arrow-alt-circle-down mr-2 "></i>Bottom</a>{% endif %}

View File

@ -396,9 +396,9 @@
<i class="fas fa-square text-gray-500 opacity-25 fa-stack-2x"></i>
<i class="fas text-gray-500 fa-ghost fa-stack-1x text-lg"></i>
</span>
<h2 class="h5">You haven't {% if "saved" in request.full_path %}saved{% else %}made{% endif %} a post yet</h2>
<p class="text-muted mb-md-5">Your {% if "saved" in request.full_path %}saved posts{% else %}posting history{% endif %} will show here.</p>
{% if "saved" not in request.full_path %}<a href="{% if sub %}/h/{{sub.name}}{% endif %}/submit" class="btn btn-primary">Create a post</a>{% endif %}
<h2 class="h5">You haven't {% if "/saved/" in request.path %}saved{% elif "/subscribed/" in request.path %}subscribed to{% else %}made{% endif %} a post yet</h2>
<p class="text-muted mb-md-5">Your {% if "/saved/" in request.path %}saved posts{% elif "/subscribed/" in request.path %}subscribed posts{% else %}posting history{% endif %} will show here.</p>
{% if "/saved/" not in request.path and "/subscribed/" not in request.path %}<a href="/submit" class="btn btn-primary">Create a post</a>{% endif %}
</div>
</div>
</div>

View File

@ -670,18 +670,21 @@
</li>
{% if u.id == v.id %}
<li class="nav-item">
<a class="nav-link {% if 'saved' in request.path %}active{% endif %}" style="font-size: .9rem !important; padding: .75rem .4rem !important" href="/@{{u.username}}/saved/posts">Saved Posts <span class="count">({{u.saved_count}})</span></a>
<a class="nav-link {% if '/saved/' in request.path %}active{% endif %}" style="font-size: .9rem !important; padding: .75rem .4rem !important" href="/@{{u.username}}/saved/posts">Saved Posts <span class="count">({{u.saved_count}})</span></a>
</li>
<li class="nav-item">
<a class="nav-link" style="font-size: .9rem !important; padding: .75rem .4rem !important" href="/@{{u.username}}/saved/comments">Saved Comments <span class="count">({{u.saved_comment_count}})</span></a>
</li>
<li class="nav-item">
<a class="nav-link {% if '/subscribed/' in request.path %}active{% endif %}" style="font-size: .9rem !important; padding: .75rem .4rem !important" href="/@{{u.username}}/subscribed/posts">Subscribed <span class="count">({{u.subscribed_count}})</span></a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
{% if not "saved" in request.full_path %}
{% if "/saved/" not in request.path and '/subscribed/' not in request.path %}
<div class="d-flex justify-content-between align-items-center" style="padding-top:10px">
<div class="d-flex align-items-center">

View File

@ -19,13 +19,16 @@
<li class="nav-item">
<a class="nav-link {% if 'saved' in request.path %}active{% endif %}" style="font-size: .9rem !important; padding: .75rem .4rem !important" href="/@{{u.username}}/saved/comments">Saved Comments <span class="count">({{u.saved_comment_count}})</span></a>
</li>
<li class="nav-item">
<a class="nav-link" style="font-size: .9rem !important; padding: .75rem .4rem !important" href="/@{{u.username}}/saved/posts">Subscribed <span class="count">({{u.subscribed_count}})</span></a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
{% if not "saved" in request.full_path %}
{% if "/saved/" not in request.path and "/subscribed/" not in request.path %}
<div class="d-flex justify-content-between align-items-center" style="padding-top:10px">
<div class="d-flex align-items-center">