fix shadowbannedcel post count and comment count

pull/136/head
Aevann 2023-02-28 19:54:01 +02:00
parent fe894ff917
commit ac5b58cdb6
3 changed files with 22 additions and 8 deletions

View File

@ -8,6 +8,7 @@ from sqlalchemy.orm import aliased, deferred, Query
from sqlalchemy.sql import case, func, literal
from sqlalchemy.sql.expression import not_, and_, or_
from sqlalchemy.sql.sqltypes import *
from flask import g
from files.classes import Base
from files.classes.casino_game import CasinoGame
@ -771,6 +772,19 @@ class User(Base):
return self.profileurl
return f"{SITE_FULL}/i/default-profile-pic.webp?v=1008"
@lazy
def real_post_count(self, v):
if not self.shadowbanned: return self.post_count
if v and (v.id == self.id or v.can_see_shadowbanned): return self.post_count
return 0
@lazy
def real_comment_count(self, v):
if not self.shadowbanned: return self.comment_count
if v and (v.id == self.id or v.can_see_shadowbanned): return self.comment_count
return 0
@lazy
def json_popover(self, v):
data = {'username': self.username,
@ -781,8 +795,8 @@ class User(Base):
'bannerurl': self.banner_url,
'bio_html': self.bio_html_eager,
'coins': self.coins,
'post_count': 0 if self.shadowbanned and not (v and v.can_see_shadowbanned) else self.post_count,
'comment_count': 0 if self.shadowbanned and not (v and v.can_see_shadowbanned) else self.comment_count,
'post_count': self.real_post_count(v),
'comment_count': self.real_comment_count(v),
'badges': [x.path for x in self.badges],
'created_date': self.created_date,
}
@ -818,8 +832,8 @@ class User(Base):
'flair': self.customtitle,
'badges': [x.json for x in self.badges],
'coins': self.coins,
'post_count': self.post_count,
'comment_count': self.comment_count
'post_count': self.real_post_count(g.v),
'comment_count': self.real_comment_count(g.v)
}

View File

@ -7,10 +7,10 @@
<a class="nav-link{% if path == '' %} active{% endif %}" href="/@{{u.username}}#content">Wall</a>
</li>
<li class="nav-item">
<a class="nav-link{% if path == '/posts' %} active{% endif %}" href="/@{{u.username}}/posts#content">Posts <span class="count">({{u.post_count}})</span></a>
<a class="nav-link{% if path == '/posts' %} active{% endif %}" href="/@{{u.username}}/posts#content">Posts <span class="count">({{u.real_post_count(v)}})</span></a>
</li>
<li class="nav-item">
<a class="nav-link{% if path == '/comments' %} active{% endif %}" href="/@{{u.username}}/comments#content">Comments <span class="count">({{u.comment_count}})</span></a>
<a class="nav-link{% if path == '/comments' %} active{% endif %}" href="/@{{u.username}}/comments#content">Comments <span class="count">({{u.real_comment_count(v)}})</span></a>
</li>
{% if u.id == v.id %}
<li class="nav-item">

View File

@ -45,9 +45,9 @@
{{u.stored_subscriber_count}} Followers -
{%- endif -%}
{%- if not u.is_private -%}
{{0 if u.shadowbanned else u.post_count}}
{{0 if u.shadowbanned else u.real_post_count(v)}}
Posts -
{{0 if u.shadowbanned else u.comment_count}}
{{0 if u.shadowbanned else u.real_comment_count(v)}}
Comments
{%- endif -%}
{% if u.bio and (not u.shadowbanned or (v and (v.id == u.id or v.can_see_shadowbanned))) %}