add unread count to topnav and update subscription on thread view

This commit is contained in:
2026-05-20 14:07:15 +03:00
parent a5a3565496
commit daed16f099
3 changed files with 26 additions and 2 deletions

View File

@@ -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'