Fix lookup for remote activities
This commit is contained in:
@@ -113,8 +113,7 @@ def _is_local_reply(create: ap.Create) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def save(box: Box, activity: ap.BaseActivity) -> None:
|
||||
"""Custom helper for saving an activity to the DB."""
|
||||
def _meta(activity: ap.BaseActivity) -> _NewMeta:
|
||||
visibility = ap.get_visibility(activity)
|
||||
is_public = False
|
||||
if visibility in [ap.Visibility.PUBLIC, ap.Visibility.UNLISTED]:
|
||||
@@ -134,10 +133,26 @@ def save(box: Box, activity: ap.BaseActivity) -> None:
|
||||
|
||||
actor_id = activity.get_actor().id
|
||||
|
||||
return {
|
||||
MetaKey.UNDO.value: False,
|
||||
MetaKey.DELETED.value: False,
|
||||
MetaKey.PUBLIC.value: is_public,
|
||||
MetaKey.SERVER.value: urlparse(activity.id).netloc,
|
||||
MetaKey.VISIBILITY.value: visibility.name,
|
||||
MetaKey.ACTOR_ID.value: actor_id,
|
||||
MetaKey.OBJECT_ID.value: object_id,
|
||||
MetaKey.OBJECT_VISIBILITY.value: object_visibility,
|
||||
MetaKey.POLL_ANSWER.value: False,
|
||||
MetaKey.PUBLISHED.value: activity.published if activity.published else now(),
|
||||
}
|
||||
|
||||
|
||||
def save(box: Box, activity: ap.BaseActivity) -> None:
|
||||
"""Custom helper for saving an activity to the DB."""
|
||||
# Set some "type"-related neta
|
||||
extra: Dict[str, Any] = {}
|
||||
meta = _meta(activity)
|
||||
if box == Box.OUTBOX and activity.has_type(ap.ActivityType.FOLLOW):
|
||||
extra[MetaKey.FOLLOW_STATUS.value] = FollowStatus.WAITING.value
|
||||
meta[MetaKey.FOLLOW_STATUS.value] = FollowStatus.WAITING.value
|
||||
elif activity.has_type(ap.ActivityType.CREATE):
|
||||
mentions = []
|
||||
obj = activity.get_object()
|
||||
@@ -146,7 +161,7 @@ def save(box: Box, activity: ap.BaseActivity) -> None:
|
||||
hashtags = []
|
||||
for h in obj.get_hashtags():
|
||||
hashtags.append(h.name[1:]) # Strip the #
|
||||
extra.update(
|
||||
meta.update(
|
||||
{MetaKey.MENTIONS.value: mentions, MetaKey.HASHTAGS.value: hashtags}
|
||||
)
|
||||
|
||||
@@ -156,21 +171,7 @@ def save(box: Box, activity: ap.BaseActivity) -> None:
|
||||
"activity": activity.to_dict(),
|
||||
"type": _to_list(activity.type),
|
||||
"remote_id": activity.id,
|
||||
"meta": {
|
||||
MetaKey.UNDO.value: False,
|
||||
MetaKey.DELETED.value: False,
|
||||
MetaKey.PUBLIC.value: is_public,
|
||||
MetaKey.SERVER.value: urlparse(activity.id).netloc,
|
||||
MetaKey.VISIBILITY.value: visibility.name,
|
||||
MetaKey.ACTOR_ID.value: actor_id,
|
||||
MetaKey.OBJECT_ID.value: object_id,
|
||||
MetaKey.OBJECT_VISIBILITY.value: object_visibility,
|
||||
MetaKey.POLL_ANSWER.value: False,
|
||||
MetaKey.PUBLISHED.value: activity.published
|
||||
if activity.published
|
||||
else now(),
|
||||
**extra,
|
||||
},
|
||||
"meta": meta,
|
||||
}
|
||||
)
|
||||
|
||||
|
@@ -9,6 +9,7 @@ from typing import Union
|
||||
from little_boxes import activitypub as ap
|
||||
|
||||
_SubQuery = Dict[str, Any]
|
||||
_Meta = Dict["MetaKey", Any]
|
||||
|
||||
|
||||
@unique
|
||||
|
@@ -21,6 +21,7 @@ import config
|
||||
from config import DB
|
||||
from config import ME
|
||||
from core import activitypub
|
||||
from core.activitypub import _meta
|
||||
from core.db import find_activities
|
||||
from core.meta import MetaKey
|
||||
from core.meta import by_object_id
|
||||
@@ -145,10 +146,11 @@ def _build_thread(data, include_children=True, query=None): # noqa: C901
|
||||
query = {}
|
||||
data["_requested"] = True
|
||||
app.logger.info(f"_build_thread({data!r})")
|
||||
root_id = data["meta"].get(
|
||||
MetaKey.THREAD_ROOT_PARENT.value,
|
||||
data["meta"].get(MetaKey.OBJECT_ID.value, data["meta"].get("remote_id")),
|
||||
)
|
||||
root_id = data["meta"].get(MetaKey.THREAD_ROOT_PARENT.value)
|
||||
if not root_id:
|
||||
root_id = data["meta"].get(MetaKey.OBJECT_ID.value)
|
||||
if not root_id:
|
||||
root_id = data["remote_id"]
|
||||
|
||||
replies = [data]
|
||||
for dat in find_activities(
|
||||
|
Reference in New Issue
Block a user