mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 05:04:27 +00:00
Improve movedTo support
This commit is contained in:
parent
eba868e8e5
commit
3641aa0adc
4 changed files with 28 additions and 3 deletions
|
@ -34,6 +34,7 @@ AS_EXTENDED_CTX = [
|
||||||
"sensitive": "as:sensitive",
|
"sensitive": "as:sensitive",
|
||||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
"alsoKnownAs": {"@id": "as:alsoKnownAs", "@type": "@id"},
|
"alsoKnownAs": {"@id": "as:alsoKnownAs", "@type": "@id"},
|
||||||
|
"movedTo": {"@id": "as:movedTo", "@type": "@id"},
|
||||||
# toot
|
# toot
|
||||||
"toot": "http://joinmastodon.org/ns#",
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
"featured": {"@id": "toot:featured", "@type": "@id"},
|
"featured": {"@id": "toot:featured", "@type": "@id"},
|
||||||
|
|
20
app/actor.py
20
app/actor.py
|
@ -5,6 +5,7 @@ from functools import cached_property
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
|
@ -118,6 +119,10 @@ class Actor:
|
||||||
def attachments(self) -> list[ap.RawObject]:
|
def attachments(self) -> list[ap.RawObject]:
|
||||||
return ap.as_list(self.ap_actor.get("attachment", []))
|
return ap.as_list(self.ap_actor.get("attachment", []))
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def moved_to(self) -> str | None:
|
||||||
|
return self.ap_actor.get("movedTo")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def server(self) -> str:
|
def server(self) -> str:
|
||||||
return urlparse(self.ap_id).hostname # type: ignore
|
return urlparse(self.ap_id).hostname # type: ignore
|
||||||
|
@ -214,6 +219,7 @@ class ActorMetadata:
|
||||||
is_follow_request_sent: bool
|
is_follow_request_sent: bool
|
||||||
outbox_follow_ap_id: str | None
|
outbox_follow_ap_id: str | None
|
||||||
inbox_follow_ap_id: str | None
|
inbox_follow_ap_id: str | None
|
||||||
|
moved_to: typing.Optional["ActorModel"]
|
||||||
|
|
||||||
|
|
||||||
ActorsMetadata = dict[str, ActorMetadata]
|
ActorsMetadata = dict[str, ActorMetadata]
|
||||||
|
@ -260,6 +266,19 @@ async def get_actors_metadata(
|
||||||
for actor in actors:
|
for actor in actors:
|
||||||
if not actor.ap_id:
|
if not actor.ap_id:
|
||||||
raise ValueError("Should never happen")
|
raise ValueError("Should never happen")
|
||||||
|
moved_to = None
|
||||||
|
if actor.moved_to:
|
||||||
|
try:
|
||||||
|
moved_to = await fetch_actor(
|
||||||
|
db_session,
|
||||||
|
actor.moved_to,
|
||||||
|
save_if_not_found=False,
|
||||||
|
)
|
||||||
|
except ap.ObjectNotFoundError:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
logger.exception(f"Failed to fetch {actor.moved_to=}")
|
||||||
|
|
||||||
idx[actor.ap_id] = ActorMetadata(
|
idx[actor.ap_id] = ActorMetadata(
|
||||||
ap_actor_id=actor.ap_id,
|
ap_actor_id=actor.ap_id,
|
||||||
is_following=actor.ap_id in following,
|
is_following=actor.ap_id in following,
|
||||||
|
@ -267,6 +286,7 @@ async def get_actors_metadata(
|
||||||
is_follow_request_sent=actor.ap_id in sent_follow_requests,
|
is_follow_request_sent=actor.ap_id in sent_follow_requests,
|
||||||
outbox_follow_ap_id=sent_follow_requests.get(actor.ap_id),
|
outbox_follow_ap_id=sent_follow_requests.get(actor.ap_id),
|
||||||
inbox_follow_ap_id=followers.get(actor.ap_id),
|
inbox_follow_ap_id=followers.get(actor.ap_id),
|
||||||
|
moved_to=moved_to,
|
||||||
)
|
)
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
|
|
|
@ -908,7 +908,7 @@ async def _handle_delete_activity(
|
||||||
except ap.ObjectNotFoundError:
|
except ap.ObjectNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if ap_object_to_delete is None:
|
if ap_object_to_delete is None or not ap_object_to_delete.is_from_db:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Received Delete for an unknown object "
|
"Received Delete for an unknown object "
|
||||||
f"{delete_activity.activity_object_ap_id}"
|
f"{delete_activity.activity_object_ap_id}"
|
||||||
|
|
|
@ -223,7 +223,7 @@
|
||||||
{% elif metadata.is_follow_request_sent %}
|
{% elif metadata.is_follow_request_sent %}
|
||||||
<li>follow request sent</li>
|
<li>follow request sent</li>
|
||||||
<li>{{ admin_undo_button(metadata.outbox_follow_ap_id, "undo follow") }}</li>
|
<li>{{ admin_undo_button(metadata.outbox_follow_ap_id, "undo follow") }}</li>
|
||||||
{% else %}
|
{% elif not actor.moved_to %}
|
||||||
<li>{{ admin_follow_button(actor) }}</li>
|
<li>{{ admin_follow_button(actor) }}</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if metadata.is_follower %}
|
{% if metadata.is_follower %}
|
||||||
|
@ -231,7 +231,11 @@
|
||||||
{% if not metadata.is_following and not with_details %}
|
{% if not metadata.is_following and not with_details %}
|
||||||
<li>{{ admin_profile_button(actor.ap_id) }}</li>
|
<li>{{ admin_profile_button(actor.ap_id) }}</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
{$ elif actor.is_from_db and not with_details %}
|
||||||
|
<li>{{ admin_profile_button(actor.ap_id) }}</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if actor.moved_to %}
|
||||||
|
<li>has moved to {% if metadata.moved_to %}<a href="{{ url_for("admin_profile") }}?actor_id={{ actor.moved_to }}">{{ metadata.moved_to.handle }}</a>{% else %}<a href="{{ url_for("get_lookup") }}?query={{ actor.moved_to }}">{{ actor.moved_to }}</a>{% endif %}</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if actor.is_from_db %}
|
{% if actor.is_from_db %}
|
||||||
{% if actor.is_blocked %}
|
{% if actor.is_blocked %}
|
||||||
|
|
Loading…
Reference in a new issue