mirror of https://gitlab.com/bashrc2/epicyon
Handle inbox posts containing collections of subposts
parent
83e7397c3a
commit
101ea22e89
101
inbox.py
101
inbox.py
|
|
@ -3358,6 +3358,34 @@ def _receive_follow_request(session, session_onion, session_i2p,
|
|||
system_language, mitm_servers)
|
||||
|
||||
|
||||
def _split_post_collection(collection_post_json: {}) -> []:
|
||||
"""Splits a collection post up into separate posts
|
||||
https://codeberg.org/fediverse/fep/src/branch/main/fep/1a11/fep-1a11.md
|
||||
"""
|
||||
if not has_object_dict(collection_post_json):
|
||||
return [collection_post_json]
|
||||
if not collection_post_json['object'].get('type'):
|
||||
return [collection_post_json]
|
||||
if not isinstance(collection_post_json['object']['type'], str):
|
||||
return [collection_post_json]
|
||||
if collection_post_json['object']['type'] != 'OrderedCollection':
|
||||
return [collection_post_json]
|
||||
if not collection_post_json['object'].get('orderedItems'):
|
||||
return [collection_post_json]
|
||||
if not isinstance(collection_post_json['object']['orderedItems'], list):
|
||||
return [collection_post_json]
|
||||
posts_list = []
|
||||
for post_dict in collection_post_json['object']['orderedItems']:
|
||||
if not isinstance(post_dict, dict):
|
||||
continue
|
||||
post_json = collection_post_json.copy()
|
||||
post_json['object'] = post_dict
|
||||
posts_list.append(post_json)
|
||||
if not posts_list:
|
||||
return [collection_post_json]
|
||||
return posts_list
|
||||
|
||||
|
||||
def run_inbox_queue(server,
|
||||
recent_posts_cache: {}, max_recent_posts: int,
|
||||
project_version: str,
|
||||
|
|
@ -3811,22 +3839,19 @@ def run_inbox_queue(server,
|
|||
# if queue_json['post'].get('id'):
|
||||
# queue_json['post']['id'] = queue_json['id']
|
||||
|
||||
curr_post_json = queue_json['post']
|
||||
curr_nickname = queue_json['postNickname']
|
||||
curr_destination = queue_json['destination']
|
||||
|
||||
# if the post contains a collection of posts then split it up
|
||||
remove_queue_item = False
|
||||
posts_list_json = _split_post_collection(queue_json['post'])
|
||||
for curr_post_json in posts_list_json:
|
||||
|
||||
if receive_undo(base_dir, curr_post_json,
|
||||
debug, domain, onion_domain, i2p_domain,
|
||||
yggdrasil_domain):
|
||||
print('Queue: Undo accepted from ' + key_id)
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
except OSError:
|
||||
print('EX: run_inbox_queue 5 unable to delete ' +
|
||||
str(queue_filename))
|
||||
if queue:
|
||||
queue.pop(0)
|
||||
remove_queue_item = True
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', '_receive_undo',
|
||||
debug)
|
||||
|
|
@ -3852,14 +3877,7 @@ def run_inbox_queue(server,
|
|||
server.followers_sync_cache,
|
||||
server.sites_unavailable,
|
||||
server.mitm_servers):
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
except OSError:
|
||||
print('EX: run_inbox_queue 6 unable to delete ' +
|
||||
str(queue_filename))
|
||||
if queue:
|
||||
queue.pop(0)
|
||||
remove_queue_item = True
|
||||
print('Queue: Follow activity for ' + key_id +
|
||||
' removed from queue')
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
|
|
@ -3876,14 +3894,7 @@ def run_inbox_queue(server,
|
|||
domain, onion_domain, i2p_domain,
|
||||
yggdrasil_domain):
|
||||
print('Queue: Accept/Reject received from ' + key_id)
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
except OSError:
|
||||
print('EX: run_inbox_queue 7 unable to delete ' +
|
||||
str(queue_filename))
|
||||
if queue:
|
||||
queue.pop(0)
|
||||
remove_queue_item = True
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', 'receive_accept_reject',
|
||||
debug)
|
||||
|
|
@ -3909,14 +3920,7 @@ def run_inbox_queue(server,
|
|||
last_quote_request):
|
||||
last_quote_request = int(time.time())
|
||||
print('Queue: QuoteRequest received from ' + key_id)
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
except OSError:
|
||||
print('EX: run_inbox_queue 7 unable to delete ' +
|
||||
str(queue_filename))
|
||||
if queue:
|
||||
queue.pop(0)
|
||||
remove_queue_item = True
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', 'receive_quote_request',
|
||||
debug)
|
||||
|
|
@ -3944,14 +3948,7 @@ def run_inbox_queue(server,
|
|||
server.mitm_servers):
|
||||
if debug:
|
||||
print('Queue: _receive_move_activity ' + key_id)
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
except OSError:
|
||||
print('EX: run_inbox_queue 8 unable to receive move ' +
|
||||
str(queue_filename))
|
||||
if queue:
|
||||
queue.pop(0)
|
||||
remove_queue_item = True
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', '_receive_move_activity',
|
||||
debug)
|
||||
|
|
@ -3991,14 +3988,7 @@ def run_inbox_queue(server,
|
|||
server.block_nostr):
|
||||
if debug:
|
||||
print('Queue: Update accepted from ' + key_id)
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
except OSError:
|
||||
print('EX: run_inbox_queue 8 unable to delete ' +
|
||||
str(queue_filename))
|
||||
if queue:
|
||||
queue.pop(0)
|
||||
remove_queue_item = True
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', '_receive_update_activity',
|
||||
debug)
|
||||
|
|
@ -4016,14 +4006,7 @@ def run_inbox_queue(server,
|
|||
if debug:
|
||||
print('Queue: no recipients were resolved ' +
|
||||
'for post arriving in inbox')
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
except OSError:
|
||||
print('EX: run_inbox_queue 9 unable to delete ' +
|
||||
str(queue_filename))
|
||||
if queue:
|
||||
queue.pop(0)
|
||||
remove_queue_item = True
|
||||
continue
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', '_post_recipients',
|
||||
|
|
@ -4131,6 +4114,10 @@ def run_inbox_queue(server,
|
|||
if debug:
|
||||
pprint(curr_post_json)
|
||||
print('Queue: Queue post accepted')
|
||||
remove_queue_item = True
|
||||
|
||||
# should the current queue item be removed?
|
||||
if remove_queue_item:
|
||||
if os.path.isfile(queue_filename):
|
||||
try:
|
||||
os.remove(queue_filename)
|
||||
|
|
|
|||
Loading…
Reference in New Issue