add unread count to thread title in topic view and thread view
This commit is contained in:
@ -54,12 +54,14 @@ def thread(slug):
|
||||
other_topics = Topics.select()
|
||||
|
||||
is_subscribed = False
|
||||
unread_count = None
|
||||
if is_logged_in():
|
||||
subscription = Subscriptions.find({
|
||||
'thread_id': thread.id,
|
||||
'user_id': get_active_user().id,
|
||||
})
|
||||
if subscription:
|
||||
unread_count = subscription.get_unread_count()
|
||||
if int(posts[-1]['created_at']) > int(subscription.last_seen):
|
||||
subscription.update({
|
||||
'last_seen': int(posts[-1]['created_at'])
|
||||
@ -76,6 +78,7 @@ def thread(slug):
|
||||
topics = other_topics,
|
||||
is_subscribed = is_subscribed,
|
||||
Reactions = Reactions,
|
||||
unread_count = unread_count,
|
||||
)
|
||||
|
||||
|
||||
|
@ -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