[PLUGINS][Repeat] Repeat now added has a reply and conversation of original note
This commit is contained in:
parent
e10a38a3e2
commit
78cc9c4659
@ -50,12 +50,12 @@ class Repeat extends Controller
|
|||||||
* @throws RedirectException
|
* @throws RedirectException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public function repeatAddNote(Request $request, int $id): bool|array
|
public function repeatAddNote(Request $request, int $note_id): bool|array
|
||||||
{
|
{
|
||||||
$user = Common::ensureLoggedIn();
|
$user = Common::ensureLoggedIn();
|
||||||
|
|
||||||
$actor_id = $user->getId();
|
$actor_id = $user->getId();
|
||||||
$note = Note::getByPK(['id' => $id]);
|
$note = Note::getByPK(['id' => $note_id]);
|
||||||
|
|
||||||
$form_add_to_repeat = Form::create([
|
$form_add_to_repeat = Form::create([
|
||||||
['add_repeat', SubmitType::class,
|
['add_repeat', SubmitType::class,
|
||||||
@ -103,7 +103,7 @@ class Repeat extends Controller
|
|||||||
* @throws RedirectException
|
* @throws RedirectException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public function repeatRemoveNote(Request $request, int $id): array
|
public function repeatRemoveNote(Request $request, int $note_id): array
|
||||||
{
|
{
|
||||||
$user = Common::ensureLoggedIn();
|
$user = Common::ensureLoggedIn();
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ class Repeat extends Controller
|
|||||||
|
|
||||||
$form_remove_repeat->handleRequest($request);
|
$form_remove_repeat->handleRequest($request);
|
||||||
if ($form_remove_repeat->isSubmitted()) {
|
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();
|
DB::flush();
|
||||||
} else {
|
} else {
|
||||||
throw new ClientException(_m('Note wasn\'t repeated!'));
|
throw new ClientException(_m('Note wasn\'t repeated!'));
|
||||||
@ -146,7 +146,7 @@ class Repeat extends Controller
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'_template' => 'repeat/remove_from_repeats.html.twig',
|
'_template' => 'repeat/remove_from_repeats.html.twig',
|
||||||
'note' => Note::getById($id),
|
'note' => Note::getById($note_id),
|
||||||
'remove_repeat' => $form_remove_repeat->createView(),
|
'remove_repeat' => $form_remove_repeat->createView(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,10 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
], order_by: ['created' => 'DESC'])[0];
|
], 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
|
// Create a new note with the same content as the original
|
||||||
$repeat = Posting::storeLocalNote(
|
$repeat = Posting::storeLocalNote(
|
||||||
actor: Actor::getById($actor_id),
|
actor: Actor::getById($actor_id),
|
||||||
@ -67,11 +71,11 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
content_type: $note->getContentType(),
|
content_type: $note->getContentType(),
|
||||||
language: \is_null($lang_id = $note->getLanguageId()) ? null : Language::getById($lang_id)->getLocale(),
|
language: \is_null($lang_id = $note->getLanguageId()) ? null : Language::getById($lang_id)->getLocale(),
|
||||||
processed_attachments: $note->getAttachmentsWithTitle(),
|
processed_attachments: $note->getAttachmentsWithTitle(),
|
||||||
|
process_note_content_extra_args: $extra_args,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Find the id of the note we just created
|
// Find the id of the note we just created
|
||||||
$repeat_id = $repeat?->getId();
|
$repeat_id = $repeat?->getId();
|
||||||
$og_id = $note->getId();
|
|
||||||
|
|
||||||
// Add it to note_repeat table
|
// Add it to note_repeat table
|
||||||
if (!\is_null($repeat_id)) {
|
if (!\is_null($repeat_id)) {
|
||||||
@ -182,7 +186,7 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generating URL for repeat action route
|
// 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;
|
$type = Router::ABSOLUTE_PATH;
|
||||||
$repeat_action_url = $is_repeat
|
$repeat_action_url = $is_repeat
|
||||||
? Router::url('repeat_remove', $args, $type)
|
? Router::url('repeat_remove', $args, $type)
|
||||||
@ -199,7 +203,7 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
'url' => $repeat_action_url,
|
'url' => $repeat_action_url,
|
||||||
'title' => $is_repeat ? 'Remove this repeat' : 'Repeat this note!',
|
'title' => $is_repeat ? 'Remove this repeat' : 'Repeat this note!',
|
||||||
'classes' => "button-container repeat-button-container {$extra_classes}",
|
'classes' => "button-container repeat-button-container {$extra_classes}",
|
||||||
'id' => 'repeat-button-container-' . $note->getId(),
|
'note_id' => 'repeat-button-container-' . $note->getId(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$actions[] = $repeat_action;
|
$actions[] = $repeat_action;
|
||||||
@ -265,8 +269,8 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
public function onAddRoute(RouteLoader $r): bool
|
public function onAddRoute(RouteLoader $r): bool
|
||||||
{
|
{
|
||||||
// Add/remove note to/from repeats
|
// 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_add', uri_path: '/object/note/{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_remove', uri_path: '/object/note/{note_id<\d+>}/unrepeat', target: [Controller\Repeat::class, 'repeatRemoveNote']);
|
||||||
|
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user