This commit is contained in:
Thomas Sileo 2018-06-23 01:04:58 +02:00
parent 200c6edc18
commit be68208056
2 changed files with 17 additions and 12 deletions

View file

@ -365,7 +365,7 @@ class MicroblogPubBackend(Backend):
key to make it easy to query a whole thread.""" key to make it easy to query a whole thread."""
in_reply_to = create.get_object().inReplyTo in_reply_to = create.get_object().inReplyTo
if not in_reply_to: if not in_reply_to:
pass return
new_threads = [] new_threads = []
root_reply = in_reply_to root_reply = in_reply_to

27
app.py
View file

@ -516,29 +516,34 @@ def with_replies():
def _build_thread(data, include_children=True): def _build_thread(data, include_children=True):
data["_requested"] = True data["_requested"] = True
print(data)
root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"]) root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"])
thread_ids = data["meta"].get("thread_parents", []) query = {"$or": [{"meta.thread_root_parent": root_id, "type": "Create"}]}
if include_children: if data['activity']['object'].get('inReplyTo'):
thread_ids.extend(data["meta"].get("thread_children", [])) query['$or'].append({'activity.object.id': data['activity']['object']['inReplyTo']})
query = {
"activity.object.id": {"$in": thread_ids},
"type": "Create",
"meta.deleted": False, # TODO(tsileo): handle Tombstone instead of filtering them
}
# Fetch the root replies, and the children # Fetch the root replies, and the children
replies = [data] + list(DB.inbox.find(query)) + list(DB.outbox.find(query)) replies = (
[data]
+ list(DB.inbox.find(query))
+ list(DB.outbox.find(query))
+ list(DB.threads.find(query))
)
replies = sorted(replies, key=lambda d: d["activity"]["object"]["published"])
# Index all the IDs in order to build a tree # Index all the IDs in order to build a tree
idx = {} idx = {}
replies2 = []
for rep in replies: for rep in replies:
rep_id = rep["activity"]["object"]["id"] rep_id = rep["activity"]["object"]["id"]
if rep_id in idx:
continue
idx[rep_id] = rep.copy() idx[rep_id] = rep.copy()
idx[rep_id]["_nodes"] = [] idx[rep_id]["_nodes"] = []
replies2.append(rep)
# Build the tree # Build the tree
for rep in replies: for rep in replies2:
rep_id = rep["activity"]["object"]["id"] rep_id = rep["activity"]["object"]["id"]
if rep_id == root_id: if rep_id == root_id:
continue continue