update user.last_seen whenever they post content or vote

This commit is contained in:
rimu 2023-12-09 22:28:20 +13:00
parent 05c2c7372b
commit 7fd8935983
2 changed files with 12 additions and 0 deletions

View file

@ -290,6 +290,7 @@ def shared_inbox():
community = find_actor_or_create(community_ap_id)
user = find_actor_or_create(user_ap_id)
if user and community:
user.last_seen = datetime.utcnow()
object_type = request_json['object']['type']
new_content_types = ['Page', 'Article', 'Link', 'Note']
if object_type in new_content_types: # create a new post
@ -398,6 +399,7 @@ def shared_inbox():
community = find_actor_or_create(community_ap_id)
user = find_actor_or_create(user_ap_id)
if user and community:
user.last_seen = datetime.utcnow()
object_type = request_json['object']['object']['type']
new_content_types = ['Page', 'Article', 'Link', 'Note']
if object_type in new_content_types: # create a new post
@ -528,6 +530,7 @@ def shared_inbox():
banned = CommunityBan.query.filter_by(user_id=user.id,
community_id=community.id).first()
if banned is None:
user.last_seen = datetime.utcnow()
if community_membership(user, community) != SUBSCRIPTION_MEMBER:
member = CommunityMember(user_id=user.id, community_id=community.id)
db.session.add(member)
@ -588,6 +591,7 @@ def shared_inbox():
user = find_actor_or_create(user_ap_id)
community = find_actor_or_create(community_ap_id)
if user and community:
user.last_seen = datetime.utcnow()
member = CommunityMember.query.filter_by(user_id=user.id, community_id=community.id).first()
join_request = CommunityJoinRequest.query.filter_by(user_id=user.id,
community_id=community.id).first()
@ -609,6 +613,7 @@ def shared_inbox():
if '/post/' in target_ap_id:
post = Post.query.filter_by(ap_id=target_ap_id).first()
if user and post:
user.last_seen = datetime.utcnow()
existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first()
if existing_vote:
post.author.reputation -= existing_vote.effect
@ -716,6 +721,7 @@ def shared_inbox():
if '/post/' in target_ap_id:
post = Post.query.filter_by(ap_id=target_ap_id).first()
if user and post:
user.last_seen = datetime.utcnow()
existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first()
if not existing_vote:
post.up_votes += 1
@ -741,6 +747,7 @@ def shared_inbox():
db.session.add(vote)
activity_log.result = 'success'
elif user and comment:
user.last_seen = datetime.utcnow()
existing_vote = PostReplyVote.query.filter_by(user_id=user.id,
post_reply_id=comment.id).first()
if not existing_vote:
@ -784,6 +791,7 @@ def shared_inbox():
if '/post/' in target_ap_id:
post = Post.query.filter_by(ap_id=target_ap_id).first()
if user and comment:
user.last_seen = datetime.utcnow()
existing_vote = PostReplyVote.query.filter_by(user_id=user.id,
post_reply_id=comment.id).first()
if not existing_vote:
@ -814,6 +822,7 @@ def shared_inbox():
pass # they have already downvoted this reply
activity_log.result = 'success'
elif user and post:
user.last_seen = datetime.utcnow()
existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first()
if not existing_vote:
effect = -1.0

View file

@ -161,6 +161,7 @@ def post_vote(post_id: int, vote_direction):
effect=effect)
post.author.reputation += effect
db.session.add(vote)
current_user.last_seen = datetime.utcnow()
db.session.commit()
return render_template('post/_post_voting_buttons.html', post=post,
upvoted_class=upvoted_class,
@ -211,6 +212,7 @@ def comment_vote(comment_id, vote_direction):
vote = PostReplyVote(user_id=current_user.id, post_reply_id=comment_id, author_id=comment.author.id, effect=effect)
comment.author.reputation += effect
db.session.add(vote)
current_user.last_seen = datetime.utcnow()
db.session.commit()
return render_template('post/_voting_buttons.html', comment=comment,
upvoted_class=upvoted_class,
@ -238,6 +240,7 @@ def add_reply(post_id: int, comment_id: int):
is_moderator = current_user.is_authenticated and any(mod.user_id == current_user.id for mod in mods)
form = NewReplyForm()
if form.validate_on_submit():
current_user.last_seen = datetime.utcnow()
reply = PostReply(user_id=current_user.id, post_id=post.id, parent_id=in_reply_to.id, depth=in_reply_to.depth + 1,
community_id=post.community.id, body=form.body.data,
body_html=markdown_to_html(form.body.data), body_html_safe=True,