mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Move code to upvote own post into new()
This commit is contained in:
parent
7c817decf2
commit
1fa74370c6
2 changed files with 7 additions and 12 deletions
|
@ -722,8 +722,6 @@ def add_post(actor, type):
|
||||||
post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}"
|
post.ap_id = f"https://{current_app.config['SERVER_NAME']}/post/{post.id}"
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
upvote_own_post(post)
|
|
||||||
|
|
||||||
if post.type == POST_TYPE_POLL:
|
if post.type == POST_TYPE_POLL:
|
||||||
poll = Poll.query.filter_by(post_id=post.id).first()
|
poll = Poll.query.filter_by(post_id=post.id).first()
|
||||||
if not poll.local_only:
|
if not poll.local_only:
|
||||||
|
@ -2007,11 +2005,3 @@ def check_url_already_posted():
|
||||||
abort(404)
|
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)
|
|
||||||
|
|
|
@ -1171,7 +1171,7 @@ class Post(db.Model):
|
||||||
find_licence_or_create, make_image_sizes, notify_about_post
|
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, \
|
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_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
|
microblog = False
|
||||||
if 'name' not in request_json['object']: # Microblog posts
|
if 'name' not in request_json['object']: # Microblog posts
|
||||||
|
@ -1399,11 +1399,16 @@ class Post(db.Model):
|
||||||
if post.community_id not in communities_banned_from(user.id):
|
if post.community_id not in communities_banned_from(user.id):
|
||||||
notify_about_post(post)
|
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:
|
if user.reputation > 100:
|
||||||
post.up_votes += 1
|
post.up_votes += 1
|
||||||
post.score += 1
|
post.score += 1
|
||||||
post.ranking = post.post_ranking(post.score, post.posted_at)
|
post.ranking = post.post_ranking(post.score, post.posted_at)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return post
|
return post
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue