mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 13:14:28 +00:00
Improve admin actor profile
This commit is contained in:
parent
4cbfb396c6
commit
7782a39638
4 changed files with 33 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import typing
|
import typing
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from functools import cached_property
|
||||||
from typing import Union
|
from typing import Union
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
@ -66,8 +67,8 @@ class Actor:
|
||||||
return self.ap_actor["inbox"]
|
return self.ap_actor["inbox"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def shared_inbox_url(self) -> str | None:
|
def shared_inbox_url(self) -> str:
|
||||||
return self.ap_actor.get("endpoints", {}).get("sharedInbox")
|
return self.ap_actor.get("endpoints", {}).get("sharedInbox") or self.inbox_url
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon_url(self) -> str | None:
|
def icon_url(self) -> str | None:
|
||||||
|
@ -107,6 +108,10 @@ class Actor:
|
||||||
def followers_collection_id(self) -> str | None:
|
def followers_collection_id(self) -> str | None:
|
||||||
return self.ap_actor.get("followers")
|
return self.ap_actor.get("followers")
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def attachments(self) -> list[ap.RawObject]:
|
||||||
|
return ap.as_list(self.ap_actor.get("attachment", []))
|
||||||
|
|
||||||
|
|
||||||
class RemoteActor(Actor):
|
class RemoteActor(Actor):
|
||||||
def __init__(self, ap_actor: ap.RawObject) -> None:
|
def __init__(self, ap_actor: ap.RawObject) -> None:
|
||||||
|
|
10
app/boxes.py
10
app/boxes.py
|
@ -577,7 +577,7 @@ async def _compute_recipients(
|
||||||
# If we got a local collection, assume it's a collection of actors
|
# If we got a local collection, assume it's a collection of actors
|
||||||
if r.startswith(BASE_URL):
|
if r.startswith(BASE_URL):
|
||||||
for actor in await fetch_actor_collection(db_session, r):
|
for actor in await fetch_actor_collection(db_session, r):
|
||||||
recipients.add(actor.shared_inbox_url or actor.inbox_url)
|
recipients.add(actor.shared_inbox_url)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -588,19 +588,19 @@ async def _compute_recipients(
|
||||||
)
|
)
|
||||||
).scalar_one_or_none() # type: ignore
|
).scalar_one_or_none() # type: ignore
|
||||||
if known_actor:
|
if known_actor:
|
||||||
recipients.add(known_actor.shared_inbox_url or known_actor.inbox_url)
|
recipients.add(known_actor.shared_inbox_url)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Fetch the object
|
# Fetch the object
|
||||||
raw_object = await ap.fetch(r)
|
raw_object = await ap.fetch(r)
|
||||||
if raw_object.get("type") in ap.ACTOR_TYPES:
|
if raw_object.get("type") in ap.ACTOR_TYPES:
|
||||||
saved_actor = await save_actor(db_session, raw_object)
|
saved_actor = await save_actor(db_session, raw_object)
|
||||||
recipients.add(saved_actor.shared_inbox_url or saved_actor.inbox_url)
|
recipients.add(saved_actor.shared_inbox_url)
|
||||||
else:
|
else:
|
||||||
# Assume it's a collection of actors
|
# Assume it's a collection of actors
|
||||||
for raw_actor in await ap.parse_collection(payload=raw_object):
|
for raw_actor in await ap.parse_collection(payload=raw_object):
|
||||||
actor = RemoteActor(raw_actor)
|
actor = RemoteActor(raw_actor)
|
||||||
recipients.add(actor.shared_inbox_url or actor.inbox_url)
|
recipients.add(actor.shared_inbox_url)
|
||||||
|
|
||||||
return recipients
|
return recipients
|
||||||
|
|
||||||
|
@ -640,7 +640,7 @@ async def _get_followers_recipients(
|
||||||
|
|
||||||
followers = await _get_followers(db_session)
|
followers = await _get_followers(db_session)
|
||||||
return {
|
return {
|
||||||
follower.actor.shared_inbox_url or follower.actor.inbox_url # type: ignore
|
follower.actor.shared_inbox_url # type: ignore
|
||||||
for follower in followers
|
for follower in followers
|
||||||
if follower.actor.ap_id not in actor_ap_ids_to_skip
|
if follower.actor.ap_id not in actor_ap_ids_to_skip
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,6 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac
|
||||||
# TODO(ts):
|
# TODO(ts):
|
||||||
#
|
#
|
||||||
# Next:
|
# Next:
|
||||||
# - share nginx config in doc
|
|
||||||
# - prevent double accept/double follow
|
# - prevent double accept/double follow
|
||||||
# - UI support for updating posts
|
# - UI support for updating posts
|
||||||
# - indieauth tweaks
|
# - indieauth tweaks
|
||||||
|
|
|
@ -196,13 +196,6 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if with_details and actor.summary %}
|
|
||||||
<div class="p-note">
|
|
||||||
{{ actor.summary | clean_html(actor) | safe }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
{% if is_admin and metadata %}
|
{% if is_admin and metadata %}
|
||||||
<div>
|
<div>
|
||||||
<nav class="flexbox actor-metadata">
|
<nav class="flexbox actor-metadata">
|
||||||
|
@ -229,6 +222,27 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if with_details %}
|
||||||
|
{% if actor.summary %}
|
||||||
|
<div class="p-note">
|
||||||
|
{{ actor.summary | clean_html(actor) | safe }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if actor.attachments %}
|
||||||
|
<div id="profile-props">
|
||||||
|
<dl>
|
||||||
|
{% for prop in actor.attachments %}
|
||||||
|
{% if prop.type == "PropertyValue" %}
|
||||||
|
<dt>{{ prop.name }}</dt>
|
||||||
|
<dd>{{ prop.value | clean_html(actor) | safe }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if not embedded %}
|
{% if not embedded %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue