AdminNewReport.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Mail;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Mail\Mailable;
  6. use Illuminate\Mail\Mailables\Content;
  7. use Illuminate\Mail\Mailables\Envelope;
  8. use Illuminate\Queue\SerializesModels;
  9. use App\Services\AccountService;
  10. use App\Services\StatusService;
  11. class AdminNewReport extends Mailable
  12. {
  13. use Queueable, SerializesModels;
  14. public $report;
  15. /**
  16. * Create a new message instance.
  17. *
  18. * @return void
  19. */
  20. public function __construct($report)
  21. {
  22. $this->report = $report;
  23. }
  24. /**
  25. * Get the message envelope.
  26. *
  27. * @return \Illuminate\Mail\Mailables\Envelope
  28. */
  29. public function envelope()
  30. {
  31. $type = $this->report->type;
  32. $id = $this->report->id;
  33. $object_type = last(explode("\\", $this->report->object_type));
  34. return new Envelope(
  35. subject: '[' . config('pixelfed.domain.app') . '] ' . $object_type . ' Report (Ref: report-' . $id . '-' . $type . ')',
  36. );
  37. }
  38. /**
  39. * Get the message content definition.
  40. *
  41. * @return \Illuminate\Mail\Mailables\Content
  42. */
  43. public function content()
  44. {
  45. $report = $this->report;
  46. $object_type = last(explode("\\", $this->report->object_type));
  47. $reporter = AccountService::get($report->profile_id, true);
  48. $reported = AccountService::get($report->reported_profile_id, true);
  49. $title = 'New ' . $object_type . ' Report (#' . $report->id . ')';
  50. $reportUrl = url('/i/admin/reports/show/' . $report->id . '?ref=email');
  51. $data = [
  52. 'report' => $report,
  53. 'object_type' => $object_type,
  54. 'title' => $title,
  55. 'reporter' => $reporter,
  56. 'reported' => $reported,
  57. 'url' => $reportUrl,
  58. 'message' => 'You have a new moderation report.'
  59. ];
  60. if($object_type === 'Status') {
  61. $data['reported_status'] = StatusService::get($report['object_id'], false);
  62. if($reporter && $reported) {
  63. $data['message'] = '<a href="' . url('/i/web/profile/' . $reporter['id']) . '">@' .
  64. $reporter['acct'] . '</a> reported a post by <a href="' . url('/i/web/profile/' . $reported['id']) .
  65. '">@' . $reported['acct'] . '</a> as ' . $report->type . '.';
  66. }
  67. }
  68. if($object_type === 'Profile') {
  69. if($reporter && $reported) {
  70. $data['message'] = '<a href="' . url('/i/web/profile/' . $reporter['id']) . '">@' .
  71. $reporter['acct'] . '</a> reported <a href="' . url('/i/web/profile/' . $reported['id']) .
  72. '">@' . $reported['acct'] . '</a>\'s profile as ' . $report->type . '.';
  73. }
  74. }
  75. return new Content(
  76. markdown: 'emails.admin.new_report',
  77. with: $data
  78. );
  79. }
  80. /**
  81. * Get the attachments for the message.
  82. *
  83. * @return array
  84. */
  85. public function attachments()
  86. {
  87. return [];
  88. }
  89. }