From edb01af961550654988471622a45b66de72f2371 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 8 Feb 2022 10:33:13 +0000 Subject: [PATCH] Support for receiving ChatMessage activities Equivalent to a Note DM --- outbox.py | 2 +- posts.py | 8 +++++--- utils.py | 14 ++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/outbox.py b/outbox.py index db6e6a690..371d7ae20 100644 --- a/outbox.py +++ b/outbox.py @@ -408,7 +408,7 @@ def post_message_to_outbox(session, translate: {}, # The following activity types get added to the index files indexed_activities = ( 'Create', 'Question', 'Note', 'EncryptedMessage', 'Article', - 'Patch', 'Announce' + 'Patch', 'Announce', 'ChatMessage' ) if message_json['type'] in indexed_activities: indexes = [outbox_name, "inbox"] diff --git a/posts.py b/posts.py index 96b827a2c..eae572545 100644 --- a/posts.py +++ b/posts.py @@ -484,9 +484,9 @@ def _is_public_feed_post(item: {}, person_posts: {}, debug: bool) -> bool: this_item = item['object'] # check that this is a public post # #Public should appear in the "to" list - itemIsNote = False + item_is_note = False if item['type'] == 'Note' or item['type'] == 'Page': - itemIsNote = True + item_is_note = True if isinstance(this_item, dict): if this_item.get('to'): @@ -497,7 +497,7 @@ def _is_public_feed_post(item: {}, person_posts: {}, debug: bool) -> bool: break if not is_public: return False - elif isinstance(this_item, str) or itemIsNote: + elif isinstance(this_item, str) or item_is_note: if item.get('to'): is_public = False for recipient in item['to']: @@ -3561,6 +3561,7 @@ def is_image_media(session, base_dir: str, http_prefix: str, if post_json_object['object']['type'] != 'Note' and \ post_json_object['object']['type'] != 'Page' and \ post_json_object['object']['type'] != 'Event' and \ + post_json_object['object']['type'] != 'ChatMessage' and \ post_json_object['object']['type'] != 'Article': return False if not post_json_object['object'].get('attachment'): @@ -3583,6 +3584,7 @@ def _add_post_string_to_timeline(post_str: str, boxname: str, # must be a recognized ActivityPub type if ('"Note"' in post_str or '"EncryptedMessage"' in post_str or + '"ChatMessage"' in post_str or '"Event"' in post_str or '"Article"' in post_str or '"Patch"' in post_str or diff --git a/utils.py b/utils.py index 5def9ec8f..c70c4fd28 100644 --- a/utils.py +++ b/utils.py @@ -2661,12 +2661,13 @@ def is_dm(post_json_object: {}) -> bool: return False if not has_object_dict(post_json_object): return False - if post_json_object['object']['type'] != 'Note' and \ - post_json_object['object']['type'] != 'Page' and \ - post_json_object['object']['type'] != 'Patch' and \ - post_json_object['object']['type'] != 'EncryptedMessage' and \ - post_json_object['object']['type'] != 'Article': - return False + if post_json_object['object']['type'] != 'ChatMessage': + if post_json_object['object']['type'] != 'Note' and \ + post_json_object['object']['type'] != 'Page' and \ + post_json_object['object']['type'] != 'Patch' and \ + post_json_object['object']['type'] != 'EncryptedMessage' and \ + post_json_object['object']['type'] != 'Article': + return False if post_json_object['object'].get('moderationStatus'): return False fields = ('to', 'cc') @@ -2693,6 +2694,7 @@ def is_reply(post_json_object: {}, actor: str) -> bool: if post_json_object['object']['type'] != 'Note' and \ post_json_object['object']['type'] != 'Page' and \ post_json_object['object']['type'] != 'EncryptedMessage' and \ + post_json_object['object']['type'] != 'ChatMessage' and \ post_json_object['object']['type'] != 'Article': return False if post_json_object['object'].get('inReplyTo'):