PublicApiController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\{
  5. Hashtag,
  6. Follower,
  7. Like,
  8. Media,
  9. Notification,
  10. Profile,
  11. StatusHashtag,
  12. Status,
  13. UserFilter
  14. };
  15. use Auth,Cache;
  16. use Carbon\Carbon;
  17. use League\Fractal;
  18. use App\Transformer\Api\{
  19. AccountTransformer,
  20. RelationshipTransformer,
  21. StatusTransformer,
  22. };
  23. use App\Services\UserFilterService;
  24. use App\Jobs\StatusPipeline\NewStatusPipeline;
  25. use League\Fractal\Serializer\ArraySerializer;
  26. use League\Fractal\Pagination\IlluminatePaginatorAdapter;
  27. class PublicApiController extends Controller
  28. {
  29. protected $fractal;
  30. public function __construct()
  31. {
  32. $this->fractal = new Fractal\Manager();
  33. $this->fractal->setSerializer(new ArraySerializer());
  34. }
  35. protected function getUserData()
  36. {
  37. if(false == Auth::check()) {
  38. return [];
  39. } else {
  40. $profile = Auth::user()->profile;
  41. if($profile->status) {
  42. return [];
  43. }
  44. $user = new Fractal\Resource\Item($profile, new AccountTransformer());
  45. return $this->fractal->createData($user)->toArray();
  46. }
  47. }
  48. protected function getLikes($status)
  49. {
  50. if(false == Auth::check()) {
  51. return [];
  52. } else {
  53. $profile = Auth::user()->profile;
  54. if($profile->status) {
  55. return [];
  56. }
  57. $likes = $status->likedBy()->orderBy('created_at','desc')->paginate(10);
  58. $collection = new Fractal\Resource\Collection($likes, new AccountTransformer());
  59. return $this->fractal->createData($collection)->toArray();
  60. }
  61. }
  62. protected function getShares($status)
  63. {
  64. if(false == Auth::check()) {
  65. return [];
  66. } else {
  67. $profile = Auth::user()->profile;
  68. if($profile->status) {
  69. return [];
  70. }
  71. $shares = $status->sharedBy()->orderBy('created_at','desc')->paginate(10);
  72. $collection = new Fractal\Resource\Collection($shares, new AccountTransformer());
  73. return $this->fractal->createData($collection)->toArray();
  74. }
  75. }
  76. public function status(Request $request, $username, int $postid)
  77. {
  78. $profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail();
  79. $status = Status::whereProfileId($profile->id)->findOrFail($postid);
  80. $this->scopeCheck($profile, $status);
  81. $item = new Fractal\Resource\Item($status, new StatusTransformer());
  82. $res = [
  83. 'status' => $this->fractal->createData($item)->toArray(),
  84. 'user' => $this->getUserData(),
  85. 'likes' => $this->getLikes($status),
  86. 'shares' => $this->getShares($status),
  87. 'reactions' => [
  88. 'liked' => $status->liked(),
  89. 'shared' => $status->shared(),
  90. 'bookmarked' => $status->bookmarked(),
  91. ],
  92. ];
  93. return response()->json($res, 200, [], JSON_PRETTY_PRINT);
  94. }
  95. public function statusComments(Request $request, $username, int $postId)
  96. {
  97. $this->validate($request, [
  98. 'min_id' => 'nullable|integer|min:1',
  99. 'max_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
  100. 'limit' => 'nullable|integer|min:5|max:50'
  101. ]);
  102. $limit = $request->limit ?? 10;
  103. $profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail();
  104. $status = Status::whereProfileId($profile->id)->whereCommentsDisabled(false)->findOrFail($postId);
  105. $this->scopeCheck($profile, $status);
  106. if(Auth::check()) {
  107. $pid = Auth::user()->profile->id;
  108. $filtered = UserFilter::whereUserId($pid)
  109. ->whereFilterableType('App\Profile')
  110. ->whereIn('filter_type', ['mute', 'block'])
  111. ->pluck('filterable_id')->toArray();
  112. } else {
  113. $filtered = [];
  114. }
  115. if($request->filled('min_id') || $request->filled('max_id')) {
  116. if($request->filled('min_id')) {
  117. $replies = $status->comments()
  118. ->whereNull('reblog_of_id')
  119. ->whereNotIn('profile_id', $filtered)
  120. ->select('id', 'caption', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
  121. ->where('id', '>=', $request->min_id)
  122. ->orderBy('id', 'desc')
  123. ->paginate($limit);
  124. }
  125. if($request->filled('max_id')) {
  126. $replies = $status->comments()
  127. ->whereNull('reblog_of_id')
  128. ->whereNotIn('profile_id', $filtered)
  129. ->select('id', 'caption', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
  130. ->where('id', '<=', $request->max_id)
  131. ->orderBy('id', 'desc')
  132. ->paginate($limit);
  133. }
  134. } else {
  135. $replies = $status->comments()
  136. ->whereNull('reblog_of_id')
  137. ->whereNotIn('profile_id', $filtered)
  138. ->select('id', 'caption', 'is_nsfw', 'rendered', 'profile_id', 'in_reply_to_id', 'type', 'reply_count', 'created_at')
  139. ->orderBy('id', 'desc')
  140. ->paginate($limit);
  141. }
  142. $resource = new Fractal\Resource\Collection($replies, new StatusTransformer(), 'data');
  143. $resource->setPaginator(new IlluminatePaginatorAdapter($replies));
  144. $res = $this->fractal->createData($resource)->toArray();
  145. return response()->json($res, 200, [], JSON_PRETTY_PRINT);
  146. }
  147. public function statusLikes(Request $request, $username, $id)
  148. {
  149. $profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail();
  150. $status = Status::whereProfileId($profile->id)->findOrFail($id);
  151. $this->scopeCheck($profile, $status);
  152. $likes = $this->getLikes($status);
  153. return response()->json([
  154. 'data' => $likes
  155. ]);
  156. }
  157. public function statusShares(Request $request, $username, $id)
  158. {
  159. $profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail();
  160. $status = Status::whereProfileId($profile->id)->findOrFail($id);
  161. $this->scopeCheck($profile, $status);
  162. $shares = $this->getShares($status);
  163. return response()->json([
  164. 'data' => $shares
  165. ]);
  166. }
  167. protected function scopeCheck(Profile $profile, Status $status)
  168. {
  169. if($profile->is_private == true && Auth::check() == false) {
  170. abort(404);
  171. }
  172. switch ($status->scope) {
  173. case 'public':
  174. case 'unlisted':
  175. break;
  176. case 'private':
  177. $user = Auth::check() ? Auth::user() : false;
  178. if(!$user) {
  179. abort(403);
  180. } else {
  181. $follows = $profile->followedBy($user->profile);
  182. if($follows == false && $profile->id !== $user->profile->id && $user->is_admin == false) {
  183. abort(404);
  184. }
  185. }
  186. break;
  187. case 'direct':
  188. abort(404);
  189. break;
  190. case 'draft':
  191. abort(404);
  192. break;
  193. default:
  194. abort(404);
  195. break;
  196. }
  197. }
  198. public function publicTimelineApi(Request $request)
  199. {
  200. $this->validate($request,[
  201. 'page' => 'nullable|integer|max:40',
  202. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  203. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  204. 'limit' => 'nullable|integer|max:30'
  205. ]);
  206. if(config('instance.timeline.local.is_public') == false && !Auth::check()) {
  207. abort(403, 'Authentication required.');
  208. }
  209. $page = $request->input('page');
  210. $min = $request->input('min_id');
  211. $max = $request->input('max_id');
  212. $limit = $request->input('limit') ?? 3;
  213. // $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
  214. // return Profile::whereIsPrivate(true)
  215. // ->orWhere('unlisted', true)
  216. // ->orWhere('status', '!=', null)
  217. // ->pluck('id');
  218. // });
  219. // if(Auth::check()) {
  220. // // $pid = Auth::user()->profile->id;
  221. // // $filters = UserFilter::whereUserId($pid)
  222. // // ->whereFilterableType('App\Profile')
  223. // // ->whereIn('filter_type', ['mute', 'block'])
  224. // // ->pluck('filterable_id')->toArray();
  225. // // $filtered = array_merge($private->toArray(), $filters);
  226. // $filtered = UserFilterService::filters(Auth::user()->profile_id);
  227. // } else {
  228. // // $filtered = $private->toArray();
  229. // $filtered = [];
  230. // }
  231. $filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
  232. if($min || $max) {
  233. $dir = $min ? '>' : '<';
  234. $id = $min ?? $max;
  235. $timeline = Status::select(
  236. 'id',
  237. 'uri',
  238. 'caption',
  239. 'rendered',
  240. 'profile_id',
  241. 'type',
  242. 'in_reply_to_id',
  243. 'reblog_of_id',
  244. 'is_nsfw',
  245. 'scope',
  246. 'local',
  247. 'reply_count',
  248. 'comments_disabled',
  249. 'place_id',
  250. 'created_at',
  251. 'updated_at'
  252. )->where('id', $dir, $id)
  253. ->with('profile', 'hashtags', 'mentions')
  254. ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  255. ->whereLocal(true)
  256. ->whereNotIn('profile_id', $filtered)
  257. ->whereVisibility('public')
  258. ->orderBy('created_at', 'desc')
  259. ->limit($limit)
  260. ->get();
  261. //->toSql();
  262. } else {
  263. $timeline = Status::select(
  264. 'id',
  265. 'uri',
  266. 'caption',
  267. 'rendered',
  268. 'profile_id',
  269. 'type',
  270. 'in_reply_to_id',
  271. 'reblog_of_id',
  272. 'is_nsfw',
  273. 'scope',
  274. 'local',
  275. 'reply_count',
  276. 'comments_disabled',
  277. 'created_at',
  278. 'place_id',
  279. 'updated_at'
  280. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  281. ->with('profile', 'hashtags', 'mentions')
  282. ->whereLocal(true)
  283. ->whereNotIn('profile_id', $filtered)
  284. ->whereVisibility('public')
  285. ->orderBy('created_at', 'desc')
  286. ->simplePaginate($limit);
  287. //->toSql();
  288. }
  289. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  290. $res = $this->fractal->createData($fractal)->toArray();
  291. // $res = $timeline;
  292. return response()->json($res);
  293. }
  294. public function homeTimelineApi(Request $request)
  295. {
  296. if(!Auth::check()) {
  297. return abort(403);
  298. }
  299. $this->validate($request,[
  300. 'page' => 'nullable|integer|max:40',
  301. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  302. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  303. 'limit' => 'nullable|integer|max:40'
  304. ]);
  305. $page = $request->input('page');
  306. $min = $request->input('min_id');
  307. $max = $request->input('max_id');
  308. $limit = $request->input('limit') ?? 3;
  309. // TODO: Use redis for timelines
  310. // $timeline = Timeline::build()->local();
  311. $pid = Auth::user()->profile->id;
  312. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  313. $following = Follower::whereProfileId($pid)->pluck('following_id');
  314. return $following->push($pid)->toArray();
  315. });
  316. // $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
  317. // return Profile::whereIsPrivate(true)
  318. // ->orWhere('unlisted', true)
  319. // ->orWhere('status', '!=', null)
  320. // ->pluck('id');
  321. // });
  322. // $private = $private->diff($following)->flatten();
  323. // $filters = UserFilter::whereUserId($pid)
  324. // ->whereFilterableType('App\Profile')
  325. // ->whereIn('filter_type', ['mute', 'block'])
  326. // ->pluck('filterable_id')->toArray();
  327. // $filtered = array_merge($private->toArray(), $filters);
  328. $filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
  329. if($min || $max) {
  330. $dir = $min ? '>' : '<';
  331. $id = $min ?? $max;
  332. $timeline = Status::select(
  333. 'id',
  334. 'uri',
  335. 'caption',
  336. 'rendered',
  337. 'profile_id',
  338. 'type',
  339. 'in_reply_to_id',
  340. 'reblog_of_id',
  341. 'is_nsfw',
  342. 'scope',
  343. 'local',
  344. 'reply_count',
  345. 'comments_disabled',
  346. 'place_id',
  347. 'created_at',
  348. 'updated_at'
  349. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  350. ->with('profile', 'hashtags', 'mentions')
  351. ->where('id', $dir, $id)
  352. ->whereIn('profile_id', $following)
  353. ->whereNotIn('profile_id', $filtered)
  354. ->whereIn('visibility',['public', 'unlisted', 'private'])
  355. ->orderBy('created_at', 'desc')
  356. ->limit($limit)
  357. ->get();
  358. } else {
  359. $timeline = Status::select(
  360. 'id',
  361. 'uri',
  362. 'caption',
  363. 'rendered',
  364. 'profile_id',
  365. 'type',
  366. 'in_reply_to_id',
  367. 'reblog_of_id',
  368. 'is_nsfw',
  369. 'scope',
  370. 'local',
  371. 'reply_count',
  372. 'comments_disabled',
  373. 'place_id',
  374. 'created_at',
  375. 'updated_at'
  376. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  377. ->with('profile', 'hashtags', 'mentions')
  378. ->whereIn('profile_id', $following)
  379. ->whereNotIn('profile_id', $filtered)
  380. ->whereIn('visibility',['public', 'unlisted', 'private'])
  381. ->orderBy('created_at', 'desc')
  382. ->simplePaginate($limit);
  383. }
  384. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  385. $res = $this->fractal->createData($fractal)->toArray();
  386. return response()->json($res);
  387. }
  388. public function networkTimelineApi(Request $request)
  389. {
  390. if(!Auth::check()) {
  391. return abort(403);
  392. }
  393. $this->validate($request,[
  394. 'page' => 'nullable|integer|max:40',
  395. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  396. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  397. 'limit' => 'nullable|integer|max:20'
  398. ]);
  399. $page = $request->input('page');
  400. $min = $request->input('min_id');
  401. $max = $request->input('max_id');
  402. $limit = $request->input('limit') ?? 3;
  403. // TODO: Use redis for timelines
  404. // $timeline = Timeline::build()->local();
  405. $pid = Auth::user()->profile->id;
  406. $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
  407. return Profile::whereIsPrivate(true)
  408. ->orWhere('unlisted', true)
  409. ->orWhere('status', '!=', null)
  410. ->pluck('id');
  411. });
  412. $filters = UserFilter::whereUserId($pid)
  413. ->whereFilterableType('App\Profile')
  414. ->whereIn('filter_type', ['mute', 'block'])
  415. ->pluck('filterable_id')->toArray();
  416. $filtered = array_merge($private->toArray(), $filters);
  417. if($min || $max) {
  418. $dir = $min ? '>' : '<';
  419. $id = $min ?? $max;
  420. $timeline = Status::select(
  421. 'id',
  422. 'uri',
  423. 'caption',
  424. 'rendered',
  425. 'profile_id',
  426. 'type',
  427. 'in_reply_to_id',
  428. 'reblog_of_id',
  429. 'is_nsfw',
  430. 'scope',
  431. 'local',
  432. 'reply_count',
  433. 'comments_disabled',
  434. 'created_at',
  435. 'updated_at'
  436. )->where('id', $dir, $id)
  437. ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  438. ->whereNotIn('profile_id', $filtered)
  439. ->whereNotNull('uri')
  440. ->whereNull('in_reply_to_id')
  441. ->whereNull('reblog_of_id')
  442. ->whereVisibility('public')
  443. ->latest()
  444. ->limit($limit)
  445. ->get();
  446. } else {
  447. $timeline = Status::select(
  448. 'id',
  449. 'uri',
  450. 'caption',
  451. 'rendered',
  452. 'profile_id',
  453. 'type',
  454. 'in_reply_to_id',
  455. 'reblog_of_id',
  456. 'is_nsfw',
  457. 'scope',
  458. 'local',
  459. 'reply_count',
  460. 'comments_disabled',
  461. 'created_at',
  462. 'updated_at'
  463. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  464. ->whereNotIn('profile_id', $filtered)
  465. ->whereNull('in_reply_to_id')
  466. ->whereNull('reblog_of_id')
  467. ->whereNotNull('uri')
  468. ->whereVisibility('public')
  469. ->latest()
  470. ->simplePaginate($limit);
  471. }
  472. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  473. $res = $this->fractal->createData($fractal)->toArray();
  474. return response()->json($res);
  475. }
  476. public function relationships(Request $request)
  477. {
  478. if(!Auth::check()) {
  479. return response()->json([]);
  480. }
  481. $this->validate($request, [
  482. 'id' => 'required|array|min:1|max:20',
  483. 'id.*' => 'required|integer'
  484. ]);
  485. $ids = collect($request->input('id'));
  486. $filtered = $ids->filter(function($v) {
  487. return $v != Auth::user()->profile->id;
  488. });
  489. $relations = Profile::whereNull('status')->findOrFail($filtered->all());
  490. $fractal = new Fractal\Resource\Collection($relations, new RelationshipTransformer());
  491. $res = $this->fractal->createData($fractal)->toArray();
  492. return response()->json($res);
  493. }
  494. public function account(Request $request, $id)
  495. {
  496. $profile = Profile::whereNull('status')->findOrFail($id);
  497. $resource = new Fractal\Resource\Item($profile, new AccountTransformer());
  498. $res = $this->fractal->createData($resource)->toArray();
  499. return response()->json($res);
  500. }
  501. public function accountFollowers(Request $request, $id)
  502. {
  503. abort_unless(Auth::check(), 403);
  504. $profile = Profile::with('user')->whereNull('status')->whereNull('domain')->findOrFail($id);
  505. if(Auth::id() != $profile->user_id && $profile->is_private || !$profile->user->settings->show_profile_followers) {
  506. return response()->json([]);
  507. }
  508. $followers = $profile->followers()->orderByDesc('followers.created_at')->paginate(10);
  509. $resource = new Fractal\Resource\Collection($followers, new AccountTransformer());
  510. $res = $this->fractal->createData($resource)->toArray();
  511. return response()->json($res);
  512. }
  513. public function accountFollowing(Request $request, $id)
  514. {
  515. abort_unless(Auth::check(), 403);
  516. $profile = Profile::with('user')->whereNull('status')->whereNull('domain')->findOrFail($id);
  517. if(Auth::id() != $profile->user_id && $profile->is_private || !$profile->user->settings->show_profile_following) {
  518. return response()->json([]);
  519. }
  520. $following = $profile->following()->orderByDesc('followers.created_at')->paginate(10);
  521. $resource = new Fractal\Resource\Collection($following, new AccountTransformer());
  522. $res = $this->fractal->createData($resource)->toArray();
  523. return response()->json($res);
  524. }
  525. public function accountStatuses(Request $request, $id)
  526. {
  527. $this->validate($request, [
  528. 'only_media' => 'nullable',
  529. 'pinned' => 'nullable',
  530. 'exclude_replies' => 'nullable',
  531. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  532. 'since_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  533. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  534. 'limit' => 'nullable|integer|min:1|max:24'
  535. ]);
  536. $profile = Profile::whereNull('status')->findOrFail($id);
  537. $limit = $request->limit ?? 9;
  538. $max_id = $request->max_id;
  539. $min_id = $request->min_id;
  540. $scope = $request->only_media == true ?
  541. ['photo', 'photo:album', 'video', 'video:album'] :
  542. ['photo', 'photo:album', 'video', 'video:album', 'share', 'reply'];
  543. if($profile->is_private) {
  544. if(!Auth::check()) {
  545. return response()->json([]);
  546. }
  547. $pid = Auth::user()->profile->id;
  548. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  549. $following = Follower::whereProfileId($pid)->pluck('following_id');
  550. return $following->push($pid)->toArray();
  551. });
  552. $visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : [];
  553. } else {
  554. if(Auth::check()) {
  555. $pid = Auth::user()->profile->id;
  556. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  557. $following = Follower::whereProfileId($pid)->pluck('following_id');
  558. return $following->push($pid)->toArray();
  559. });
  560. $visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
  561. } else {
  562. $visibility = ['public', 'unlisted'];
  563. }
  564. }
  565. $dir = $min_id ? '>' : '<';
  566. $id = $min_id ?? $max_id;
  567. $timeline = Status::select(
  568. 'id',
  569. 'uri',
  570. 'caption',
  571. 'rendered',
  572. 'profile_id',
  573. 'type',
  574. 'in_reply_to_id',
  575. 'reblog_of_id',
  576. 'is_nsfw',
  577. 'scope',
  578. 'local',
  579. 'created_at',
  580. 'updated_at'
  581. )->whereProfileId($profile->id)
  582. ->whereIn('type', $scope)
  583. ->whereLocal(true)
  584. ->whereNull('uri')
  585. ->where('id', $dir, $id)
  586. ->whereIn('visibility', $visibility)
  587. ->latest()
  588. ->limit($limit)
  589. ->get();
  590. $resource = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  591. $res = $this->fractal->createData($resource)->toArray();
  592. return response()->json($res);
  593. }
  594. }