the browser-facing portion of osu!
at master 73 lines 2.5 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\Libraries\BeatmapsetDiscussion\Review; 9use App\Models\BeatmapDiscussion; 10use App\Models\Notification; 11use App\Models\User; 12use App\Models\UserNotificationOption; 13 14class BeatmapsetDiscussionReviewNew extends BroadcastNotificationBase 15{ 16 const NOTIFICATION_OPTION_NAME = UserNotificationOption::BEATMAPSET_MODDING; 17 18 protected $beatmapsetDiscussion; 19 20 public static function getBaseKey(Notification $notification): string 21 { 22 return "{$notification->notifiable_type}.{$notification->category}.beatmapset_discussion_post_new"; 23 } 24 25 public static function getMailLink(Notification $notification): string 26 { 27 return route('beatmapsets.discussion', ['beatmapset' => $notification->notifiable_id]).'#/'.$notification->details['discussion_id']; 28 } 29 30 public function __construct(BeatmapDiscussion $beatmapsetDiscussion, User $source) 31 { 32 parent::__construct($source); 33 34 $this->beatmapsetDiscussion = $beatmapsetDiscussion; 35 } 36 37 public function getDetails(): array 38 { 39 $beatmapset = $this->beatmapsetDiscussion->beatmapset; 40 $stats = Review::getStats(json_decode($this->beatmapsetDiscussion->startingPost->message, true)); 41 42 return [ 43 'title' => $beatmapset->title, 44 'title_unicode' => $beatmapset->title_unicode, 45 'post_id' => $this->beatmapsetDiscussion->startingPost->getKey(), 46 'discussion_id' => $this->beatmapsetDiscussion->getKey(), 47 'beatmap_id' => $this->beatmapsetDiscussion->beatmap_id, 48 'cover_url' => $beatmapset->coverURL('card'), 49 'embeds' => [ 50 'suggestions' => $stats['suggestions'], 51 'problems' => $stats['problems'], 52 'praises' => $stats['praises'], 53 ], 54 ]; 55 } 56 57 public function getListeningUserIds(): array 58 { 59 return $this->beatmapsetDiscussion->beatmapset->watches()->pluck('user_id')->all(); 60 } 61 62 public function getNotifiable() 63 { 64 return $this->beatmapsetDiscussion->beatmapset; 65 } 66 67 public function handle() 68 { 69 $this->beatmapsetDiscussion->beatmapset->watches()->update(['last_notified' => $this->getTimestamp()]); 70 71 parent::handle(); 72 } 73}