From 44b06cdad0467d7a8a872fc551d7cc5e7700c376 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 27 Dec 2023 13:02:52 +1300 Subject: [PATCH] upvotes in low quality communities do not add to reputation --- app/activitypub/util.py | 8 ++++++++ app/post/routes.py | 39 +++++++++++++++++++++++++++--------- app/templates/post/post.html | 4 ++-- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index e9f47ae6..896a951a 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -660,6 +660,8 @@ def upvote_post_reply(comment, user): comment.score += effect vote = PostReplyVote(user_id=user.id, post_reply_id=comment.id, author_id=comment.author.id, effect=effect) + if comment.community.low_quality and effect > 0: + effect = 0 comment.author.reputation += effect db.session.add(vote) else: @@ -675,6 +677,8 @@ def upvote_post_reply(comment, user): comment.score += effect vote = PostReplyVote(user_id=user.id, post_reply_id=comment.id, author_id=comment.author.id, effect=effect) + if comment.community.low_quality and effect > 0: + effect = 0 comment.author.reputation += effect db.session.add(vote) else: @@ -690,6 +694,8 @@ def upvote_post(post, user): post.score += effect vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id, effect=effect) + if post.community.low_quality and effect > 0: + effect = 0 post.author.reputation += effect db.session.add(vote) else: @@ -705,6 +711,8 @@ def upvote_post(post, user): post.score += effect vote = PostVote(user_id=user.id, post_id=post.id, author_id=post.author.id, effect=effect) + if post.community.low_quality and effect > 0: + effect = 0 post.author.reputation += effect db.session.add(vote) diff --git a/app/post/routes.py b/app/post/routes.py index 1248ae19..bda8955b 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -150,7 +150,8 @@ def post_vote(post_id: int, vote_direction): post = Post.query.get_or_404(post_id) existing_vote = PostVote.query.filter_by(user_id=current_user.id, post_id=post.id).first() if existing_vote: - post.author.reputation -= existing_vote.effect + if not post.community.low_quality: + post.author.reputation -= existing_vote.effect if existing_vote.effect > 0: # previous vote was up if vote_direction == 'upvote': # new vote is also up, so remove it db.session.delete(existing_vote) @@ -186,20 +187,38 @@ def post_vote(post_id: int, vote_direction): downvoted_class = 'voted_down' vote = PostVote(user_id=current_user.id, post_id=post.id, author_id=post.author.id, effect=effect) + # upvotes do not increase reputation in low quality communities + if post.community.low_quality and effect > 0: + effect = 0 post.author.reputation += effect db.session.add(vote) + action_type = 'Like' if vote_direction == 'upvote' else 'Dislike' + action_json = { + 'actor': current_user.profile_id(), + 'object': post.profile_id(), + 'type': action_type, + 'id': f"https://{current_app.config['SERVER_NAME']}/activities/{action_type.lower()}/{gibberish(15)}", + 'audience': post.community.profile_id() + } if post.community.is_local(): - ... - else: - action_type = 'Like' if vote_direction == 'upvote' else 'Dislike' - action_json = { - 'actor': current_user.profile_id(), - 'object': post.profile_id(), - 'type': action_type, - 'id': f"https://{current_app.config['SERVER_NAME']}/activities/{action_type.lower()}/{gibberish(15)}", - 'audience': post.community.profile_id() + announce = { + "id": f"https://{current_app.config['SERVER_NAME']}/activities/announce/{gibberish(15)}", + "type": 'Announce', + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "actor": post.community.ap_profile_id, + "cc": [ + post.community.ap_followers_url + ], + '@context': default_context(), + 'object': action_json } + for instance in post.community.following_instances(): + if instance[1] and not current_user.has_blocked_instance(instance[0]): + send_to_remote_instance(instance[1], post.community.id, announce) + else: success = post_request(post.community.ap_inbox_url, action_json, current_user.private_key, current_user.ap_profile_id + '#main-key') if not success: diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 4d4f938f..e8b511f1 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -153,8 +153,8 @@

{{ _('About community') }}

-

{{ community.description_html|safe if community.description_html else '' }}

-

{{ community.rules_html|safe if community.rules_html else '' }}

+

{{ post.community.description_html|safe if post.community.description_html else '' }}

+

{{ post.community.rules_html|safe if post.community.rules_html else '' }}

{% if len(mods) > 0 and not post.community.private_mods %}

Moderators