PublicApiController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. 'likes_count',
  251. 'reblogs_count',
  252. 'created_at',
  253. 'updated_at'
  254. )->where('id', $dir, $id)
  255. ->with('profile', 'hashtags', 'mentions')
  256. ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  257. ->whereLocal(true)
  258. ->whereNotIn('profile_id', $filtered)
  259. ->whereVisibility('public')
  260. ->orderBy('created_at', 'desc')
  261. ->limit($limit)
  262. ->get();
  263. //->toSql();
  264. } else {
  265. $timeline = Status::select(
  266. 'id',
  267. 'uri',
  268. 'caption',
  269. 'rendered',
  270. 'profile_id',
  271. 'type',
  272. 'in_reply_to_id',
  273. 'reblog_of_id',
  274. 'is_nsfw',
  275. 'scope',
  276. 'local',
  277. 'reply_count',
  278. 'comments_disabled',
  279. 'created_at',
  280. 'place_id',
  281. 'likes_count',
  282. 'reblogs_count',
  283. 'updated_at'
  284. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  285. ->with('profile', 'hashtags', 'mentions')
  286. ->whereLocal(true)
  287. ->whereNotIn('profile_id', $filtered)
  288. ->whereVisibility('public')
  289. ->orderBy('created_at', 'desc')
  290. ->simplePaginate($limit);
  291. //->toSql();
  292. }
  293. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  294. $res = $this->fractal->createData($fractal)->toArray();
  295. // $res = $timeline;
  296. return response()->json($res);
  297. }
  298. public function homeTimelineApi(Request $request)
  299. {
  300. if(!Auth::check()) {
  301. return abort(403);
  302. }
  303. $this->validate($request,[
  304. 'page' => 'nullable|integer|max:40',
  305. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  306. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  307. 'limit' => 'nullable|integer|max:40'
  308. ]);
  309. $page = $request->input('page');
  310. $min = $request->input('min_id');
  311. $max = $request->input('max_id');
  312. $limit = $request->input('limit') ?? 3;
  313. // TODO: Use redis for timelines
  314. // $timeline = Timeline::build()->local();
  315. $pid = Auth::user()->profile->id;
  316. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  317. $following = Follower::whereProfileId($pid)->pluck('following_id');
  318. return $following->push($pid)->toArray();
  319. });
  320. // $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
  321. // return Profile::whereIsPrivate(true)
  322. // ->orWhere('unlisted', true)
  323. // ->orWhere('status', '!=', null)
  324. // ->pluck('id');
  325. // });
  326. // $private = $private->diff($following)->flatten();
  327. // $filters = UserFilter::whereUserId($pid)
  328. // ->whereFilterableType('App\Profile')
  329. // ->whereIn('filter_type', ['mute', 'block'])
  330. // ->pluck('filterable_id')->toArray();
  331. // $filtered = array_merge($private->toArray(), $filters);
  332. $filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
  333. if($min || $max) {
  334. $dir = $min ? '>' : '<';
  335. $id = $min ?? $max;
  336. $timeline = Status::select(
  337. 'id',
  338. 'uri',
  339. 'caption',
  340. 'rendered',
  341. 'profile_id',
  342. 'type',
  343. 'in_reply_to_id',
  344. 'reblog_of_id',
  345. 'is_nsfw',
  346. 'scope',
  347. 'local',
  348. 'reply_count',
  349. 'comments_disabled',
  350. 'place_id',
  351. 'likes_count',
  352. 'reblogs_count',
  353. 'created_at',
  354. 'updated_at'
  355. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  356. ->with('profile', 'hashtags', 'mentions')
  357. ->where('id', $dir, $id)
  358. ->whereIn('profile_id', $following)
  359. ->whereNotIn('profile_id', $filtered)
  360. ->whereIn('visibility',['public', 'unlisted', 'private'])
  361. ->orderBy('created_at', 'desc')
  362. ->limit($limit)
  363. ->get();
  364. } else {
  365. $timeline = Status::select(
  366. 'id',
  367. 'uri',
  368. 'caption',
  369. 'rendered',
  370. 'profile_id',
  371. 'type',
  372. 'in_reply_to_id',
  373. 'reblog_of_id',
  374. 'is_nsfw',
  375. 'scope',
  376. 'local',
  377. 'reply_count',
  378. 'comments_disabled',
  379. 'place_id',
  380. 'likes_count',
  381. 'reblogs_count',
  382. 'created_at',
  383. 'updated_at'
  384. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  385. ->with('profile', 'hashtags', 'mentions')
  386. ->whereIn('profile_id', $following)
  387. ->whereNotIn('profile_id', $filtered)
  388. ->whereIn('visibility',['public', 'unlisted', 'private'])
  389. ->orderBy('created_at', 'desc')
  390. ->simplePaginate($limit);
  391. }
  392. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  393. $res = $this->fractal->createData($fractal)->toArray();
  394. return response()->json($res);
  395. }
  396. public function networkTimelineApi(Request $request)
  397. {
  398. if(!Auth::check()) {
  399. return abort(403);
  400. }
  401. $this->validate($request,[
  402. 'page' => 'nullable|integer|max:40',
  403. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  404. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  405. 'limit' => 'nullable|integer|max:20'
  406. ]);
  407. $page = $request->input('page');
  408. $min = $request->input('min_id');
  409. $max = $request->input('max_id');
  410. $limit = $request->input('limit') ?? 3;
  411. // TODO: Use redis for timelines
  412. // $timeline = Timeline::build()->local();
  413. $pid = Auth::user()->profile->id;
  414. $private = Cache::remember('profiles:private', now()->addMinutes(1440), function() {
  415. return Profile::whereIsPrivate(true)
  416. ->orWhere('unlisted', true)
  417. ->orWhere('status', '!=', null)
  418. ->pluck('id');
  419. });
  420. $filters = UserFilter::whereUserId($pid)
  421. ->whereFilterableType('App\Profile')
  422. ->whereIn('filter_type', ['mute', 'block'])
  423. ->pluck('filterable_id')->toArray();
  424. $filtered = array_merge($private->toArray(), $filters);
  425. if($min || $max) {
  426. $dir = $min ? '>' : '<';
  427. $id = $min ?? $max;
  428. $timeline = Status::select(
  429. 'id',
  430. 'uri',
  431. 'caption',
  432. 'rendered',
  433. 'profile_id',
  434. 'type',
  435. 'in_reply_to_id',
  436. 'reblog_of_id',
  437. 'is_nsfw',
  438. 'scope',
  439. 'local',
  440. 'reply_count',
  441. 'comments_disabled',
  442. 'created_at',
  443. 'updated_at'
  444. )->where('id', $dir, $id)
  445. ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  446. ->whereNotIn('profile_id', $filtered)
  447. ->whereNotNull('uri')
  448. ->whereNull('in_reply_to_id')
  449. ->whereNull('reblog_of_id')
  450. ->whereVisibility('public')
  451. ->latest()
  452. ->limit($limit)
  453. ->get();
  454. } else {
  455. $timeline = Status::select(
  456. 'id',
  457. 'uri',
  458. 'caption',
  459. 'rendered',
  460. 'profile_id',
  461. 'type',
  462. 'in_reply_to_id',
  463. 'reblog_of_id',
  464. 'is_nsfw',
  465. 'scope',
  466. 'local',
  467. 'reply_count',
  468. 'comments_disabled',
  469. 'created_at',
  470. 'updated_at'
  471. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  472. ->whereNotIn('profile_id', $filtered)
  473. ->whereNull('in_reply_to_id')
  474. ->whereNull('reblog_of_id')
  475. ->whereNotNull('uri')
  476. ->whereVisibility('public')
  477. ->latest()
  478. ->simplePaginate($limit);
  479. }
  480. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  481. $res = $this->fractal->createData($fractal)->toArray();
  482. return response()->json($res);
  483. }
  484. public function relationships(Request $request)
  485. {
  486. if(!Auth::check()) {
  487. return response()->json([]);
  488. }
  489. $this->validate($request, [
  490. 'id' => 'required|array|min:1|max:20',
  491. 'id.*' => 'required|integer'
  492. ]);
  493. $ids = collect($request->input('id'));
  494. $filtered = $ids->filter(function($v) {
  495. return $v != Auth::user()->profile->id;
  496. });
  497. $relations = Profile::whereNull('status')->findOrFail($filtered->all());
  498. $fractal = new Fractal\Resource\Collection($relations, new RelationshipTransformer());
  499. $res = $this->fractal->createData($fractal)->toArray();
  500. return response()->json($res);
  501. }
  502. public function account(Request $request, $id)
  503. {
  504. $profile = Profile::whereNull('status')->findOrFail($id);
  505. $resource = new Fractal\Resource\Item($profile, new AccountTransformer());
  506. $res = $this->fractal->createData($resource)->toArray();
  507. return response()->json($res);
  508. }
  509. public function accountFollowers(Request $request, $id)
  510. {
  511. abort_unless(Auth::check(), 403);
  512. $profile = Profile::with('user')->whereNull('status')->whereNull('domain')->findOrFail($id);
  513. if(Auth::id() != $profile->user_id && $profile->is_private || !$profile->user->settings->show_profile_followers) {
  514. return response()->json([]);
  515. }
  516. $followers = $profile->followers()->orderByDesc('followers.created_at')->paginate(10);
  517. $resource = new Fractal\Resource\Collection($followers, new AccountTransformer());
  518. $res = $this->fractal->createData($resource)->toArray();
  519. return response()->json($res);
  520. }
  521. public function accountFollowing(Request $request, $id)
  522. {
  523. abort_unless(Auth::check(), 403);
  524. $profile = Profile::with('user')->whereNull('status')->whereNull('domain')->findOrFail($id);
  525. if(Auth::id() != $profile->user_id && $profile->is_private || !$profile->user->settings->show_profile_following) {
  526. return response()->json([]);
  527. }
  528. $following = $profile->following()->orderByDesc('followers.created_at')->paginate(10);
  529. $resource = new Fractal\Resource\Collection($following, new AccountTransformer());
  530. $res = $this->fractal->createData($resource)->toArray();
  531. return response()->json($res);
  532. }
  533. public function accountStatuses(Request $request, $id)
  534. {
  535. $this->validate($request, [
  536. 'only_media' => 'nullable',
  537. 'pinned' => 'nullable',
  538. 'exclude_replies' => 'nullable',
  539. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  540. 'since_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  541. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  542. 'limit' => 'nullable|integer|min:1|max:24'
  543. ]);
  544. $profile = Profile::whereNull('status')->findOrFail($id);
  545. $limit = $request->limit ?? 9;
  546. $max_id = $request->max_id;
  547. $min_id = $request->min_id;
  548. $scope = $request->only_media == true ?
  549. ['photo', 'photo:album', 'video', 'video:album'] :
  550. ['photo', 'photo:album', 'video', 'video:album', 'share', 'reply'];
  551. if($profile->is_private) {
  552. if(!Auth::check()) {
  553. return response()->json([]);
  554. }
  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'] : [];
  561. } else {
  562. if(Auth::check()) {
  563. $pid = Auth::user()->profile->id;
  564. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  565. $following = Follower::whereProfileId($pid)->pluck('following_id');
  566. return $following->push($pid)->toArray();
  567. });
  568. $visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
  569. } else {
  570. $visibility = ['public', 'unlisted'];
  571. }
  572. }
  573. $dir = $min_id ? '>' : '<';
  574. $id = $min_id ?? $max_id;
  575. $timeline = Status::select(
  576. 'id',
  577. 'uri',
  578. 'caption',
  579. 'rendered',
  580. 'profile_id',
  581. 'type',
  582. 'in_reply_to_id',
  583. 'reblog_of_id',
  584. 'is_nsfw',
  585. 'likes_count',
  586. 'reblogs_count',
  587. 'scope',
  588. 'local',
  589. 'created_at',
  590. 'updated_at'
  591. )->whereProfileId($profile->id)
  592. ->whereIn('type', $scope)
  593. ->whereLocal(true)
  594. ->whereNull('uri')
  595. ->where('id', $dir, $id)
  596. ->whereIn('visibility', $visibility)
  597. ->latest()
  598. ->limit($limit)
  599. ->get();
  600. $resource = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  601. $res = $this->fractal->createData($resource)->toArray();
  602. return response()->json($res);
  603. }
  604. }