Fix thread display

This commit is contained in:
Thomas Sileo 2019-08-16 22:27:59 +02:00
parent 27ec87a2ef
commit 0edf5f0651
3 changed files with 38 additions and 26 deletions

View file

@ -25,6 +25,9 @@ from config import ID
from config import PASS from config import PASS
from core.activitypub import Box from core.activitypub import Box
from core.activitypub import post_to_outbox from core.activitypub import post_to_outbox
from core.db import find_one_activity
from core.meta import by_object_id
from core.meta import by_type
from core.shared import MY_PERSON from core.shared import MY_PERSON
from core.shared import _build_thread from core.shared import _build_thread
from core.shared import _Response from core.shared import _Response
@ -195,12 +198,11 @@ def admin_lookup() -> _Response:
@blueprint.route("/admin/thread") @blueprint.route("/admin/thread")
@login_required @login_required
def admin_thread() -> _Response: def admin_thread() -> _Response:
data = DB.activities.find_one( oid = request.args.get("oid")
{ if not oid:
"type": ap.ActivityType.CREATE.value, abort(404)
"activity.object.id": request.args.get("oid"),
} data = find_one_activity({**by_type(ap.ActivityType.CREATE), **by_object_id(oid)})
)
if not data: if not data:
abort(404) abort(404)

View file

@ -74,6 +74,10 @@ def not_undo() -> _SubQuery:
return flag(MetaKey.UNDO, False) return flag(MetaKey.UNDO, False)
def not_deleted() -> _SubQuery:
return flag(MetaKey.DELETED, False)
def by_actor(actor: ap.BaseActivity) -> _SubQuery: def by_actor(actor: ap.BaseActivity) -> _SubQuery:
return flag(MetaKey.ACTOR_ID, actor.id) return flag(MetaKey.ACTOR_ID, actor.id)

View file

@ -19,6 +19,11 @@ import config
from config import DB from config import DB
from config import ME from config import ME
from core import activitypub from core import activitypub
from core.db import find_activities
from core.meta import MetaKey
from core.meta import by_type
from core.meta import flag
from core.meta import not_deleted
# _Response = Union[flask.Response, werkzeug.wrappers.Response, str, Any] # _Response = Union[flask.Response, werkzeug.wrappers.Response, str, Any]
_Response = Any _Response = Any
@ -113,29 +118,30 @@ def _get_ip():
def _build_thread(data, include_children=True): # noqa: C901 def _build_thread(data, include_children=True): # noqa: C901
data["_requested"] = True data["_requested"] = True
app.logger.info(f"_build_thread({data!r})") app.logger.info(f"_build_thread({data!r})")
root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"]) root_id = data["meta"][MetaKey.OBJECT_ID.value]
query = {
"$or": [{"meta.thread_root_parent": root_id}, {"activity.object.id": root_id}],
"meta.deleted": False,
}
replies = [data] replies = [data]
for dat in DB.activities.find(query): for dat in find_activities(
print(dat["type"]) {
if dat["type"][0] == ap.ActivityType.CREATE.value: **flag(MetaKey.THREAD_ROOT_PARENT, root_id),
replies.append(dat) **not_deleted(),
if dat["type"][0] == ap.ActivityType.UPDATE.value: **by_type(ap.ActivityType.CREATE),
continue }
else: ):
# Make a Note/Question/... looks like a Create replies.append(dat)
dat = {
"activity": {"object": dat["activity"]},
"meta": dat["meta"],
"_id": dat["_id"],
}
replies.append(dat)
replies = sorted(replies, key=lambda d: d["activity"]["object"]["published"]) for dat in DB.replies.find(
{**flag(MetaKey.THREAD_ROOT_PARENT, root_id), **not_deleted()}
):
# Make a Note/Question/... looks like a Create
dat = {
"activity": {"object": dat["activity"]},
"meta": dat["meta"],
"_id": dat["_id"],
}
replies.append(dat)
replies = sorted(replies, key=lambda d: d["meta"]["published"])
# Index all the IDs in order to build a tree # Index all the IDs in order to build a tree
idx = {} idx = {}