add unread count to thread title in topic view and thread view
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
from flask import (
|
||||
Blueprint, render_template, request, redirect, url_for, flash, session
|
||||
)
|
||||
from .users import login_required, mod_only
|
||||
from ..models import Users, Topics, Threads
|
||||
from .users import login_required, mod_only, get_active_user, is_logged_in
|
||||
from ..models import Users, Topics, Threads, Subscriptions
|
||||
from ..constants import InfoboxKind
|
||||
from slugify import slugify
|
||||
import time
|
||||
@ -62,9 +62,22 @@ def topic(slug):
|
||||
page_count = max(math.ceil(threads_count / THREADS_PER_PAGE), 1)
|
||||
page = max(1, min(int(request.args.get('page', default=1)), page_count))
|
||||
|
||||
threads_list = target_topic.get_threads(THREADS_PER_PAGE, page, sort_by)
|
||||
subscriptions = {}
|
||||
if is_logged_in():
|
||||
for thread in threads_list:
|
||||
subscription = Subscriptions.find({
|
||||
'user_id': get_active_user().id,
|
||||
'thread_id': thread['id'],
|
||||
})
|
||||
if subscription:
|
||||
print(subscription.get_unread_count())
|
||||
subscriptions[subscription.id] = subscription.get_unread_count()
|
||||
|
||||
return render_template(
|
||||
"topics/topic.html",
|
||||
threads_list = target_topic.get_threads(THREADS_PER_PAGE, page, sort_by),
|
||||
threads_list = threads_list,
|
||||
subscriptions = subscriptions,
|
||||
topic = target_topic,
|
||||
current_page = page,
|
||||
page_count = page_count
|
||||
|
Reference in New Issue
Block a user