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\Http\Controllers\Forum;
7
8use App\Models\Forum\Topic;
9use App\Models\Forum\TopicWatch;
10use Auth;
11
12class TopicWatchesController extends Controller
13{
14 public function __construct()
15 {
16 parent::__construct();
17
18 $this->middleware('auth');
19 }
20
21 public function update($topicId)
22 {
23 $topic = Topic::findOrFail($topicId);
24 $state = request('state');
25
26 if ($state !== 'not_watching') {
27 priv_check('ForumTopicWatch', $topic)->ensureCan();
28 }
29
30 $watch = TopicWatch::setState($topic, Auth::user(), $state);
31
32 switch (request('return')) {
33 case 'index':
34 return response([], 204);
35
36 default:
37 return ext_view('forum.topics.replace_watch_button', [
38 'topic' => $topic,
39 'state' => $watch,
40 ], 'js');
41 }
42 }
43}