[COMPONENT][Conversation] Minor corrections and don't store URI in DB

This commit is contained in:
Diogo Peralta Cordeiro 2021-12-23 16:20:52 +00:00
parent e04d927fe9
commit b05106e7f9
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
3 changed files with 22 additions and 37 deletions

View File

@ -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';
}
$prepend = "<a href={$reply_actor_url}>{$you_translation}</a>, " . ($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;

View File

@ -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'],
],
'foreign keys' => [
'initial_note_id_to_id_fkey' => ['note', ['initial_note_id' => 'id']],
],

View File

@ -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) {