[COMPONENT][Posting] Plumb in reply_to and redirecto to GET from

This commit is contained in:
Hugo Sales 2022-01-03 20:35:26 +00:00
parent 7d38c927e1
commit a8a8cc4046
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 28 additions and 14 deletions

View File

@ -55,6 +55,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException; use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException;
use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\Length;
class Posting extends Component class Posting extends Component
@ -129,6 +130,8 @@ class Posting extends Component
try { try {
if ($form->isValid()) { if ($form->isValid()) {
$data = $form->getData(); $data = $form->getData();
Event::handle('PostingModifyData', [$request, $actor, &$data, $form_params, $form]);
if (empty($data['content']) && empty($data['attachments'])) { if (empty($data['content']) && empty($data['attachments'])) {
// TODO Display error: At least one of `content` and `attachments` must be provided // TODO Display error: At least one of `content` and `attachments` must be provided
throw new ClientException(_m('You must enter content or provide at least one attachment to post a note.')); throw new ClientException(_m('You must enter content or provide at least one attachment to post a note.'));
@ -148,15 +151,28 @@ class Posting extends Component
content_type: $content_type, content_type: $content_type,
language: $data['language'], language: $data['language'],
scope: VisibilityScope::from($data['visibility']), scope: VisibilityScope::from($data['visibility']),
target: $data['in'] ?? null, target: $data['in'] ?? $context_actor,
reply_to_id: $data['reply_to_id'],
attachments: $data['attachments'], attachments: $data['attachments'],
process_note_content_extra_args: $extra_args, process_note_content_extra_args: $extra_args,
); );
try {
if ($request->query->has('from')) {
$from = $request->query->get('from');
if (str_contains($from, '#')) {
[$from, $fragment] = explode('#', $from);
}
Router::match($from);
throw new RedirectException(url: $from . (isset($fragment) ? '#' . $fragment : ''));
}
} catch (ResourceNotFoundException $e) {
// continue
}
throw new RedirectException(); throw new RedirectException();
} }
} catch (FormSizeFileException $sizeFileException) { } catch (FormSizeFileException $e) {
throw new FormSizeFileException(); throw new ClientException(_m('Invalid file size given'), previous: $e);
} }
} }
@ -185,7 +201,8 @@ class Posting extends Component
string $content_type, string $content_type,
?string $language = null, ?string $language = null,
?VisibilityScope $scope = null, ?VisibilityScope $scope = null,
?string $target = null, null|int|Actor $target = null,
?int $reply_to_id = null,
array $attachments = [], array $attachments = [],
array $processed_attachments = [], array $processed_attachments = [],
array $process_note_content_extra_args = [], array $process_note_content_extra_args = [],
@ -206,6 +223,7 @@ class Posting extends Component
'language_id' => !\is_null($language) ? Language::getByLocale($language)->getId() : null, 'language_id' => !\is_null($language) ? Language::getByLocale($language)->getId() : null,
'is_local' => true, 'is_local' => true,
'scope' => $scope, 'scope' => $scope,
'reply_to' => $reply_to_id,
]); ]);
/** @var UploadedFile[] $attachments */ /** @var UploadedFile[] $attachments */
@ -222,11 +240,6 @@ class Posting extends Component
DB::persist($note); 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 // Need file and note ids for the next step
$note->setUrl(Router::url('note_view', ['id' => $note->getId()], Router::ABSOLUTE_URL)); $note->setUrl(Router::url('note_view', ['id' => $note->getId()], Router::ABSOLUTE_URL));
if (!empty($content)) { if (!empty($content)) {
@ -242,6 +255,8 @@ class Posting extends Component
} }
} }
Conversation::assignLocalConversation($note, $reply_to_id);
$activity = Activity::create([ $activity = Activity::create([
'actor_id' => $actor->getId(), 'actor_id' => $actor->getId(),
'verb' => 'create', 'verb' => 'create',
@ -269,7 +284,7 @@ class Posting extends Component
DB::flush(); DB::flush();
if ($notify) { if ($notify) {
Event::handle('NewNotification', [$actor, $activity, ['object' => $mention_ids], _m('{nickname} created a note {note_id}.', ['nickname' => $actor->getNickname(), 'note_id' => $activity->getObjectId()])]); Event::handle('NewNotification', [$actor, $activity, ['object' => $mention_ids], _m('{nickname} created a note {note_id}.', ['{nickname}' => $actor->getNickname(), '{note_id}' => $activity->getObjectId()])]);
} }
return $note; return $note;

View File

@ -56,9 +56,9 @@ use Symfony\Component\Validator\Exception\ValidatorException;
use Throwable; use Throwable;
/** /**
* @method ?int int(string $param) * @method ?int int(string $param, ?\Throwable $throw = null)
* @method ?bool bool(string $param) * @method ?bool bool(string $param, ?\Throwable $throw = null)
* @method ?string string(string $param) * @method ?string string(string $param, ?\Throwable $throw = null)
* @method ?string params(string $param) * @method ?string params(string $param)
* @method mixed handle(Request $request, mixed ...$extra) * @method mixed handle(Request $request, mixed ...$extra)
*/ */
@ -257,7 +257,6 @@ abstract class Controller extends AbstractController implements EventSubscriberI
} else { } else {
return null; return null;
} }
break;
case 'params': case 'params':
return $this->request->query->all(); return $this->request->query->all();
default: default: