subscription fixes

This commit is contained in:
Lera Elvoé 2025-07-02 18:51:33 +03:00
parent 7ef0b9dc7d
commit 58dd9fb439
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc

View File

@ -46,8 +46,9 @@ def thread(slug):
'user_id': get_active_user().id, 'user_id': get_active_user().id,
}) })
if subscription: if subscription:
if int(posts[-1]['created_at']) > int(subscription.last_seen):
subscription.update({ subscription.update({
'last_seen': int(time.time()) 'last_seen': int(posts[-1]['created_at'])
}) })
is_subscribed = True is_subscribed = True
@ -78,6 +79,13 @@ def reply(slug):
post_content = request.form['post_content'] post_content = request.form['post_content']
post = create_post(thread.id, user.id, 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")) return redirect(url_for(".thread", slug=slug, after=post.id, _anchor="latest-post"))