From cd3fce17ae9be57066a6234ced5cbb3e3237d26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Thu, 28 May 2026 21:56:07 +0300 Subject: [PATCH] fix subscriptions --- app/routes/threads.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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/')