From bb1ab6dc69aee05a999a1b035b782e591db5acb4 Mon Sep 17 00:00:00 2001 From: Marty McGuire Date: Sat, 4 Nov 2023 17:18:32 +0000 Subject: [PATCH] minimal support for channels method=tree https://github.com/indieweb/microsub/issues/44 --- aperture/app/Channel.php | 14 +++++++++++++- .../app/Http/Controllers/MicrosubController.php | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/aperture/app/Channel.php b/aperture/app/Channel.php index c3114f7..1f00721 100644 --- a/aperture/app/Channel.php +++ b/aperture/app/Channel.php @@ -33,7 +33,7 @@ public function excluded_types() { return $types; } - public function to_array() { + public function to_array($include_sources = false) { $array = [ 'uid' => $this->uid, 'name' => $this->name, @@ -49,6 +49,18 @@ public function to_array() { if($this->default_destination) { $array['destination'] = $this->default_destination; } + if($include_sources) { + $sources = $this->sources()->get(); + $array['sources'] = []; + foreach($sources as $source) { + $source_array = $source->to_array(); + + $array['sources'][] = array_merge([ + '_id' => $source->id, + 'url' => $source->url + ], $source_array); + } + } return $array; } diff --git a/aperture/app/Http/Controllers/MicrosubController.php b/aperture/app/Http/Controllers/MicrosubController.php index d269bb4..a85ff1a 100644 --- a/aperture/app/Http/Controllers/MicrosubController.php +++ b/aperture/app/Http/Controllers/MicrosubController.php @@ -144,10 +144,11 @@ public function post(Request $request) { ////////////////////////////////////////////////////////////////////////////////// private function get_channels() { + $include_sources = (Request::input('method') == 'tree'); $channels = []; foreach(Auth::user()->channels()->get() as $channel) { - $channels[] = $channel->to_array(); + $channels[] = $channel->to_array($include_sources); } return [