mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 05:04:27 +00:00
Fix lookup for remote activities
This commit is contained in:
parent
83b683ecf2
commit
2836959d92
5 changed files with 38 additions and 41 deletions
|
@ -24,6 +24,7 @@ from config import DB
|
|||
from config import ID
|
||||
from config import PASS
|
||||
from core.activitypub import Box
|
||||
from core.activitypub import _meta
|
||||
from core.activitypub import post_to_outbox
|
||||
from core.db import find_one_activity
|
||||
from core.meta import by_object_id
|
||||
|
@ -193,14 +194,8 @@ def admin_lookup() -> _Response:
|
|||
if request.args.get("url"):
|
||||
data = lookup(request.args.get("url")) # type: ignore
|
||||
if data:
|
||||
if data.has_type(ap.ActivityType.ANNOUNCE):
|
||||
meta = dict(
|
||||
object=data.get_object().to_dict(),
|
||||
object_actor=data.get_object().get_actor().to_dict(),
|
||||
actor=data.get_actor().to_dict(),
|
||||
)
|
||||
|
||||
elif data.has_type(ap.ActivityType.QUESTION):
|
||||
meta = _meta(data)
|
||||
if data.has_type(ap.ActivityType.QUESTION):
|
||||
p.push(data.id, "/task/fetch_remote_question")
|
||||
|
||||
print(data)
|
||||
|
@ -302,12 +297,10 @@ def admin_new() -> _Response:
|
|||
if data:
|
||||
reply = ap.parse_activity(data["activity"])
|
||||
else:
|
||||
data = dict(
|
||||
meta={},
|
||||
activity=dict(
|
||||
object=ap.get_backend().fetch_iri(request.args.get("reply"))
|
||||
),
|
||||
)
|
||||
obj = ap.get_backend().fetch_iri(request.args.get("reply"))
|
||||
data = dict(meta=_meta(ap.parse_activity(obj)), activity=dict(object=obj))
|
||||
data["_id"] = obj["id"]
|
||||
data["remote_id"] = obj["id"]
|
||||
reply = ap.parse_activity(data["activity"]["object"])
|
||||
# Fetch the post visibility, in case it's follower only
|
||||
default_visibility = ap.get_visibility(reply)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -28,15 +28,15 @@
|
|||
{{ utils.display_actor_inline(data, size=80) }}
|
||||
|
||||
{% elif data | has_type('Create') %}
|
||||
{{ utils.display_note(data.object) }}
|
||||
{{ utils.display_note(data.object, meta=meta) }}
|
||||
{% elif data | has_type(['Note', 'Article', 'Video', 'Audio', 'Page', 'Question']) %}
|
||||
{{ utils.display_note(data) }}
|
||||
{{ utils.display_note(data, meta=meta) }}
|
||||
{% elif data | has_type('Announce') %}
|
||||
{% set boost_actor = meta.actor %}
|
||||
<p style="margin-left:65px;padding-bottom:5px;">
|
||||
<span class="bar-item-no-hover"><a style="color:#808080;" href="{{ boost_actor.url | get_url }}">{{ boost_actor.name }}</a> boosted</span>
|
||||
</p>
|
||||
{{ utils.display_note(meta.object) }}
|
||||
{{ utils.display_note(meta.object, meta=meta) }}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue