From b05106e7f96202538e71bde23ed5e8e61a9dcb78 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Thu, 23 Dec 2021 16:20:52 +0000 Subject: [PATCH] [COMPONENT][Conversation] Minor corrections and don't store URI in DB --- components/Conversation/Conversation.php | 21 ++++---------- .../Conversation/Entity/Conversation.php | 28 ++++++++----------- components/Posting/Posting.php | 10 +++---- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/components/Conversation/Conversation.php b/components/Conversation/Conversation.php index 2b58d20a7e..9a6d819031 100644 --- a/components/Conversation/Conversation.php +++ b/components/Conversation/Conversation.php @@ -30,16 +30,11 @@ use App\Core\Modules\Component; use App\Core\Router\RouteLoader; use App\Core\Router\Router; use App\Entity\Actor; -use App\Entity\Feed; -use App\Entity\LocalUser; use App\Entity\Note; use App\Util\Common; -use App\Util\Exception\ServerException; use App\Util\Formatting; -use App\Util\Nickname; use Component\Conversation\Controller\Reply as ReplyController; use Component\Conversation\Entity\Conversation as ConversationEntity; -use const SORT_REGULAR; use Symfony\Component\HttpFoundation\Request; class Conversation extends Component @@ -64,8 +59,7 @@ class Conversation extends Component // We need the Conversation id itself, so a persist is in order DB::persist($conversation); - // Set the Uri and current_note's own conversation_id - $conversation->setUri(Router::url('conversation', ['conversation_id' => $conversation->getId()], Router::ABSOLUTE_URL)); + // Set current_note's own conversation_id $current_note->setConversationId($conversation->getId()); } else { // It's a reply for sure @@ -103,7 +97,7 @@ class Conversation extends Component $reply_action = [ 'url' => $reply_action_url, - 'title' => 'Reply to this note!', + 'title' => _m('Reply to this note!'), 'classes' => 'button-container reply-button-container note-actions-unset', 'id' => 'reply-button-container-' . $note->getId(), ]; @@ -143,7 +137,7 @@ class Conversation extends Component } // Filter out multiple replies from the same actor - $reply_actor = array_unique($reply_actor, SORT_REGULAR); + $reply_actor = array_unique($reply_actor, \SORT_REGULAR); // Add to complementary info foreach ($reply_actor as $actor) { @@ -152,12 +146,7 @@ class Conversation extends Component if ($check_user && $actor->getId() === (Common::actor())->getId()) { // If the reply is yours - try { - $you_translation = _m('You'); - } catch (ServerException $e) { - $you_translation = 'You'; - } - + $you_translation = _m('You'); $prepend = "{$you_translation}, " . ($prepend = &$complementary_info); $complementary_info = $prepend; } else { @@ -167,7 +156,7 @@ class Conversation extends Component } $complementary_info = rtrim(trim($complementary_info), ','); - $complementary_info .= ' replied to this note.'; + $complementary_info .= _m(' replied to this note.'); $result[] = Formatting::twigRenderString($complementary_info, []); return Event::next; diff --git a/components/Conversation/Entity/Conversation.php b/components/Conversation/Entity/Conversation.php index fb34304cb8..3060283b40 100644 --- a/components/Conversation/Entity/Conversation.php +++ b/components/Conversation/Entity/Conversation.php @@ -24,6 +24,7 @@ declare(strict_types = 1); namespace Component\Conversation\Entity; use App\Core\Entity; +use App\Core\Router\Router; /** * Entity class for Conversations @@ -59,17 +60,6 @@ class Conversation extends Entity return $this->id; } - public function setUri(string $uri): self - { - $this->uri = $uri; - return $this; - } - - public function getUri(): string - { - return $this->uri; - } - public function setInitialNoteId(int $initial_note_id): self { $this->initial_note_id = $initial_note_id; @@ -84,19 +74,25 @@ class Conversation extends Entity // @codeCoverageIgnoreEnd // }}} Autocode + public function getUrl(int $type = Router::ABSOLUTE_URL): string + { + return Router::url('conversation', ['conversation_id' => $this->getId()], $type); + } + + public function getUri(): string + { + return $this->getUrl(type: Router::ABSOLUTE_URL); + } + public static function schemaDef(): array { return [ 'name' => 'conversation', 'fields' => [ 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'Serial identifier, since any additional meaning would require updating its value for every reply upon receiving a new aparent root'], - 'uri' => ['type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'URI of the conversation'], 'initial_note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'Initial note seen on this host for this conversation'], ], - 'primary key' => ['id'], - 'unique keys' => [ - 'conversation_uri_uniq' => ['uri'], - ], + 'primary key' => ['id'], 'foreign keys' => [ 'initial_note_id_to_id_fkey' => ['note', ['initial_note_id' => 'id']], ], diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 351d29ebba..bb115ec327 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -224,17 +224,17 @@ class Posting extends Component DB::persist($note); + // Assign conversation to this note + // AddExtraArgsToNoteContent already added the info we need + $reply_to = $process_note_content_extra_args['reply_to']; + Conversation::assignLocalConversation($note, $reply_to); + // Need file and note ids for the next step $note->setUrl(Router::url('note_view', ['id' => $note->getId()], Router::ABSOLUTE_URL)); if (!empty($content)) { Event::handle('ProcessNoteContent', [$note, $content, $content_type, $process_note_content_extra_args]); } - // Assign conversation to this note - // AddExtraArgsToNoteContent already added the info we need - $reply_to = $process_note_content_extra_args['reply_to']; - Conversation::assignLocalConversation($note, $reply_to); - if ($processed_attachments !== []) { foreach ($processed_attachments as [$a, $fname]) { if (DB::count('actor_to_attachment', $args = ['attachment_id' => $a->getId(), 'actor_id' => $actor->getId()]) === 0) {