Example #1
0
async def get_content_replies(parent: str, parent_permlink: str):
    """Get a list of post objects based on parent."""
    valid_account(parent)
    valid_permlink(parent_permlink)
    parent_id = get_post_id(parent, parent_permlink)
    if parent_id:
        child_ids = get_child_ids(parent_id)
        if child_ids:
            return load_posts(child_ids)
    return []
Example #2
0
def _load_posts_recursive(post_ids):
    """Recursively load a discussion thread."""
    assert post_ids, 'no posts provided'

    out = {}
    for post in load_posts(post_ids):
        out[_ref(post)] = post

        child_ids = get_child_ids(post['post_id'])
        if child_ids:
            children = _load_posts_recursive(child_ids)
            post['replies'] = list(children.keys())
            out = {**out, **children}

    return out
Example #3
0
def _load_discussion(author, permlink):
    """Load a full discussion thread."""
    post_id = get_post_id(author, permlink)
    if not post_id:
        return {}

    ret = []
    queue = load_posts([post_id])
    while queue:
        parent = queue.pop()

        children = load_posts(get_child_ids(parent['post_id']))
        parent['replies'] = list(map(_ref, children))

        queue.extend(children)
        ret.append(parent)

    return {_ref(post): post for post in ret}