the browser-facing portion of osu!
at master 70 lines 2.1 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\Achievement; 9use App\Models\Notification; 10use App\Models\User; 11 12class UserAchievementUnlock extends BroadcastNotificationBase 13{ 14 // Mainly to ensure client always getting the event. 15 // Also it probably doesn't really make sense to mail the event 16 // in the first place. 17 const DELIVERY_MODE_DEFAULTS = ['mail' => false, 'push' => true]; 18 19 protected $achievement; 20 21 public static function getMailGroupingKey(Notification $notification): string 22 { 23 $base = parent::getMailGroupingKey($notification); 24 25 return "{$base}-{$notification->details['achievement_id']}-{$notification->source_user_id}"; 26 } 27 28 public static function getMailLink(Notification $notification): string 29 { 30 return route('users.show', [ 31 'mode' => $notification->details['achievement_mode'] ?? null, // might not be set in old notifications. 32 'user' => $notification->details['user_id'], 33 ]).'#medals'; 34 } 35 36 public function __construct(Achievement $achievement, User $source) 37 { 38 parent::__construct($source); 39 40 $this->achievement = $achievement; 41 } 42 43 public function getDetails(): array 44 { 45 return [ 46 'achievement_id' => $this->achievement->getKey(), 47 'achievement_mode' => $this->achievement->mode, 48 'cover_url' => $this->achievement->iconUrl(), 49 'slug' => $this->achievement->slug, 50 'title' => $this->achievement->name, 51 'description' => $this->achievement->description, 52 'user_id' => $this->source->getKey(), 53 ]; 54 } 55 56 public function getListeningUserIds(): array 57 { 58 return [$this->source->getKey()]; 59 } 60 61 public function getNotifiable() 62 { 63 return $this->source; 64 } 65 66 public function getReceiverIds(): array 67 { 68 return $this->getListeningUserIds(); 69 } 70}