the browser-facing portion of osu!
at master 60 lines 1.6 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; 7 8use App\Libraries\Notification\BatchIdentities; 9use App\Models\UserNotification; 10use Illuminate\Bus\Queueable; 11use Illuminate\Contracts\Queue\ShouldQueue; 12use Illuminate\Queue\InteractsWithQueue; 13 14/** 15 * Checks access permission of specified topic for all currently watching users. 16 */ 17class UpdateUserForumTopicFollows implements ShouldQueue 18{ 19 use InteractsWithQueue, Queueable; 20 21 protected $topic; 22 23 /** 24 * Create a new job instance. 25 * 26 * @return void 27 */ 28 public function __construct($topic) 29 { 30 $this->topic = $topic; 31 } 32 33 /** 34 * Execute the job. 35 * 36 * @return void 37 */ 38 public function handle() 39 { 40 foreach ($this->topic->watches()->with(['user', 'topic.forum'])->get() as $watch) { 41 $user = $watch->user; 42 $topic = $watch->topic; 43 44 if ($user === null || $topic === null || priv_check_user($user, 'ForumTopicWatch', $topic)->can()) { 45 continue; 46 } 47 48 $watch->delete(); 49 UserNotification::batchDestroy( 50 $user->getKey(), 51 BatchIdentities::fromParams(['identities' => [ 52 [ 53 'object_id' => $topic->getKey(), 54 'object_type' => $topic->getMorphClass(), 55 ], 56 ]]) 57 ); 58 } 59 } 60}