Move code to upvote own post into new()

This commit is contained in:
freamon 2025-01-07 09:45:30 +00:00
parent 7c817decf2
commit 1fa74370c6
2 changed files with 7 additions and 12 deletions

View file

@ -722,8 +722,6 @@ def add_post(actor, type):
post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}"
db.session.commit()
upvote_own_post(post)
if post.type == POST_TYPE_POLL:
poll = Poll.query.filter_by(post_id=post.id).first()
if not poll.local_only:
@ -2007,11 +2005,3 @@ def check_url_already_posted():
abort(404)
def upvote_own_post(post):
post.score = 1
post.up_votes = 1
post.ranking = post.post_ranking(post.score, utcnow())
vote = PostVote(user_id=current_user.id, post_id=post.id, author_id=current_user.id, effect=1)
db.session.add(vote)
db.session.commit()
cache.delete_memoized(recently_upvoted_posts, current_user.id)

View file

@ -1171,7 +1171,7 @@ class Post(db.Model):
find_licence_or_create, make_image_sizes, notify_about_post
from app.utils import allowlist_html, markdown_to_html, html_to_text, microblog_content_to_title, blocked_phrases, \
is_image_url, is_video_url, domain_from_url, opengraph_parse, shorten_string, remove_tracking_from_link, \
is_video_hosting_site, communities_banned_from
is_video_hosting_site, communities_banned_from, recently_upvoted_posts
microblog = False
if 'name' not in request_json['object']: # Microblog posts
@ -1399,6 +1399,11 @@ class Post(db.Model):
if post.community_id not in communities_banned_from(user.id):
notify_about_post(post)
# attach initial upvote to author
vote = PostVote(user_id=user.id, post_id=post.id, author_id=user.id, effect=1)
db.session.add(vote)
if user.is_local():
cache.delete_memoized(recently_upvoted_posts, user.id)
if user.reputation > 100:
post.up_votes += 1
post.score += 1