PublicApiController.php 25 KB

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