[NoteActions] Refactor note actions and fix bug in favourite
This commit is contained in:
parent
4c15271d36
commit
72208b066c
|
@ -36,11 +36,6 @@ class Favourite extends Module
|
|||
public function onAddNoteActions(Request $request, Note $note, array &$actions)
|
||||
{
|
||||
$user = Common::user();
|
||||
// Only show buttons if a user is logged in
|
||||
if ($user == null) {
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
$opts = ['note_id' => $note->getId(), 'gsactor_id' => $user->getId()];
|
||||
$is_set = DB::find('favourite', $opts) != null;
|
||||
$form = Form::create([
|
||||
|
|
|
@ -34,13 +34,6 @@ class Repeat extends Module
|
|||
{
|
||||
public function onAddNoteActions(Request $request, Note $note, array &$actions)
|
||||
{
|
||||
$user = Common::user();
|
||||
// Only show buttons if a user is logged in
|
||||
if ($user == null) {
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
$to_repeat = DB::find('note', ['id' => $note->getId()]);
|
||||
$is_set = false;
|
||||
$form = Form::create([
|
||||
['is_set', HiddenType::class, ['data' => $is_set ? '1' : '0']],
|
||||
|
@ -52,17 +45,23 @@ class Repeat extends Module
|
|||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted()) {
|
||||
$data = $form->getData();
|
||||
// Loose comparison
|
||||
if ($data['note_id'] != $to_repeat) {
|
||||
if ($data['note_id'] != $note . getId()) {
|
||||
// ^ Loose comparison
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!$note->isVisibleTo(Common::user())) {
|
||||
// ^ Ensure user isn't trying to trip us up
|
||||
Log::error('Suspicious activity: user ' . $user->getNickname() .
|
||||
' tried to repeat note ' . $note->getId() .
|
||||
', but they shouldn\'t have access to it');
|
||||
throw new NoSuchNoteException();
|
||||
} else {
|
||||
if ($form->isValid()) {
|
||||
if (!$data['is_set']) {
|
||||
DB::persist(Note::create(['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId(), 'content' => $note->getContent(), 'is_local' => true]));
|
||||
DB::flush();
|
||||
} else {
|
||||
DB::remove($to_repeat);
|
||||
DB::remove(DB::findOneBy('note', ['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId()]));
|
||||
DB::flush();
|
||||
}
|
||||
return Event::stop;
|
||||
|
@ -71,6 +70,8 @@ class Repeat extends Module
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$actions[] = $form->createView();
|
||||
return Event::next;
|
||||
|
|
|
@ -60,6 +60,11 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface
|
|||
|
||||
public function getNoteActions(Note $note)
|
||||
{
|
||||
// Only show buttons if a user is logged in
|
||||
if (Common::user() == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$actions = [];
|
||||
Event::handle('add_note_actions', [$this->request, $note, &$actions]);
|
||||
return $actions;
|
||||
|
|
Loading…
Reference in New Issue
Block a user