Show in reply to admin button

main
Thomas Sileo 2022-07-07 08:36:07 +02:00
parent ad62b79da9
commit d058c1ba26
5 changed files with 40 additions and 6 deletions

View File

@ -76,10 +76,23 @@ async def get_lookup(
request: Request, request: Request,
query: str | None = None, query: str | None = None,
db_session: AsyncSession = Depends(get_db_session), db_session: AsyncSession = Depends(get_db_session),
) -> templates.TemplateResponse: ) -> templates.TemplateResponse | RedirectResponse:
ap_object = None ap_object = None
actors_metadata = {} actors_metadata = {}
if query: if query:
requested_object = await boxes.get_anybox_object_by_ap_id(db_session, query)
if requested_object:
if (
requested_object.ap_type == "Create"
and requested_object.relates_to_anybox_object
):
query = requested_object.relates_to_anybox_object.ap_id
return RedirectResponse(
request.url_for("admin_object") + f"?ap_id={query}",
status_code=302,
)
# TODO(ts): redirect to admin_profile if the actor is in DB
ap_object = await lookup(db_session, query) ap_object = await lookup(db_session, query)
if ap_object.ap_type in ap.ACTOR_TYPES: if ap_object.ap_type in ap.ACTOR_TYPES:
actors_metadata = await get_actors_metadata( actors_metadata = await get_actors_metadata(
@ -266,7 +279,7 @@ async def admin_outbox(
cursor: str | None = None, cursor: str | None = None,
) -> templates.TemplateResponse: ) -> templates.TemplateResponse:
where = [ where = [
models.OutboxObject.ap_type.not_in(["Accept", "Delete"]), models.OutboxObject.ap_type.not_in(["Accept", "Delete", "Update"]),
models.OutboxObject.is_deleted.is_(False), models.OutboxObject.is_deleted.is_(False),
] ]
if filter_by: if filter_by:

View File

@ -455,7 +455,21 @@ async def get_outbox_object_by_ap_id(
) -> models.OutboxObject | None: ) -> models.OutboxObject | None:
return ( return (
await db_session.execute( await db_session.execute(
select(models.OutboxObject).where(models.OutboxObject.ap_id == ap_id) select(models.OutboxObject)
.where(models.OutboxObject.ap_id == ap_id)
.options(
joinedload(models.OutboxObject.outbox_object_attachments).options(
joinedload(models.OutboxObjectAttachment.upload)
),
joinedload(models.OutboxObject.relates_to_inbox_object).options(
joinedload(models.InboxObject.actor),
),
joinedload(models.OutboxObject.relates_to_outbox_object).options(
joinedload(models.OutboxObject.outbox_object_attachments).options(
joinedload(models.OutboxObjectAttachment.upload)
),
),
)
) )
).scalar_one_or_none() # type: ignore ).scalar_one_or_none() # type: ignore

View File

@ -64,9 +64,8 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac
# TODO(ts): # TODO(ts):
# #
# Next: # Next:
# - [ ] show [reply to @truc] next to visiblity
# - support update post with history # - support update post with history
# - update actor support
# - hash config/profile to detect when to send Update actor
# #
# - [ ] block support # - [ ] block support
# - [ ] prevent SSRF (urlutils from little-boxes) # - [ ] prevent SSRF (urlutils from little-boxes)

View File

@ -162,7 +162,7 @@ class OutboxObject(Base, BaseObject):
# Never actually delete from the outbox # Never actually delete from the outbox
is_deleted = Column(Boolean, nullable=False, default=False) is_deleted = Column(Boolean, nullable=False, default=False)
# Used for Like, Announce and Undo activities # Used for Create, Like, Announce and Undo activities
relates_to_inbox_object_id = Column( relates_to_inbox_object_id = Column(
Integer, Integer,
ForeignKey("inbox.id"), ForeignKey("inbox.id"),

View File

@ -332,6 +332,14 @@
<nav class="flexbox activity-bar"> <nav class="flexbox activity-bar">
<ul> <ul>
{% if object.in_reply_to and is_admin %}
<li>
<a href="{{ url_for("get_lookup") }}?query={{ object.in_reply_to }}" title="{{ object.in_reply_to }}">in reply to {{ object.in_reply_to|truncate(16, True) }}</a>
</li>
{% endif %}
{% if not is_admin or object.is_from_outbox %}<li><div><a href="{{ object.url }}"{% if object.is_from_inbox %} rel="nofollow"{% endif %}>permalink</a></div></li>{% endif %} {% if not is_admin or object.is_from_outbox %}<li><div><a href="{{ object.url }}"{% if object.is_from_inbox %} rel="nofollow"{% endif %}>permalink</a></div></li>{% endif %}
{% if object.is_from_outbox %} {% if object.is_from_outbox %}
{% if object.likes_count %} {% if object.likes_count %}