From 5db63d6907e9d9ab2d9b84e0017d0763ab3ad6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Wed, 20 May 2026 14:21:33 +0300 Subject: [PATCH] add unread count to thread title in topic view --- app/routes/topics.py | 13 +++++++++++-- app/templates/topics/topic.html | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/routes/topics.py b/app/routes/topics.py index b1e7ebb..4476b58 100644 --- a/app/routes/topics.py +++ b/app/routes/topics.py @@ -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('//feed.atom/') def feed(topic_id): diff --git a/app/templates/topics/topic.html b/app/templates/topics/topic.html index 5fda2fe..5a13d21 100644 --- a/app/templates/topics/topic.html +++ b/app/templates/topics/topic.html @@ -49,7 +49,13 @@ {%- for thread in threads -%}
- {{thread.title}} + +
    +
  • {{thread.title}}
  • + {%- if subscriptions[thread.id] -%} +
  • ({{subscriptions[thread.id]}} unread)
  • + {%- endif -%} +
    {%- if thread.is_locked -%}