You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Twitter;
  5. use App\Tweet;
  6. use App\Events\NewTweetEvent, App\Events\TweetClaimedEvent;
  7. class DashboardController extends Controller
  8. {
  9. /**
  10. * Create a new controller instance.
  11. *
  12. * @return void
  13. */
  14. public function __construct()
  15. {
  16. $this->middleware('auth');
  17. }
  18. /**
  19. * Show the application dashboard.
  20. *
  21. * @return \Illuminate\Http\Response
  22. */
  23. public function index()
  24. {
  25. return view('dashboard', [
  26. ]);
  27. }
  28. public function queue() {
  29. Tweet::claimed_timeout();
  30. $tweets = Tweet::queued()->get();
  31. $queue = [];
  32. foreach($tweets as $tweet) {
  33. $queue[] = new NewTweetEvent($tweet);
  34. }
  35. return response()->json(['queue'=>$queue]);
  36. }
  37. public function ping() {
  38. Tweet::claimed_timeout();
  39. return response()->json(['result'=>'ok']);
  40. }
  41. public function claim_tweet(Request $request) {
  42. $tweet = Tweet::where('id', $request->input('tweet_id'))->first();
  43. if($tweet) {
  44. if($request->input('status') == 'unclaimed') {
  45. $tweet->claimed_at = null;
  46. $tweet->save();
  47. event(new NewTweetEvent($tweet));
  48. } else {
  49. $tweet->claimed_at = date('Y-m-d H:i:s');
  50. $tweet->save();
  51. // Broadcast that this tweet was claimed
  52. event(new TweetClaimedEvent($tweet));
  53. }
  54. }
  55. return response()->json(['result'=>'ok']);
  56. }
  57. }