评论自动关注

This commit is contained in:
2021-12-15 22:00:49 +08:00
parent 2388e1a45e
commit 28edfd85e5

18
hole.py
View File

@@ -310,6 +310,20 @@ def do_comment():
) )
post.comments.append(c) post.comments.append(c)
post.comment_timestamp = c.timestamp post.comment_timestamp = c.timestamp
at = Attention.query.filter_by(
name_hash=hash_name(u.name), pid=pid
).first()
if not at:
at = Attention(name_hash=hash_name(u.name), pid=pid, disabled=False)
db.session.add(at)
post.likenum += 1
else:
if at.disabled:
post.likenum += 1
at.disabled = False
db.session.commit() db.session.commit()
return { return {
@@ -336,8 +350,8 @@ def attention():
abort(404) abort(404)
at = Attention.query.filter_by( at = Attention.query.filter_by(
name_hash=hash_name( name_hash=hash_name(u.name), pid=pid
u.name), pid=pid).first() ).first()
if not at: if not at:
at = Attention(name_hash=hash_name(u.name), pid=pid, disabled=True) at = Attention(name_hash=hash_name(u.name), pid=pid, disabled=True)