fdfd
parent
332e79a107
commit
7118a4a0d6
|
@ -213,27 +213,10 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def voted(self, v):
|
||||||
@property
|
x = g.db.query(CommentVote).filter_by(comment_id=self.id, user_id=g.v.id).first()
|
||||||
def voted(self):
|
if x: return x.vote_type
|
||||||
|
else: return 0
|
||||||
x = self.__dict__.get("_voted")
|
|
||||||
if x != None:
|
|
||||||
return x
|
|
||||||
|
|
||||||
if g.v:
|
|
||||||
x = g.db.query(CommentVote).filter_by(
|
|
||||||
comment_id=self.id,
|
|
||||||
user_id=g.v.id
|
|
||||||
).first()
|
|
||||||
|
|
||||||
if x:
|
|
||||||
x = x.vote_type
|
|
||||||
else:
|
|
||||||
x = 0
|
|
||||||
else:
|
|
||||||
x = 0
|
|
||||||
return x
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_blocking(self):
|
def is_blocking(self):
|
||||||
|
|
|
@ -179,42 +179,20 @@ def get_posts(pids, v=None):
|
||||||
|
|
||||||
def get_comment(cid, v=None, graceful=False, **kwargs):
|
def get_comment(cid, v=None, graceful=False, **kwargs):
|
||||||
|
|
||||||
if isinstance(cid, str):
|
if isinstance(cid, str): i = base36decode(cid)
|
||||||
i = base36decode(cid)
|
else: i = cid
|
||||||
else:
|
|
||||||
i = cid
|
|
||||||
|
|
||||||
if v:
|
if v:
|
||||||
blocking = v.blocking.subquery()
|
blocking = v.blocking.subquery()
|
||||||
blocked = v.blocked.subquery()
|
blocked = v.blocked.subquery()
|
||||||
vt = g.db.query(CommentVote).filter(
|
|
||||||
CommentVote.user_id == v.id,
|
|
||||||
CommentVote.comment_id == i).subquery()
|
|
||||||
|
|
||||||
items = g.db.query(
|
items = g.db.query(Comment)
|
||||||
Comment,
|
|
||||||
vt.c.vote_type,
|
|
||||||
)
|
|
||||||
|
|
||||||
if v.admin_level >=4:
|
if v.admin_level >=4: items=items.options(joinedload(Comment.oauth_app))
|
||||||
items=items.options(joinedload(Comment.oauth_app))
|
|
||||||
|
|
||||||
items=items.filter(
|
x=items.filter(Comment.id == i).first()
|
||||||
Comment.id == i
|
|
||||||
).join(
|
|
||||||
vt,
|
|
||||||
vt.c.comment_id == Comment.id,
|
|
||||||
isouter=True
|
|
||||||
).join(
|
|
||||||
Comment.post,
|
|
||||||
isouter=True
|
|
||||||
).first()
|
|
||||||
|
|
||||||
if not items and not graceful:
|
if not x and not graceful: abort(404)
|
||||||
abort(404)
|
|
||||||
|
|
||||||
x = items[0]
|
|
||||||
x._voted = items[1] or 0
|
|
||||||
|
|
||||||
block = g.db.query(UserBlock).filter(
|
block = g.db.query(UserBlock).filter(
|
||||||
or_(
|
or_(
|
||||||
|
@ -232,75 +210,23 @@ def get_comment(cid, v=None, graceful=False, **kwargs):
|
||||||
x._is_blocked = block and block.target_id == v.id
|
x._is_blocked = block and block.target_id == v.id
|
||||||
|
|
||||||
else:
|
else:
|
||||||
x = g.db.query(
|
x = g.db.query(Comment).filter(Comment.id == i).first()
|
||||||
Comment,
|
if not x and not graceful:abort(404)
|
||||||
).filter(Comment.id == i).first()
|
|
||||||
|
|
||||||
if not x and not graceful:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
def get_comments(cids, v=None, load_parent=False, **kwargs):
|
def get_comments(cids, v=None, **kwargs):
|
||||||
|
|
||||||
if not cids:
|
if not cids: return []
|
||||||
return []
|
|
||||||
|
|
||||||
cids=tuple(cids)
|
cids=tuple(cids)
|
||||||
|
|
||||||
if v:
|
output = g.db.query(Comment)
|
||||||
vt = g.db.query(CommentVote).filter(
|
|
||||||
CommentVote.comment_id.in_(cids),
|
|
||||||
CommentVote.user_id==v.id
|
|
||||||
).subquery()
|
|
||||||
|
|
||||||
query = g.db.query(
|
if v and v.admin_level >=4: output=output.options(joinedload(Comment.oauth_app))
|
||||||
Comment,
|
|
||||||
aliased(CommentVote, alias=vt),
|
|
||||||
)
|
|
||||||
|
|
||||||
if v.admin_level >=4:
|
output = output.options(joinedload(Comment.parent_comment)).filter(Comment.id.in_(cids)).all()
|
||||||
query=query.options(joinedload(Comment.oauth_app))
|
|
||||||
|
|
||||||
if load_parent:
|
|
||||||
query = query.options(
|
|
||||||
joinedload(
|
|
||||||
Comment.parent_comment
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
query = query.join(
|
|
||||||
vt,
|
|
||||||
vt.c.comment_id == Comment.id,
|
|
||||||
isouter=True
|
|
||||||
).join(
|
|
||||||
Comment.post,
|
|
||||||
isouter=True
|
|
||||||
).filter(
|
|
||||||
Comment.id.in_(cids)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
output = [x[0] for x in query]
|
|
||||||
for i in range(len(output)):
|
|
||||||
if query[i][1] != None:
|
|
||||||
try: output[i]._voted = query[i][1].vote_type
|
|
||||||
except:
|
|
||||||
print(query[i][1])
|
|
||||||
output[i]._voted = 0
|
|
||||||
else: output[i]._voted = 0
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
|
||||||
query = g.db.query(
|
|
||||||
Comment,
|
|
||||||
).filter(
|
|
||||||
Comment.id.in_(cids)
|
|
||||||
).all()
|
|
||||||
|
|
||||||
output=[x for x in query]
|
|
||||||
|
|
||||||
output = sorted(output, key=lambda x: cids.index(x.id))
|
output = sorted(output, key=lambda x: cids.index(x.id))
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,12 @@ def notifications(v):
|
||||||
cids = v.notification_subscriptions(page=page, all_=all_)
|
cids = v.notification_subscriptions(page=page, all_=all_)
|
||||||
next_exists = (len(cids) == 26)
|
next_exists = (len(cids) == 26)
|
||||||
cids = cids[:25]
|
cids = cids[:25]
|
||||||
comments = get_comments(cids, v=v, sort="new", load_parent=True)
|
comments = get_comments(cids, v=v, sort="new")
|
||||||
else:
|
else:
|
||||||
cids = v.notification_commentlisting(page=page, all_=all_)
|
cids = v.notification_commentlisting(page=page, all_=all_)
|
||||||
next_exists = (len(cids) == 26)
|
next_exists = (len(cids) == 26)
|
||||||
cids = cids[:25]
|
cids = cids[:25]
|
||||||
comments = get_comments(cids, v=v, sort="new", load_parent=True)
|
comments = get_comments(cids, v=v, sort="new")
|
||||||
|
|
||||||
listing = []
|
listing = []
|
||||||
for c in comments:
|
for c in comments:
|
||||||
|
|
|
@ -69,12 +69,10 @@
|
||||||
{% set score=c.score %}
|
{% set score=c.score %}
|
||||||
|
|
||||||
{% if v %}
|
{% if v %}
|
||||||
{% set voted=c.voted %}
|
{% set voted=c.voted(v) %}
|
||||||
{% set adjust = voted %}
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set voted=-2 %}
|
{% set voted=-2 %}
|
||||||
{% set adjust=0 %}
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue