add unread count to topnav and update subscription on thread view
This commit is contained in:
@@ -117,6 +117,24 @@ class Users(Model):
|
||||
def is_subscribed(self, thread_id):
|
||||
return Subscriptions.count({'user_id': self.id, 'thread_id': thread_id}) > 0
|
||||
|
||||
def get_unread_count(self):
|
||||
q = """
|
||||
SELECT
|
||||
COUNT(posts.id) as c
|
||||
FROM
|
||||
subscriptions
|
||||
JOIN
|
||||
threads ON subscriptions.thread_id = threads.id
|
||||
JOIN
|
||||
posts ON threads.id = posts.thread_id
|
||||
WHERE
|
||||
subscriptions.user_id = ?
|
||||
AND
|
||||
posts.created_at > subscriptions.last_seen
|
||||
"""
|
||||
res = db.fetch_one(q, self.id)
|
||||
return res["c"] or 0
|
||||
|
||||
|
||||
class Topics(Model):
|
||||
table = 'topics'
|
||||
|
||||
Reference in New Issue
Block a user