From ad4d30a1bb3cf46744a5fa851a72cb9fe3c7c93c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 10 Dec 2023 22:58:05 +0000 Subject: [PATCH] reply control for pixelfed capabilities --- inbox.py | 14 ++++++++++++-- utils.py | 16 ++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/inbox.py b/inbox.py index 24de733da..97b54e28a 100644 --- a/inbox.py +++ b/inbox.py @@ -3355,7 +3355,11 @@ def json_post_allows_comments(post_json_object: {}) -> bool: 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'] + if isinstance(post_json_object['capabilities']['reply'], str): + reply_control = post_json_object['capabilities']['reply'] + else: + # capabilities exist but there is no reply field + reply_control = 'noreply' obj_dict_exists = False if has_object_dict(post_json_object): obj_dict_exists = True @@ -3365,9 +3369,15 @@ def json_post_allows_comments(post_json_object: {}) -> bool: if 'capabilities' in post_obj: if isinstance(post_obj['capabilities'], dict): if 'reply' in post_obj['capabilities']: - reply_control = post_obj['capabilities']['reply'] + if isinstance(post_obj['capabilities']['reply'], str): + reply_control = post_obj['capabilities']['reply'] + else: + # capabilities exist but there is no reply field + reply_control = 'noreply' if reply_control: if isinstance(reply_control, str): + if reply_control == 'noreply': + return False if not reply_control.endswith('#Public'): # TODO handle non-public reply permissions print('CAPABILITIES: replies ' + str(reply_control)) diff --git a/utils.py b/utils.py index cbcd257cd..2d472f911 100644 --- a/utils.py +++ b/utils.py @@ -4237,12 +4237,16 @@ def disallow_announce(content: str, attachment: [], capabilities: {}) -> bool: """Are announces/boosts not allowed for the given post? """ # pixelfed style capabilities - if capabilities.get('announce'): - if isinstance(capabilities['announce'], str): - if not capabilities['announce'].endswith('#Public'): - # TODO handle non-public announce permissions - print('CAPABILITIES: announce ' + capabilities['announce']) - return True + if capabilities: + if 'announce' in capabilities: + if isinstance(capabilities['announce'], str): + if not capabilities['announce'].endswith('#Public'): + # TODO handle non-public announce permissions + print('CAPABILITIES: announce ' + capabilities['announce']) + return True + else: + # capabilities exist but with no announce defined + return True # emojis disallow_strings = (