mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 05:04:27 +00:00
Fix thread display
This commit is contained in:
parent
27ec87a2ef
commit
0edf5f0651
3 changed files with 38 additions and 26 deletions
|
@ -25,6 +25,9 @@ from config import ID
|
|||
from config import PASS
|
||||
from core.activitypub import Box
|
||||
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 _build_thread
|
||||
from core.shared import _Response
|
||||
|
@ -195,12 +198,11 @@ def admin_lookup() -> _Response:
|
|||
@blueprint.route("/admin/thread")
|
||||
@login_required
|
||||
def admin_thread() -> _Response:
|
||||
data = DB.activities.find_one(
|
||||
{
|
||||
"type": ap.ActivityType.CREATE.value,
|
||||
"activity.object.id": request.args.get("oid"),
|
||||
}
|
||||
)
|
||||
oid = request.args.get("oid")
|
||||
if not oid:
|
||||
abort(404)
|
||||
|
||||
data = find_one_activity({**by_type(ap.ActivityType.CREATE), **by_object_id(oid)})
|
||||
|
||||
if not data:
|
||||
abort(404)
|
||||
|
|
|
@ -74,6 +74,10 @@ def not_undo() -> _SubQuery:
|
|||
return flag(MetaKey.UNDO, False)
|
||||
|
||||
|
||||
def not_deleted() -> _SubQuery:
|
||||
return flag(MetaKey.DELETED, False)
|
||||
|
||||
|
||||
def by_actor(actor: ap.BaseActivity) -> _SubQuery:
|
||||
return flag(MetaKey.ACTOR_ID, actor.id)
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@ import config
|
|||
from config import DB
|
||||
from config import ME
|
||||
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 = Any
|
||||
|
@ -113,29 +118,30 @@ def _get_ip():
|
|||
def _build_thread(data, include_children=True): # noqa: C901
|
||||
data["_requested"] = True
|
||||
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]
|
||||
for dat in DB.activities.find(query):
|
||||
print(dat["type"])
|
||||
if dat["type"][0] == ap.ActivityType.CREATE.value:
|
||||
replies.append(dat)
|
||||
if dat["type"][0] == ap.ActivityType.UPDATE.value:
|
||||
continue
|
||||
else:
|
||||
# Make a Note/Question/... looks like a Create
|
||||
dat = {
|
||||
"activity": {"object": dat["activity"]},
|
||||
"meta": dat["meta"],
|
||||
"_id": dat["_id"],
|
||||
}
|
||||
replies.append(dat)
|
||||
for dat in find_activities(
|
||||
{
|
||||
**flag(MetaKey.THREAD_ROOT_PARENT, root_id),
|
||||
**not_deleted(),
|
||||
**by_type(ap.ActivityType.CREATE),
|
||||
}
|
||||
):
|
||||
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
|
||||
idx = {}
|
||||
|
|
Loading…
Reference in a new issue