From d32a686eb1b7daecc7ed11ad77a93e73e7a3230c Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 26 Dec 2022 10:03:13 -0700 Subject: [PATCH] Persist CWs in replies, expand linked at once Fixes #268 --- activities/models/post.py | 10 +++++++++- activities/views/compose.py | 1 + core/models/config.py | 1 + templates/activities/_post.html | 10 +++++++--- users/views/settings/interface.py | 6 +++++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/activities/models/post.py b/activities/models/post.py index 44854b6..7952cd5 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -9,7 +9,7 @@ from django.contrib.postgres.indexes import GinIndex from django.db import models, transaction from django.template import loader from django.template.defaultfilters import linebreaks_filter -from django.utils import timezone +from django.utils import text, timezone from activities.models.emoji import Emoji from activities.models.fan_out import FanOut @@ -388,6 +388,14 @@ class Post(StatorModel): """ return self.safe_content(local=False) + def summary_class(self) -> str: + """ + Returns a CSS class name to identify this summary value + """ + if not self.summary: + return "" + return "summary-" + text.slugify(self.summary, allow_unicode=True) + ### Async helpers ### async def afetch_full(self) -> "Post": diff --git a/activities/views/compose.py b/activities/views/compose.py index 7fef78a..1ca0435 100644 --- a/activities/views/compose.py +++ b/activities/views/compose.py @@ -120,6 +120,7 @@ class Compose(FormView): initial["visibility"] = Post.Visibilities.unlisted else: initial["visibility"] = self.reply_to.visibility + initial["content_warning"] = self.reply_to.summary # Build a set of mentions for the content to start as mentioned = {self.reply_to.author} mentioned.update(self.reply_to.mentions.all()) diff --git a/core/models/config.py b/core/models/config.py index 84c08c8..35eb934 100644 --- a/core/models/config.py +++ b/core/models/config.py @@ -246,5 +246,6 @@ class Config(models.Model): # wellness Options visible_reaction_counts: bool = True + expand_linked_cws: bool = True custom_css: str | None diff --git a/templates/activities/_post.html b/templates/activities/_post.html index 55f5256..649ca3d 100644 --- a/templates/activities/_post.html +++ b/templates/activities/_post.html @@ -1,6 +1,6 @@ {% load static %} {% load activity_tags %} -
+
@@ -30,12 +30,16 @@ {% if post.summary %} -
+ {% if config_identity.expand_linked_cws %} +
+ {% else %} +
+ {% endif %} {{ post.summary }}
{% endif %} -
+
{{ post.safe_content_local }} {% if post.attachments.exists %} diff --git a/users/views/settings/interface.py b/users/views/settings/interface.py index 2f95e29..ca9a4f5 100644 --- a/users/views/settings/interface.py +++ b/users/views/settings/interface.py @@ -25,10 +25,14 @@ class InterfacePage(SettingsPage): "help_text": "Theme the website however you'd like, just for you. You should probably not use this unless you know what you're doing.", "display": "textarea", }, + "expand_linked_cws": { + "title": "Expand linked Content Warnings", + "help_text": "Expands all CWs of the same type at once, rather than one at a time.", + }, } layout = { "Posting": ["toot_mode", "default_post_visibility"], - "Wellness": ["visible_reaction_counts"], + "Wellness": ["visible_reaction_counts", "expand_linked_cws"], "Appearance": ["custom_css"], }