forked from forks/microblog.pub
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 ID
|
||||||
from config import PASS
|
from config import PASS
|
||||||
from core.activitypub import Box
|
from core.activitypub import Box
|
||||||
|
from core.activitypub import _meta
|
||||||
from core.activitypub import post_to_outbox
|
from core.activitypub import post_to_outbox
|
||||||
from core.db import find_one_activity
|
from core.db import find_one_activity
|
||||||
from core.meta import by_object_id
|
from core.meta import by_object_id
|
||||||
|
@ -193,14 +194,8 @@ def admin_lookup() -> _Response:
|
||||||
if request.args.get("url"):
|
if request.args.get("url"):
|
||||||
data = lookup(request.args.get("url")) # type: ignore
|
data = lookup(request.args.get("url")) # type: ignore
|
||||||
if data:
|
if data:
|
||||||
if data.has_type(ap.ActivityType.ANNOUNCE):
|
meta = _meta(data)
|
||||||
meta = dict(
|
if data.has_type(ap.ActivityType.QUESTION):
|
||||||
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):
|
|
||||||
p.push(data.id, "/task/fetch_remote_question")
|
p.push(data.id, "/task/fetch_remote_question")
|
||||||
|
|
||||||
print(data)
|
print(data)
|
||||||
|
@ -302,12 +297,10 @@ def admin_new() -> _Response:
|
||||||
if data:
|
if data:
|
||||||
reply = ap.parse_activity(data["activity"])
|
reply = ap.parse_activity(data["activity"])
|
||||||
else:
|
else:
|
||||||
data = dict(
|
obj = ap.get_backend().fetch_iri(request.args.get("reply"))
|
||||||
meta={},
|
data = dict(meta=_meta(ap.parse_activity(obj)), activity=dict(object=obj))
|
||||||
activity=dict(
|
data["_id"] = obj["id"]
|
||||||
object=ap.get_backend().fetch_iri(request.args.get("reply"))
|
data["remote_id"] = obj["id"]
|
||||||
),
|
|
||||||
)
|
|
||||||
reply = ap.parse_activity(data["activity"]["object"])
|
reply = ap.parse_activity(data["activity"]["object"])
|
||||||
# Fetch the post visibility, in case it's follower only
|
# Fetch the post visibility, in case it's follower only
|
||||||
default_visibility = ap.get_visibility(reply)
|
default_visibility = ap.get_visibility(reply)
|
||||||
|
|
|
@ -113,8 +113,7 @@ def _is_local_reply(create: ap.Create) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def save(box: Box, activity: ap.BaseActivity) -> None:
|
def _meta(activity: ap.BaseActivity) -> _NewMeta:
|
||||||
"""Custom helper for saving an activity to the DB."""
|
|
||||||
visibility = ap.get_visibility(activity)
|
visibility = ap.get_visibility(activity)
|
||||||
is_public = False
|
is_public = False
|
||||||
if visibility in [ap.Visibility.PUBLIC, ap.Visibility.UNLISTED]:
|
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
|
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
|
# Set some "type"-related neta
|
||||||
extra: Dict[str, Any] = {}
|
meta = _meta(activity)
|
||||||
if box == Box.OUTBOX and activity.has_type(ap.ActivityType.FOLLOW):
|
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):
|
elif activity.has_type(ap.ActivityType.CREATE):
|
||||||
mentions = []
|
mentions = []
|
||||||
obj = activity.get_object()
|
obj = activity.get_object()
|
||||||
|
@ -146,7 +161,7 @@ def save(box: Box, activity: ap.BaseActivity) -> None:
|
||||||
hashtags = []
|
hashtags = []
|
||||||
for h in obj.get_hashtags():
|
for h in obj.get_hashtags():
|
||||||
hashtags.append(h.name[1:]) # Strip the #
|
hashtags.append(h.name[1:]) # Strip the #
|
||||||
extra.update(
|
meta.update(
|
||||||
{MetaKey.MENTIONS.value: mentions, MetaKey.HASHTAGS.value: hashtags}
|
{MetaKey.MENTIONS.value: mentions, MetaKey.HASHTAGS.value: hashtags}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -156,21 +171,7 @@ def save(box: Box, activity: ap.BaseActivity) -> None:
|
||||||
"activity": activity.to_dict(),
|
"activity": activity.to_dict(),
|
||||||
"type": _to_list(activity.type),
|
"type": _to_list(activity.type),
|
||||||
"remote_id": activity.id,
|
"remote_id": activity.id,
|
||||||
"meta": {
|
"meta": 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,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ from typing import Union
|
||||||
from little_boxes import activitypub as ap
|
from little_boxes import activitypub as ap
|
||||||
|
|
||||||
_SubQuery = Dict[str, Any]
|
_SubQuery = Dict[str, Any]
|
||||||
|
_Meta = Dict["MetaKey", Any]
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
|
|
|
@ -21,6 +21,7 @@ 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.activitypub import _meta
|
||||||
from core.db import find_activities
|
from core.db import find_activities
|
||||||
from core.meta import MetaKey
|
from core.meta import MetaKey
|
||||||
from core.meta import by_object_id
|
from core.meta import by_object_id
|
||||||
|
@ -145,10 +146,11 @@ def _build_thread(data, include_children=True, query=None): # noqa: C901
|
||||||
query = {}
|
query = {}
|
||||||
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(
|
root_id = data["meta"].get(MetaKey.THREAD_ROOT_PARENT.value)
|
||||||
MetaKey.THREAD_ROOT_PARENT.value,
|
if not root_id:
|
||||||
data["meta"].get(MetaKey.OBJECT_ID.value, data["meta"].get("remote_id")),
|
root_id = data["meta"].get(MetaKey.OBJECT_ID.value)
|
||||||
)
|
if not root_id:
|
||||||
|
root_id = data["remote_id"]
|
||||||
|
|
||||||
replies = [data]
|
replies = [data]
|
||||||
for dat in find_activities(
|
for dat in find_activities(
|
||||||
|
|
|
@ -28,15 +28,15 @@
|
||||||
{{ utils.display_actor_inline(data, size=80) }}
|
{{ utils.display_actor_inline(data, size=80) }}
|
||||||
|
|
||||||
{% elif data | has_type('Create') %}
|
{% 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']) %}
|
{% 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') %}
|
{% elif data | has_type('Announce') %}
|
||||||
{% set boost_actor = meta.actor %}
|
{% set boost_actor = meta.actor %}
|
||||||
<p style="margin-left:65px;padding-bottom:5px;">
|
<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>
|
<span class="bar-item-no-hover"><a style="color:#808080;" href="{{ boost_actor.url | get_url }}">{{ boost_actor.name }}</a> boosted</span>
|
||||||
</p>
|
</p>
|
||||||
{{ utils.display_note(meta.object) }}
|
{{ utils.display_note(meta.object, meta=meta) }}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue