[PLUGINS][TreeNotes] Feed only shows each note and its respective direct

replies, conversation shows whole tree

[COMPONENTS][Feed] Added request to FormatNoteList event

Every single Note that was provided to FeedController::postProcess is
shown. This means, that even though the Feed is formatted to show only a
Note and its respective direct replies, those same replies are shown
individually again (and they get the chance to show their own direct
replies).

The Note list provided to FormatNoteList is reversed, and for every
index, the respective Note replies are filtered out of the original list.
The replies are then added as leafs of the current Note and added to the tree.
This commit is contained in:
2021-12-31 23:26:39 +00:00
parent f6311debbf
commit e7940a21ee
6 changed files with 59 additions and 17 deletions

View File

@@ -49,7 +49,7 @@ class Reply extends FeedController
*
* @return array
*/
public function addReply(Request $request, int $note_id, int $actor_id)
public function addReply(Request $request, int $note_id)
{
$user = Common::ensureLoggedIn();

View File

@@ -86,9 +86,9 @@ class Conversation extends Component
}
// Generating URL for reply action route
$args = ['note_id' => $note->getId(), 'actor_id' => $note->getActor()->getId()];
$args = ['note_id' => $note->getId()];
$type = Router::ABSOLUTE_PATH;
$reply_action_url = Router::url('reply_add', $args, $type);
$reply_action_url = Router::url('conversation_reply_to', $args, $type);
$query_string = $request->getQueryString();
// Concatenating get parameter to redirect the user to where he came from
@@ -109,7 +109,7 @@ class Conversation extends Component
{
// If Actor is adding a reply, get parent's Note id
// Else it's null
$extra_args['reply_to'] = $request->get('_route') === 'reply_add' ? (int) $request->get('note_id') : null;
$extra_args['reply_to'] = $request->get('_route') === 'conversation_reply_to' ? (int) $request->get('note_id') : null;
return Event::next;
}
@@ -147,7 +147,7 @@ class Conversation extends Component
public function onAddRoute(RouteLoader $r): bool
{
$r->connect('reply_add', '/object/note/new?to={actor_id<\d+>}&reply_to={note_id<\d+>}', [ReplyController::class, 'addReply']);
$r->connect('conversation_reply_to', '/conversation/reply?reply_to_note={note_id<\d+>}', [ReplyController::class, 'addReply']);
$r->connect('conversation', '/conversation/{conversation_id<\d+>}', [Controller\Conversation::class, 'showConversation']);
$r->connect('conversation_mute', '/conversation/{conversation_id<\d+>}/mute', [Controller\Conversation::class, 'muteConversation']);

View File

@@ -38,6 +38,7 @@ use App\Entity\Actor;
use App\Entity\Note;
use App\Util\Common;
use Functional as F;
use function App\Core\I18n\_m;
abstract class FeedController extends Controller
{
@@ -49,12 +50,11 @@ abstract class FeedController extends Controller
protected function postProcess(array $result): array
{
$actor = Common::actor();
if (\array_key_exists('notes', $result)) {
$notes = $result['notes'];
self::enforceScope($notes, $actor);
Event::handle('FilterNoteList', [$actor, &$notes, $result['request']]);
Event::handle('FormatNoteList', [$notes, &$result['notes']]);
Event::handle('FormatNoteList', [$notes, &$result['notes'], &$result['request']]);
}
return $result;

View File

@@ -15,7 +15,7 @@
<summary class="section-title-summary">
<h2>
{% set current_path = app.request.get('_route') %}
{% if current_path == 'reply_add' %}
{% if current_path == 'conversation_reply_to' %}
{{ "Reply to note" | trans }}
{% else %}
{{ "Create a note" | trans }}