mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
stop lemmy from duplicating content
This commit is contained in:
parent
fec2e9117c
commit
1fc2ba631f
4 changed files with 20 additions and 14 deletions
|
@ -417,7 +417,7 @@ def shared_inbox():
|
|||
community_ap_id = request_json['object']['audience']
|
||||
community = find_actor_or_create(community_ap_id)
|
||||
user = find_actor_or_create(user_ap_id)
|
||||
if user and community:
|
||||
if (user and not user.is_local()) and community:
|
||||
user.last_seen = community.last_active = g.site.last_active = utcnow()
|
||||
object_type = request_json['object']['object']['type']
|
||||
new_content_types = ['Page', 'Article', 'Link', 'Note']
|
||||
|
@ -512,7 +512,7 @@ def shared_inbox():
|
|||
user_ap_id = request_json['object']['actor']
|
||||
liked_ap_id = request_json['object']['object']
|
||||
user = find_actor_or_create(user_ap_id)
|
||||
if user:
|
||||
if user and not user.is_local():
|
||||
liked = find_liked_object(liked_ap_id)
|
||||
# insert into voted table
|
||||
if liked is None:
|
||||
|
@ -536,7 +536,7 @@ def shared_inbox():
|
|||
user_ap_id = request_json['object']['actor']
|
||||
liked_ap_id = request_json['object']['object']
|
||||
user = find_actor_or_create(user_ap_id)
|
||||
if user:
|
||||
if user and not user.is_local():
|
||||
disliked = find_liked_object(liked_ap_id)
|
||||
# insert into voted table
|
||||
if disliked is None:
|
||||
|
@ -647,7 +647,7 @@ def shared_inbox():
|
|||
comment = PostReply.query.filter_by(ap_id=target_ap_id).first()
|
||||
if '/post/' in target_ap_id:
|
||||
post = Post.query.filter_by(ap_id=target_ap_id).first()
|
||||
if user and post:
|
||||
if (user and not user.is_local()) and post:
|
||||
user.last_seen = utcnow()
|
||||
existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first()
|
||||
if existing_vote:
|
||||
|
@ -659,7 +659,7 @@ def shared_inbox():
|
|||
post.score -= existing_vote.effect
|
||||
db.session.delete(existing_vote)
|
||||
activity_log.result = 'success'
|
||||
if user and comment:
|
||||
if (user and not user.is_local()) and comment:
|
||||
existing_vote = PostReplyVote.query.filter_by(user_id=user.id, post_reply_id=comment.id).first()
|
||||
if existing_vote:
|
||||
comment.author.reputation -= existing_vote.effect
|
||||
|
@ -682,7 +682,7 @@ def shared_inbox():
|
|||
comment = PostReply.query.filter_by(ap_id=target_ap_id).first()
|
||||
if '/post/' in target_ap_id:
|
||||
post = Post.query.filter_by(ap_id=target_ap_id).first()
|
||||
if user and post:
|
||||
if (user and not user.is_local()) and post:
|
||||
existing_vote = PostVote.query.filter_by(user_id=user.id, post_id=post.id).first()
|
||||
if existing_vote:
|
||||
post.author.reputation -= existing_vote.effect
|
||||
|
@ -690,7 +690,7 @@ def shared_inbox():
|
|||
post.score -= existing_vote.effect
|
||||
db.session.delete(existing_vote)
|
||||
activity_log.result = 'success'
|
||||
if user and comment:
|
||||
if (user and not user.is_local()) and comment:
|
||||
existing_vote = PostReplyVote.query.filter_by(user_id=user.id,
|
||||
post_reply_id=comment.id).first()
|
||||
if existing_vote:
|
||||
|
@ -754,10 +754,10 @@ def shared_inbox():
|
|||
comment = PostReply.query.filter_by(ap_id=target_ap_id).first()
|
||||
if '/post/' in target_ap_id:
|
||||
post = Post.query.filter_by(ap_id=target_ap_id).first()
|
||||
if user and post:
|
||||
if (user and not user.is_local()) and post:
|
||||
upvote_post(post, user)
|
||||
activity_log.result = 'success'
|
||||
elif user and comment:
|
||||
elif (user and not user.is_local()) and comment:
|
||||
upvote_post_reply(comment, user)
|
||||
activity_log.result = 'success'
|
||||
|
||||
|
@ -775,10 +775,10 @@ def shared_inbox():
|
|||
comment = PostReply.query.filter_by(ap_id=target_ap_id).first()
|
||||
if '/post/' in target_ap_id:
|
||||
post = Post.query.filter_by(ap_id=target_ap_id).first()
|
||||
if user and comment:
|
||||
if (user and not user.is_local()) and comment:
|
||||
downvote_post_reply(comment, user)
|
||||
activity_log.result = 'success'
|
||||
elif user and post:
|
||||
elif (user and not user.is_local()) and post:
|
||||
downvote_post(post, user)
|
||||
activity_log.result = 'success'
|
||||
else:
|
||||
|
|
|
@ -459,7 +459,10 @@ def find_instance_id(server):
|
|||
if instance:
|
||||
return instance.id
|
||||
else:
|
||||
instance_data = get_request(f"https://{server}", headers={'Accept': 'application/activity+json'})
|
||||
try:
|
||||
instance_data = get_request(f"https://{server}", headers={'Accept': 'application/activity+json'})
|
||||
except:
|
||||
return None
|
||||
if instance_data.status_code == 200:
|
||||
try:
|
||||
instance_json = instance_data.json()
|
||||
|
|
|
@ -48,7 +48,7 @@ def show_post(post_id: int):
|
|||
from_bot=current_user.bot, up_votes=1, nsfw=post.nsfw, nsfl=post.nsfl,
|
||||
notify_author=form.notify_author.data)
|
||||
if post.notify_author and current_user.id != post.user_id: # todo: check if replier is blocked
|
||||
notification = Notification(title=_('Reply: ') + shorten_string(form.body.data), user_id=post.user_id,
|
||||
notification = Notification(title=_('Reply: ') + shorten_string(form.body.data, 42), user_id=post.user_id,
|
||||
author_id=current_user.id, url=url_for('activitypub.post_ap', post_id=post.id))
|
||||
db.session.add(notification)
|
||||
post.last_active = post.community.last_active = utcnow()
|
||||
|
@ -301,7 +301,7 @@ def add_reply(post_id: int, comment_id: int):
|
|||
notify_author=form.notify_author.data)
|
||||
db.session.add(reply)
|
||||
if in_reply_to.notify_author and current_user.id != in_reply_to.user_id and in_reply_to.author.ap_id is None: # todo: check if replier is blocked
|
||||
notification = Notification(title=_('Reply: ') + shorten_string(form.body.data), user_id=in_reply_to.user_id,
|
||||
notification = Notification(title=_('Reply: ') + shorten_string(form.body.data, 42), user_id=in_reply_to.user_id,
|
||||
author_id=current_user.id, url=url_for('activitypub.post_ap', post_id=post.id))
|
||||
db.session.add(notification)
|
||||
db.session.commit()
|
||||
|
|
|
@ -78,6 +78,9 @@ def get_request(uri, params=None, headers=None) -> requests.Response:
|
|||
except ValueError as ex:
|
||||
# Convert to a more generic error we handle
|
||||
raise requests.exceptions.RequestException(f"InvalidCodepoint: {str(ex)}") from None
|
||||
except requests.exceptions.ReadTimeout as read_timeout:
|
||||
current_app.logger.info(f"{uri} {read_timeout}")
|
||||
raise requests.exceptions.ReadTimeout from read_timeout
|
||||
|
||||
return response
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue