mirror of https://gitlab.com/bashrc2/epicyon
Avoid circularity in replies resolution
parent
da7150c24c
commit
159e03a782
|
@ -117,7 +117,7 @@ def _get_replies_to_post(post_json_object: {},
|
||||||
signing_priv_key_pem: str,
|
signing_priv_key_pem: str,
|
||||||
session, as_header, debug: bool,
|
session, as_header, debug: bool,
|
||||||
http_prefix: str, domain: str,
|
http_prefix: str, domain: str,
|
||||||
depth: int) -> []:
|
depth: int, ids: []) -> []:
|
||||||
"""Returns a list of reply posts to the given post as json
|
"""Returns a list of reply posts to the given post as json
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
|
@ -243,18 +243,26 @@ def _get_replies_to_post(post_json_object: {},
|
||||||
# render harmless any dangerous markup
|
# render harmless any dangerous markup
|
||||||
harmless_markup(item)
|
harmless_markup(item)
|
||||||
|
|
||||||
|
# keep a list of ids encountered, to avoid circularity
|
||||||
|
reply_post_id = None
|
||||||
|
if item.get('id'):
|
||||||
|
if isinstance(item['id'], str):
|
||||||
|
reply_post_id = item['id']
|
||||||
|
if reply_post_id in ids:
|
||||||
|
continue
|
||||||
|
ids.append(reply_post_id)
|
||||||
|
|
||||||
# add it to the list
|
# add it to the list
|
||||||
result.append(item)
|
result.append(item)
|
||||||
|
|
||||||
if depth < 10 and item.get('id'):
|
if depth < 10 and reply_post_id:
|
||||||
if isinstance(item['id'], str):
|
|
||||||
result += \
|
result += \
|
||||||
_get_replies_to_post(item,
|
_get_replies_to_post(item,
|
||||||
signing_priv_key_pem,
|
signing_priv_key_pem,
|
||||||
session, as_header,
|
session, as_header,
|
||||||
debug,
|
debug,
|
||||||
http_prefix, domain,
|
http_prefix, domain,
|
||||||
depth + 1)
|
depth + 1, ids)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -296,7 +304,7 @@ def download_conversation_posts(authorized: bool, session,
|
||||||
_get_replies_to_post(post_json_object,
|
_get_replies_to_post(post_json_object,
|
||||||
signing_priv_key_pem,
|
signing_priv_key_pem,
|
||||||
session, as_header, debug,
|
session, as_header, debug,
|
||||||
http_prefix, domain, 0)
|
http_prefix, domain, 0, [])
|
||||||
|
|
||||||
while get_json_valid(post_json_object):
|
while get_json_valid(post_json_object):
|
||||||
if not isinstance(post_json_object, dict):
|
if not isinstance(post_json_object, dict):
|
||||||
|
|
Loading…
Reference in New Issue