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