From 0f20a1d12f8f08b83a21811d99750a6c3419fa26 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Thu, 8 Sep 2022 22:20:16 +0200 Subject: [PATCH] Allow to post note with attachments and a CW --- app/admin.py | 15 ++++++++++++++- app/templates/object.html | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/admin.py b/app/admin.py index 55538a8..3a72889 100644 --- a/app/admin.py +++ b/app/admin.py @@ -1021,7 +1021,7 @@ async def admin_actions_unpin( async def admin_actions_new( request: Request, files: list[UploadFile] = [], - content: str = Form(), + content: str | None = Form(None), redirect_url: str = Form(), in_reply_to: str | None = Form(None), content_warning: str | None = Form(None), @@ -1032,6 +1032,19 @@ async def admin_actions_new( csrf_check: None = Depends(verify_csrf_token), db_session: AsyncSession = Depends(get_db_session), ) -> RedirectResponse: + if not content and not content_warning: + raise HTTPException(status_code=422, detail="Error: object must have a content") + + # Do like Mastodon, if there's only a CW with no content and some attachments, + # swap the CW and the content + if not content and content_warning and len(files) >= 1: + content = content_warning + is_sensitive = True + content_warning = None + + if not content: + raise HTTPException(status_code=422, detail="Error: objec must have a content") + # XXX: for some reason, no files restuls in an empty single file uploads = [] raw_form_data = await request.form() diff --git a/app/templates/object.html b/app/templates/object.html index 1d6e519..b6cfa28 100644 --- a/app/templates/object.html +++ b/app/templates/object.html @@ -3,7 +3,11 @@ {% block head %} {% if outbox_object %} -{% set excerpt = outbox_object.content | html2text | trim | truncate(50) %} +{% if outbox_object.content %} + {% set excerpt = outbox_object.content | html2text | trim | truncate(50) %} +{% else %} + {% set excerpt = outbox_object.summary | html2text | trim | truncate(50) %} +{% endif %} {% if outbox_object.name %}{{ outbox_object.name }}{% else %}{{ local_actor.display_name }}: "{{ excerpt }}"{% endif %}