StatusObserver.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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(!in_array($status->scope, ['public', 'unlisted', 'private'])) {
  37. return;
  38. }
  39. if(config('instance.timeline.home.cached')) {
  40. Cache::forget('pf:timelines:home:' . $status->profile_id);
  41. }
  42. if(in_array($status->scope, ['public', 'unlisted']) && in_array($status->type, ['photo', 'photo:album', 'video'])) {
  43. ProfileStatusService::add($status->profile_id, $status->id);
  44. }
  45. }
  46. /**
  47. * Handle the Status "deleted" event.
  48. *
  49. * @param \App\Status $status
  50. * @return void
  51. */
  52. public function deleted(Status $status)
  53. {
  54. if(!in_array($status->scope, ['public', 'unlisted', 'private'])) {
  55. return;
  56. }
  57. if(config('instance.timeline.home.cached')) {
  58. Cache::forget('pf:timelines:home:' . $status->profile_id);
  59. }
  60. ProfileStatusService::delete($status->profile_id, $status->id);
  61. if($status->uri == null) {
  62. ImportPost::whereProfileId($status->profile_id)->whereStatusId($status->id)->delete();
  63. ImportService::clearImportedFiles($status->profile_id);
  64. }
  65. if(config('exp.cached_home_timeline')) {
  66. if($status->uri) {
  67. FeedRemoveRemotePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
  68. } else {
  69. FeedRemovePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
  70. }
  71. }
  72. }
  73. /**
  74. * Handle the Status "restored" event.
  75. *
  76. * @param \App\Status $status
  77. * @return void
  78. */
  79. public function restored(Status $status)
  80. {
  81. //
  82. }
  83. /**
  84. * Handle the Status "force deleted" event.
  85. *
  86. * @param \App\Status $status
  87. * @return void
  88. */
  89. public function forceDeleted(Status $status)
  90. {
  91. //
  92. }
  93. }