diff --git a/app/routes/threads.py b/app/routes/threads.py index cb938ca..cba37e8 100644 --- a/app/routes/threads.py +++ b/app/routes/threads.py @@ -46,9 +46,10 @@ def thread(slug): 'user_id': get_active_user().id, }) if subscription: - subscription.update({ - 'last_seen': int(time.time()) - }) + if int(posts[-1]['created_at']) > int(subscription.last_seen): + subscription.update({ + 'last_seen': int(posts[-1]['created_at']) + }) is_subscribed = True return render_template( @@ -78,6 +79,13 @@ def reply(slug): post_content = request.form['post_content'] post = create_post(thread.id, user.id, post_content) + subscription = Subscriptions.find({'user_id': user.id, 'thread_id': thread.id}) + + if subscription: + subscription.update({'last_seen': int(time.time())}) + elif request.form.get('subscribe', default=None) == 'on': + Subscriptions.create({'user_id': user.id, 'thread_id': thread.id, 'last_seen': int(time.time())}) + return redirect(url_for(".thread", slug=slug, after=post.id, _anchor="latest-post"))