From 4dd976eb223afd276c3459bfe688c3fb95fc255e Mon Sep 17 00:00:00 2001 From: Eliseu Amaro Date: Fri, 4 Feb 2022 16:03:49 +0000 Subject: [PATCH] [ENTITY][Note] Added function getRenderedSplit, return an array of paragraphs/line breaks [PLUGINS][Favourite] Foreign keys now properly defined on schema [CARDS][Note] Note text is now hidden by default if too many paragraphs/line breaks are present, BlogCollection plugin will certainly need this feature --- .../Entity/AttachmentCollection.php | 2 +- plugins/Favourite/Entity/NoteFavourite.php | 8 +++++-- .../assets/default_theme/css/pages/feeds.css | 23 +++++++++++++++++++ src/Entity/Note.php | 5 ++++ templates/cards/note/view.html.twig | 17 +++++++++++++- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/plugins/AttachmentCollections/Entity/AttachmentCollection.php b/plugins/AttachmentCollections/Entity/AttachmentCollection.php index 2c1f976bcd..a40f30a37e 100644 --- a/plugins/AttachmentCollections/Entity/AttachmentCollection.php +++ b/plugins/AttachmentCollections/Entity/AttachmentCollection.php @@ -55,7 +55,7 @@ class AttachmentCollection extends Entity public static function schemaDef() { return [ - 'name' => 'collection', + 'name' => 'attachment_collection', 'fields' => [ 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'], 'name' => ['type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'collection\'s name'], diff --git a/plugins/Favourite/Entity/NoteFavourite.php b/plugins/Favourite/Entity/NoteFavourite.php index de3027f23a..9b08f3a164 100644 --- a/plugins/Favourite/Entity/NoteFavourite.php +++ b/plugins/Favourite/Entity/NoteFavourite.php @@ -152,8 +152,12 @@ class NoteFavourite extends Entity 'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'], 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'], ], - 'primary key' => ['note_id', 'actor_id'], - 'indexes' => [ + 'primary key' => ['note_id', 'actor_id'], + 'foreign keys' => [ + 'note_id_to_id_fkey' => ['note', ['note_id' => 'id']], + 'actor_reply_to_id_fkey' => ['actor', ['actor_id' => 'id']], + ], + 'indexes' => [ 'fave_note_id_idx' => ['note_id'], 'fave_actor_id_idx' => ['actor_id', 'modified'], 'fave_modified_idx' => ['modified'], diff --git a/public/assets/default_theme/css/pages/feeds.css b/public/assets/default_theme/css/pages/feeds.css index eab59a9ba3..9120a8f66a 100644 --- a/public/assets/default_theme/css/pages/feeds.css +++ b/public/assets/default_theme/css/pages/feeds.css @@ -324,6 +324,29 @@ embed header { text-decoration: underline !important; } +.note-text p:not(:last-of-type) { + display: block; + margin-bottom: var(--s); + width: 100%; +} + +.note-text-details-summary:after { + content: "\2193"; +} + +.note-text-details .note-text-details-summary small { + font-style: italic; +} + +.note-text-details[open] summary:after { + content: "\2191"; + float: right; +} + +.note-text-details[open] .note-text-details-summary small { + display: none; +} + .note-wrapper { height: inherit; width: 100%; diff --git a/src/Entity/Note.php b/src/Entity/Note.php index a47f2fe68b..25ace3174e 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -286,6 +286,11 @@ class Note extends Entity return !\is_null($this->getLanguageId()) ? Language::getById($this->getLanguageId())->getLocale() : null; } + public function getRenderedSplit(): array + { + return preg_split('/(<\s*p\s*\/?>)|(<\s*br\s*\/?>)|(\s\s+)|(<\s*\/p\s*\/?>)/', $this->getRendered(), -1, PREG_SPLIT_NO_EMPTY); + } + public static function getAllNotesByActor(Actor $actor): array { // TODO: Enforce scoping on the notes before returning diff --git a/templates/cards/note/view.html.twig b/templates/cards/note/view.html.twig index 16df0f1ca9..cf4d5b2589 100644 --- a/templates/cards/note/view.html.twig +++ b/templates/cards/note/view.html.twig @@ -64,7 +64,22 @@ {% block note_text %}
- {{ note.getRendered() | raw }} + {% set paragraph_array = note.getRenderedSplit() %} + {% if 'conversation' not in app.request.get('_route') and paragraph_array | length > 3 %} +

{{ paragraph_array[0] | raw }}

+
+ + {% trans %}Expand to see all content{% endtrans %} + + {% for paragraph in paragraph_array | slice(1, paragraph_array | length) %} +

{{ paragraph | raw }}

+ {% endfor %} +
+ {% else %} + {% for paragraph in paragraph_array %} +

{{ paragraph | raw }}

+ {% endfor %} + {% endif %}
{% endblock note_text %}