[EVENTS] Change FormatNoteList do separate in and out arguments

This is necessary due to some weird problem which I wasn't able to figure out (but which doesn't matter)
that somehow causes the event to be called twice during testing, and thus the function was exploding
This commit is contained in:
2021-08-07 21:52:00 +00:00
parent 57f43108bb
commit 061a85d6b3
4 changed files with 58 additions and 15 deletions

View File

@@ -27,10 +27,10 @@ class TreeNotes extends Plugin
/**
* Format the given $notes_in_trees_out in a list of reply trees
*/
public function onFormatNoteList(array &$notes_in_trees_out)
public function onFormatNoteList(array $notes_in, ?array &$notes_out)
{
$roots = array_filter($notes_in_trees_out, function (Note $note) { return $note->getReplyTo() == null; }, ARRAY_FILTER_USE_BOTH);
$notes_in_trees_out = $this->build_tree($roots, $notes_in_trees_out);
$roots = array_filter($notes_in, function (Note $note) { return $note->getReplyTo() == null; });
$notes_out = $this->build_tree($roots, $notes_in);
}
private function build_tree(array $parents, array $notes)
@@ -44,7 +44,7 @@ class TreeNotes extends Plugin
private function build_subtree(Note $parent, array $notes)
{
$children = array_filter($notes, function (Note $n) use ($parent) { return $parent->getId() == $n->getReplyTo(); }, ARRAY_FILTER_USE_BOTH);
$children = array_filter($notes, function (Note $n) use ($parent) { return $parent->getId() == $n->getReplyTo(); });
return ['note' => $parent, 'replies' => $this->build_tree($children, $notes)];
}
}