From be682080563518dc3c0351fb9d5be874a2915a41 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 23 Jun 2018 01:04:58 +0200 Subject: [PATCH] Bugfixes --- activitypub.py | 2 +- app.py | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/activitypub.py b/activitypub.py index ae7970b..a167360 100644 --- a/activitypub.py +++ b/activitypub.py @@ -365,7 +365,7 @@ class MicroblogPubBackend(Backend): key to make it easy to query a whole thread.""" in_reply_to = create.get_object().inReplyTo if not in_reply_to: - pass + return new_threads = [] root_reply = in_reply_to diff --git a/app.py b/app.py index 722e16b..ca9448b 100644 --- a/app.py +++ b/app.py @@ -516,29 +516,34 @@ def with_replies(): def _build_thread(data, include_children=True): data["_requested"] = True + print(data) root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"]) - thread_ids = data["meta"].get("thread_parents", []) - if include_children: - thread_ids.extend(data["meta"].get("thread_children", [])) + query = {"$or": [{"meta.thread_root_parent": root_id, "type": "Create"}]} + if data['activity']['object'].get('inReplyTo'): + 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 - 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 idx = {} + replies2 = [] for rep in replies: rep_id = rep["activity"]["object"]["id"] + if rep_id in idx: + continue idx[rep_id] = rep.copy() idx[rep_id]["_nodes"] = [] + replies2.append(rep) # Build the tree - for rep in replies: + for rep in replies2: rep_id = rep["activity"]["object"]["id"] if rep_id == root_id: continue