add unread count to thread title in topic view

This commit is contained in:
2026-05-20 14:21:33 +03:00
parent daed16f099
commit 5db63d6907
2 changed files with 18 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
from flask import Blueprint, redirect, url_for, render_template, request, session, abort
from ..models import Topics, Threads
from ..models import Topics, Threads, Subscriptions
from ..auth import get_active_user
import math
bp = Blueprint('topics', __name__, url_prefix = '/topics/')
@@ -33,7 +34,15 @@ def topic(topic_id, slug):
page = max(1, min(int(request.args.get('page', default=1)), page_count))
except ValueError:
abort(404)
return render_template('topics/topic.html', topic=topic, threads=topic.get_threads(PER_PAGE, page, sort_by), sort_by=sort_by, page=page, page_count=page_count)
threads = topic.get_threads(PER_PAGE, page, sort_by)
subscriptions = {}
user = get_active_user()
if user:
for thread in threads:
subscription = Subscriptions.find({'user_id': user.id, 'thread_id': thread['id']})
if subscription:
subscriptions[thread['id']] = subscription.get_unread_count()
return render_template('topics/topic.html', topic=topic, threads=threads, sort_by=sort_by, page=page, page_count=page_count, subscriptions=subscriptions)
@bp.get('/<int:topic_id>/feed.atom/')
def feed(topic_id):