the browser-facing portion of osu!
at master 77 lines 2.0 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Jobs\Notifications; 7 8use App\Models\Forum\Post; 9use App\Models\Notification; 10use App\Models\User; 11use App\Models\UserNotificationOption; 12 13class ForumTopicReply extends BroadcastNotificationBase 14{ 15 const NOTIFICATION_OPTION_NAME = UserNotificationOption::FORUM_TOPIC_REPLY; 16 17 protected $post; 18 19 public static function getMailLink(Notification $notification): string 20 { 21 // link to start=unread since all updates get collapsed into one line. 22 return route('forum.topics.show', ['start' => 'unread', 'topic' => $notification->notifiable_id]); 23 } 24 25 /** 26 * {@inheritdoc} 27 */ 28 public static function shouldSendMail(Notification $notification, $watches, $time): bool 29 { 30 $watch = $watches['topics'][$notification->notifiable_id] ?? null; 31 if ($watch === null) { 32 return false; 33 } 34 35 // make the model dirty so UserNotificationDigest job can batch update. 36 $watch->notify_status = true; 37 38 return true; 39 } 40 41 public function __construct(Post $post, User $source) 42 { 43 parent::__construct($source); 44 45 $this->post = $post; 46 } 47 48 public function getDetails(): array 49 { 50 return [ 51 'title' => $this->post->topic->topic_title, 52 'post_id' => $this->post->getKey(), 53 'cover_url' => $this->post->topic->cover?->file()->url(), 54 ]; 55 } 56 57 public function getListeningUserIds(): array 58 { 59 return $this->post 60 ->topic 61 ->watches() 62 ->where('mail', true) 63 ->where('user_id', '<>', $this->source->getKey()) 64 ->pluck('user_id') 65 ->all(); 66 } 67 68 public function getNotifiable() 69 { 70 return $this->post->topic; 71 } 72 73 public function getTimestamp() 74 { 75 return $this->post->post_time; 76 } 77}