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.

61 lines
1.4 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 claim_tweet(Request $request) {
  38. $tweet = Tweet::where('id', $request->input('tweet_id'))->first();
  39. if($tweet) {
  40. if($request->input('status') == 'unclaimed') {
  41. $tweet->claimed_at = null;
  42. $tweet->save();
  43. event(new NewTweetEvent($tweet));
  44. } else {
  45. $tweet->claimed_at = date('Y-m-d H:i:s');
  46. $tweet->save();
  47. // Broadcast that this tweet was claimed
  48. event(new TweetClaimedEvent($tweet));
  49. }
  50. }
  51. return response()->json(['result'=>'ok']);
  52. }
  53. }