[PLUGINS][Repeat] Repeat now added has a reply and conversation of original note

This commit is contained in:
Eliseu Amaro 2021-12-26 18:40:54 +00:00 committed by Diogo Peralta Cordeiro
parent e10a38a3e2
commit 78cc9c4659
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 14 additions and 10 deletions

View File

@ -50,12 +50,12 @@ class Repeat extends Controller
* @throws RedirectException
* @throws ServerException
*/
public function repeatAddNote(Request $request, int $id): bool|array
public function repeatAddNote(Request $request, int $note_id): bool|array
{
$user = Common::ensureLoggedIn();
$actor_id = $user->getId();
$note = Note::getByPK(['id' => $id]);
$note = Note::getByPK(['id' => $note_id]);
$form_add_to_repeat = Form::create([
['add_repeat', SubmitType::class,
@ -103,7 +103,7 @@ class Repeat extends Controller
* @throws RedirectException
* @throws ServerException
*/
public function repeatRemoveNote(Request $request, int $id): array
public function repeatRemoveNote(Request $request, int $note_id): array
{
$user = Common::ensureLoggedIn();
@ -122,7 +122,7 @@ class Repeat extends Controller
$form_remove_repeat->handleRequest($request);
if ($form_remove_repeat->isSubmitted()) {
if (!\is_null(\Plugin\RepeatNote\RepeatNote::unrepeatNote(note_id: $id, actor_id: $actor_id))) {
if (!\is_null(\Plugin\RepeatNote\RepeatNote::unrepeatNote(note_id: $note_id, actor_id: $actor_id))) {
DB::flush();
} else {
throw new ClientException(_m('Note wasn\'t repeated!'));
@ -146,7 +146,7 @@ class Repeat extends Controller
return [
'_template' => 'repeat/remove_from_repeats.html.twig',
'note' => Note::getById($id),
'note' => Note::getById($note_id),
'remove_repeat' => $form_remove_repeat->createView(),
];
}

View File

@ -60,6 +60,10 @@ class RepeatNote extends NoteHandlerPlugin
], order_by: ['created' => 'DESC'])[0];
}
// If it's a repeat, the reply_to should be to the original, conversation ought to be the same
$og_id = $note->getId();
$extra_args['reply_to'] = $og_id;
// Create a new note with the same content as the original
$repeat = Posting::storeLocalNote(
actor: Actor::getById($actor_id),
@ -67,11 +71,11 @@ class RepeatNote extends NoteHandlerPlugin
content_type: $note->getContentType(),
language: \is_null($lang_id = $note->getLanguageId()) ? null : Language::getById($lang_id)->getLocale(),
processed_attachments: $note->getAttachmentsWithTitle(),
process_note_content_extra_args: $extra_args,
);
// Find the id of the note we just created
$repeat_id = $repeat?->getId();
$og_id = $note->getId();
// Add it to note_repeat table
if (!\is_null($repeat_id)) {
@ -182,7 +186,7 @@ class RepeatNote extends NoteHandlerPlugin
}
// Generating URL for repeat action route
$args = ['id' => $is_repeat === 0 ? $note->getId() : $note_repeat[0]->getRepeatOf()];
$args = ['note_id' => $is_repeat === 0 ? $note->getId() : $note_repeat[0]->getRepeatOf()];
$type = Router::ABSOLUTE_PATH;
$repeat_action_url = $is_repeat
? Router::url('repeat_remove', $args, $type)
@ -199,7 +203,7 @@ class RepeatNote extends NoteHandlerPlugin
'url' => $repeat_action_url,
'title' => $is_repeat ? 'Remove this repeat' : 'Repeat this note!',
'classes' => "button-container repeat-button-container {$extra_classes}",
'id' => 'repeat-button-container-' . $note->getId(),
'note_id' => 'repeat-button-container-' . $note->getId(),
];
$actions[] = $repeat_action;
@ -265,8 +269,8 @@ class RepeatNote extends NoteHandlerPlugin
public function onAddRoute(RouteLoader $r): bool
{
// Add/remove note to/from repeats
$r->connect(id: 'repeat_add', uri_path: '/object/note/{id<\d+>}/repeat', target: [Controller\Repeat::class, 'repeatAddNote']);
$r->connect(id: 'repeat_remove', uri_path: '/object/note/{id<\d+>}/unrepeat', target: [Controller\Repeat::class, 'repeatRemoveNote']);
$r->connect(id: 'repeat_add', uri_path: '/object/note/{note_id<\d+>}/repeat', target: [Controller\Repeat::class, 'repeatAddNote']);
$r->connect(id: 'repeat_remove', uri_path: '/object/note/{note_id<\d+>}/unrepeat', target: [Controller\Repeat::class, 'repeatRemoveNote']);
return Event::next;
}