StatusObserver.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Observers;
  3. use App\Status;
  4. use App\Services\ProfileStatusService;
  5. use Cache;
  6. use App\Models\ImportPost;
  7. use App\Services\ImportService;
  8. use App\Jobs\HomeFeedPipeline\FeedRemovePipeline;
  9. use App\Jobs\HomeFeedPipeline\FeedRemoveRemotePipeline;
  10. class StatusObserver
  11. {
  12. /**
  13. * Handle events after all transactions are committed.
  14. *
  15. * @var bool
  16. */
  17. public $afterCommit = true;
  18. /**
  19. * Handle the Status "created" event.
  20. *
  21. * @param \App\Status $status
  22. * @return void
  23. */
  24. public function created(Status $status)
  25. {
  26. //
  27. }
  28. /**
  29. * Handle the Status "updated" event.
  30. *
  31. * @param \App\Status $status
  32. * @return void
  33. */
  34. public function updated(Status $status)
  35. {
  36. if(config('instance.timeline.home.cached')) {
  37. Cache::forget('pf:timelines:home:' . $status->profile_id);
  38. }
  39. if(in_array($status->scope, ['public', 'unlisted']) && in_array($status->type, ['photo', 'photo:album', 'video'])) {
  40. ProfileStatusService::add($status->profile_id, $status->id);
  41. }
  42. }
  43. /**
  44. * Handle the Status "deleted" event.
  45. *
  46. * @param \App\Status $status
  47. * @return void
  48. */
  49. public function deleted(Status $status)
  50. {
  51. if(config('instance.timeline.home.cached')) {
  52. Cache::forget('pf:timelines:home:' . $status->profile_id);
  53. }
  54. ProfileStatusService::delete($status->profile_id, $status->id);
  55. if($status->uri == null) {
  56. ImportPost::whereProfileId($status->profile_id)->whereStatusId($status->id)->delete();
  57. ImportService::clearImportedFiles($status->profile_id);
  58. }
  59. if(config('exp.cached_home_timeline')) {
  60. if($status->uri) {
  61. FeedRemoveRemotePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
  62. } else {
  63. FeedRemovePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
  64. }
  65. }
  66. }
  67. /**
  68. * Handle the Status "restored" event.
  69. *
  70. * @param \App\Status $status
  71. * @return void
  72. */
  73. public function restored(Status $status)
  74. {
  75. //
  76. }
  77. /**
  78. * Handle the Status "force deleted" event.
  79. *
  80. * @param \App\Status $status
  81. * @return void
  82. */
  83. public function forceDeleted(Status $status)
  84. {
  85. //
  86. }
  87. }