diff --git a/inbox.py b/inbox.py index 6c8b0e31d..44c8d06c7 100644 --- a/inbox.py +++ b/inbox.py @@ -3222,17 +3222,43 @@ def _receive_undo_announce(recent_posts_cache: {}, def json_post_allows_comments(post_json_object: {}) -> bool: """Returns true if the given post allows comments/replies """ + # reply control with + # https://codeberg.org/fediverse/fep/src/branch/main/fep/5624/fep-5624.md + reply_control = None + if 'canReply' in post_json_object: + reply_control = post_json_object['canReply'] + if 'capabilities' in post_json_object: + if isinstance(post_json_object['capabilities'], dict): + if 'reply' in post_json_object['capabilities']: + reply_control = post_json_object['capabilities']['reply'] + obj_dict_exists = False + if has_object_dict(post_json_object): + obj_dict_exists = True + post_obj = post_json_object['object'] + if 'canReply' in post_obj: + reply_control = post_obj['canReply'] + if 'capabilities' in post_obj: + if isinstance(post_obj['capabilities'], dict): + if 'reply' in post_obj['capabilities']: + reply_control = post_obj['capabilities']['reply'] + if reply_control: + if isinstance(reply_control, str): + if not reply_control.endswith('#Public'): + return False + if 'commentsEnabled' in post_json_object: return post_json_object['commentsEnabled'] if 'rejectReplies' in post_json_object: return not post_json_object['rejectReplies'] + if post_json_object.get('object'): - if not has_object_dict(post_json_object): + if not obj_dict_exists: return False if 'commentsEnabled' in post_json_object['object']: return post_json_object['object']['commentsEnabled'] if 'rejectReplies' in post_json_object['object']: return not post_json_object['object']['rejectReplies'] + return True