add reactions support to thread
This commit is contained in:
@ -256,3 +256,28 @@ class APIRateLimits(Model):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
class Reactions(Model):
|
||||
table = "reactions"
|
||||
|
||||
@classmethod
|
||||
def for_post(cls, post_id):
|
||||
qb = db.QueryBuilder(cls.table)\
|
||||
.select("reaction_text, COUNT(*) as c")\
|
||||
.where({"post_id": post_id})\
|
||||
.group_by("reaction_text")\
|
||||
.order_by("c", False)
|
||||
result = qb.all()
|
||||
return result if result else []
|
||||
|
||||
@classmethod
|
||||
def get_users(cls, post_id, reaction_text):
|
||||
q = """
|
||||
SELECT user_id, username FROM reactions
|
||||
JOIN
|
||||
users ON users.id = user_id
|
||||
WHERE
|
||||
post_id = ? AND reaction_text = ?
|
||||
"""
|
||||
|
||||
return db.query(q, post_id, reaction_text)
|
||||
|
Reference in New Issue
Block a user