Merge pull request 'Ignore Page/Announce, and some little fixes' (#158) from freamon/pyfedi:15 into main

Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/158
This commit is contained in:
rimu 2024-04-16 10:20:52 +00:00
commit 39946fcc2a
4 changed files with 14 additions and 28 deletions

View file

@ -79,7 +79,7 @@ sudo apt install tesseract-ocr
* Clone PyFedi * Clone PyFedi
```basg ```bash
git clone https://codeberg.org/rimu/pyfedi.git git clone https://codeberg.org/rimu/pyfedi.git
``` ```

View file

@ -672,30 +672,16 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
ocp.cross_posts.remove(post.id) ocp.cross_posts.remove(post.id)
delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id) delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id)
activity_log.result = 'success' activity_log.result = 'success'
elif request_json['object']['type'] == 'Page': # Editing a post elif request_json['object']['type'] == 'Page': # Sent for Mastodon's benefit
post = Post.query.filter_by(ap_id=request_json['object']['id']).first() activity_log.result = 'ignored'
if post: activity_log.exception_message = 'Intended for Mastodon'
try: db.session.add(activity_log)
update_post_from_activity(post, request_json) db.session.commit()
except KeyError: elif request_json['object']['type'] == 'Note': # Never sent?
activity_log.result = 'exception' activity_log.result = 'ignored'
db.session.commit() activity_log.exception_message = 'Intended for Mastodon'
return db.session.add(activity_log)
activity_log.result = 'success' db.session.commit()
else:
activity_log.exception_message = 'Post not found'
elif request_json['object']['type'] == 'Note': # Editing a reply
reply = PostReply.query.filter_by(ap_id=request_json['object']['id']).first()
if reply:
try:
update_post_reply_from_activity(reply, request_json)
except KeyError:
activity_log.result = 'exception'
db.session.commit()
return
activity_log.result = 'success'
else:
activity_log.exception_message = 'PostReply not found'
elif request_json['object']['type'] == 'Update': # Editing a post or comment elif request_json['object']['type'] == 'Update': # Editing a post or comment
if request_json['object']['object']['type'] == 'Page': if request_json['object']['object']['type'] == 'Page':
post = Post.query.filter_by(ap_id=request_json['object']['object']['id']).first() post = Post.query.filter_by(ap_id=request_json['object']['object']['id']).first()

View file

@ -41,9 +41,9 @@
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
{% if current_user.is_authenticated and community_membership(current_user, post.community) %} {% if current_user.is_authenticated and community_membership(current_user, post.community) %}
<a class="w-100 btn btn-primary" href="/community/{{ post.community.link() }}/unsubscribe" rel="nofollow">{{ _('Unsubscribe') }}</a> <a class="w-100 btn btn-primary" href="/community/{{ post.community.link() }}/unsubscribe" rel="nofollow">{{ _('Leave') }}</a>
{% else %} {% else %}
<a class="w-100 btn btn-primary" href="/community/{{ post.community.link() }}/subscribe" rel="nofollow">{{ _('Subscribe') }}</a> <a class="w-100 btn btn-primary" href="/community/{{ post.community.link() }}/subscribe" rel="nofollow">{{ _('Join') }}</a>
{% endif %} {% endif %}
</div> </div>
<div class="col-6"> <div class="col-6">

View file

@ -231,7 +231,7 @@ def markdown_to_html(markdown_text) -> str:
if markdown_text: if markdown_text:
raw_html = markdown2.markdown(markdown_text, safe_mode=True, extras={'middle-word-em': False, 'tables': True, 'fenced-code-blocks': True, 'strike': True}) raw_html = markdown2.markdown(markdown_text, safe_mode=True, extras={'middle-word-em': False, 'tables': True, 'fenced-code-blocks': True, 'strike': True})
# replace lemmy spoiler tokens with appropriate html tags instead. (until possibly added as extra to markdown2) # replace lemmy spoiler tokens with appropriate html tags instead. (until possibly added as extra to markdown2)
re_spoiler = re.compile(r':{3} spoiler\s+?(\S.+?)(?:\n|</p>)(.+?)(?:\n|<p>):{3}', re.S) re_spoiler = re.compile(r':{3}\s*?spoiler\s+?(\S.+?)(?:\n|</p>)(.+?)(?:\n|<p>):{3}', re.S)
raw_html = re_spoiler.sub(r'<details><summary>\1</summary><p>\2</p></details>', raw_html) raw_html = re_spoiler.sub(r'<details><summary>\1</summary><p>\2</p></details>', raw_html)
return allowlist_html(raw_html) return allowlist_html(raw_html)
else: else: