diff --git a/app/routes/threads.py b/app/routes/threads.py index f01ffa0..24165c6 100644 --- a/app/routes/threads.py +++ b/app/routes/threads.py @@ -62,7 +62,7 @@ def thread(thread_id, slug): user = get_active_user() if user: subscription = Subscriptions.find({'user_id': user.id, 'thread_id': thread.id}) - if subscription: + if subscription and last_post['created_at'] > int(subscription.last_seen): subscription.update({'last_seen': last_post['created_at']}) return render_template( 'threads/thread.html', thread=thread, @@ -82,13 +82,16 @@ def reply(thread_id): if not user.can_post_to_thread_or_topic(thread): return redirect(url_for('.thread_by_id', thread_id=thread_id)) post = Posts.new(user.id, thread.id, request.form.get('babycode_content')) + subscription = Subscriptions.find({'user_id': user.id, 'thread_id': thread.id}) if get_form_checkbox('subscribe'): - if not Subscriptions.find({'user_id': user.id, 'thread_id': thread.id}): - Subscriptions.create({ + if not subscription: + subscription = Subscriptions.create({ 'user_id': user.id, 'thread_id': thread.id, 'last_seen': time_now(), }) + if subscription and subscription.last_seen < time_now(): + subscription.update({'last_seen': time_now()}) return redirect(url_for('.thread_by_id', thread_id=thread_id, after=post.id, _anchor=f'post-{post.id}')) @bp.get('//edit/')