+2
-7
app/Http/Controllers/Forum/TopicsController.php
+2
-7
app/Http/Controllers/Forum/TopicsController.php
···
6
6
namespace App\Http\Controllers\Forum;
7
7
8
8
use App\Exceptions\ModelNotSavedException;
9
-
use App\Libraries\ForumUpdateNotifier;
9
+
use App\Jobs\Notifications\ForumTopicReply;
10
10
use App\Libraries\NewForumTopic;
11
11
use App\Models\Forum\FeatureVote;
12
12
use App\Models\Forum\Forum;
···
182
182
$firstPostPosition = $topic->postPosition($post->post_id);
183
183
184
184
$post->markRead(Auth::user());
185
-
ForumUpdateNotifier::onReply([
186
-
'topic' => $topic,
187
-
'post' => $post,
188
-
'user' => Auth::user(),
189
-
]);
185
+
(new ForumTopicReply($post, auth()->user()))->dispatch();
190
186
191
187
return ext_view('forum.topics._posts', compact('posts', 'firstPostPosition', 'topic'));
192
188
}
···
378
374
379
375
$post = $topic->posts->last();
380
376
$post->markRead($user);
381
-
ForumUpdateNotifier::onNew(['topic' => $topic, 'post' => $post, 'user' => $user]);
382
377
383
378
return ujs_redirect(route('forum.topics.show', $topic));
384
379
}
-122
app/Jobs/NotifyForumUpdateSlack.php
-122
app/Jobs/NotifyForumUpdateSlack.php
···
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
-
6
-
namespace App\Jobs;
7
-
8
-
use Illuminate\Bus\Queueable;
9
-
use Illuminate\Contracts\Queue\ShouldQueue;
10
-
use Illuminate\Queue\SerializesModels;
11
-
use Slack;
12
-
13
-
class NotifyForumUpdateSlack implements ShouldQueue
14
-
{
15
-
use Queueable, SerializesModels;
16
-
17
-
public $topic;
18
-
public $post;
19
-
public $user;
20
-
public $prefix;
21
-
public $message;
22
-
23
-
public function __construct($data, $type)
24
-
{
25
-
$this->topic = $data['topic'];
26
-
$this->post = $data['post'];
27
-
$this->user = $data['user'];
28
-
29
-
switch ($type) {
30
-
case 'new':
31
-
$this->message = 'A new topic has been created at watched forum';
32
-
$this->prefix = 'New topic';
33
-
break;
34
-
case 'reply':
35
-
$this->message = 'A watched topic has been replied to';
36
-
$this->prefix = 'Reply';
37
-
break;
38
-
}
39
-
}
40
-
41
-
public function dispatchIfNeeded()
42
-
{
43
-
if (!$this->shouldNotify()) {
44
-
return;
45
-
}
46
-
47
-
return dispatch($this);
48
-
}
49
-
50
-
public function handle()
51
-
{
52
-
if ($this->topic === null || $this->post === null || $this->user === null) {
53
-
return;
54
-
}
55
-
56
-
// FIXME: travis explodes without this
57
-
if (app()->runningUnitTests()) {
58
-
return;
59
-
}
60
-
61
-
return Slack::to('dev')
62
-
->attach([
63
-
'color' => $this->notifyColour(),
64
-
'fallback' => $this->message,
65
-
'text' => $this->post->post_text,
66
-
])
67
-
->send($this->mainMessage());
68
-
}
69
-
70
-
private function shouldNotify()
71
-
{
72
-
return in_array($this->topic->getKey(), config('osu.forum.slack_watch.topic_ids'), true) ||
73
-
in_array($this->topic->forum_id, config('osu.forum.slack_watch.forum_ids'), true);
74
-
}
75
-
76
-
private function replyCommand()
77
-
{
78
-
$topicHash = base62_encode($this->topic->topic_id);
79
-
80
-
return "/msg #support !reply {$topicHash} <text>";
81
-
}
82
-
83
-
private function notifyColour()
84
-
{
85
-
if ($this->isFromSupport()) {
86
-
return 'good';
87
-
} elseif ($this->topic->topic_poster === $this->user->user_id) {
88
-
return 'warning';
89
-
} else {
90
-
return 'danger';
91
-
}
92
-
}
93
-
94
-
private function mainMessage()
95
-
{
96
-
$user = $this->userText();
97
-
$url = post_url($this->post->topic_id, $this->post->post_id);
98
-
$title = $this->topic->topic_title;
99
-
$command = $this->replyCommand();
100
-
$prefix = $this->prefix;
101
-
102
-
return "{$prefix}: <{$url}|{$title}> by {$user} `{$command}`";
103
-
}
104
-
105
-
private function isFromSupport()
106
-
{
107
-
return $this->user->isAdmin() || $this->user->isDev();
108
-
}
109
-
110
-
private function userText()
111
-
{
112
-
$suffix = '';
113
-
if ($this->isFromSupport()) {
114
-
$suffix = ' (Support Team)';
115
-
} elseif ($this->post->post_id !== $this->topic->topic_first_post_id &&
116
-
$this->topic->topic_poster === $this->user->user_id) {
117
-
$suffix = ' (OP)';
118
-
}
119
-
120
-
return $this->user->username.$suffix;
121
-
}
122
-
}
-24
app/Libraries/ForumUpdateNotifier.php
-24
app/Libraries/ForumUpdateNotifier.php
···
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
-
6
-
namespace App\Libraries;
7
-
8
-
use App\Jobs\Notifications\ForumTopicReply;
9
-
use App\Jobs\NotifyForumUpdateSlack;
10
-
11
-
class ForumUpdateNotifier
12
-
{
13
-
public static function onNew($data)
14
-
{
15
-
(new NotifyForumUpdateSlack($data, 'new'))->dispatchIfNeeded();
16
-
}
17
-
18
-
public static function onReply($data)
19
-
{
20
-
(new ForumTopicReply($data['post'], $data['user']))->dispatch();
21
-
22
-
(new NotifyForumUpdateSlack($data, 'reply'))->dispatchIfNeeded();
23
-
}
24
-
}
-5
composer.json
-5
composer.json
···
11
11
"repositories": [
12
12
{
13
13
"type": "vcs",
14
-
"url": "https://github.com/nanaya/slack-php"
15
-
},
16
-
{
17
-
"type": "vcs",
18
14
"url": "https://github.com/nanaya/xsolla-sdk-php"
19
15
}
20
16
],
···
39
35
"league/flysystem-aws-s3-v3": "*",
40
36
"league/fractal": "*",
41
37
"league/html-to-markdown": "*",
42
-
"maknz/slack": "dev-laravel-any",
43
38
"mariuzzo/laravel-js-localization": "*",
44
39
"mpociot/laravel-apidoc-generator": "*",
45
40
"paypal/rest-api-sdk-php": "*",
+24
-77
composer.lock
+24
-77
composer.lock
···
4
4
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
5
"This file is @generated automatically"
6
6
],
7
-
"content-hash": "ef0fdf25b31794ec636428dc9d1635e8",
7
+
"content-hash": "4ddecf6dfc12f377b4abb2d812e2bdbf",
8
8
"packages": [
9
9
{
10
10
"name": "anhskohbo/no-captcha",
···
297
297
"authors": [
298
298
{
299
299
"name": "Alex Corley",
300
-
"email": "anthroprose@gmail.com",
301
-
"role": "Developer"
300
+
"role": "Developer",
301
+
"email": "anthroprose@gmail.com"
302
302
},
303
303
{
304
304
"name": "Datadog",
305
-
"email": "dev@datadoghq.com",
306
-
"role": "Developer"
305
+
"role": "Developer",
306
+
"email": "dev@datadoghq.com"
307
307
}
308
308
],
309
309
"description": "This is an extremely simple PHP datadogstatsd client",
···
3079
3079
"time": "2019-07-13T18:58:26+00:00"
3080
3080
},
3081
3081
{
3082
-
"name": "maknz/slack",
3083
-
"version": "dev-laravel-any",
3084
-
"source": {
3085
-
"type": "git",
3086
-
"url": "https://github.com/nanaya/slack-php.git",
3087
-
"reference": "2f8534e23ffd5d6255f347f61a94c40a17029f42"
3088
-
},
3089
-
"dist": {
3090
-
"type": "zip",
3091
-
"url": "https://api.github.com/repos/nanaya/slack-php/zipball/2f8534e23ffd5d6255f347f61a94c40a17029f42",
3092
-
"reference": "2f8534e23ffd5d6255f347f61a94c40a17029f42",
3093
-
"shasum": ""
3094
-
},
3095
-
"require": {
3096
-
"ext-mbstring": "*",
3097
-
"guzzlehttp/guzzle": "~6.0|~5.0|~4.0",
3098
-
"php": ">=5.4.0"
3099
-
},
3100
-
"require-dev": {
3101
-
"mockery/mockery": "0.9.*",
3102
-
"phpunit/phpunit": "4.2.*"
3103
-
},
3104
-
"suggest": {
3105
-
"illuminate/support": "Required for Laravel support"
3106
-
},
3107
-
"type": "library",
3108
-
"autoload": {
3109
-
"psr-4": {
3110
-
"Maknz\\Slack\\": "src/"
3111
-
}
3112
-
},
3113
-
"license": [
3114
-
"BSD-2-Clause"
3115
-
],
3116
-
"authors": [
3117
-
{
3118
-
"name": "maknz",
3119
-
"email": "github@mak.geek.nz"
3120
-
}
3121
-
],
3122
-
"description": "A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax. Includes Laravel support out of the box.",
3123
-
"keywords": [
3124
-
"laravel",
3125
-
"slack"
3126
-
],
3127
-
"support": {
3128
-
"source": "https://github.com/nanaya/slack-php/tree/laravel-any"
3129
-
},
3130
-
"time": "2019-09-27T02:54:26+00:00"
3131
-
},
3132
-
{
3133
3082
"name": "mariuzzo/laravel-js-localization",
3134
3083
"version": "v1.5.0",
3135
3084
"source": {
···
7897
7846
"version": "v0.8.1",
7898
7847
"source": {
7899
7848
"type": "git",
7900
-
"url": "https://github.com/tightenco/ziggy.git",
7849
+
"url": "https://github.com/tighten/ziggy.git",
7901
7850
"reference": "4c4b29bc658153f0771b0a145173ce83a7b6b885"
7902
7851
},
7903
7852
"dist": {
7904
7853
"type": "zip",
7905
-
"url": "https://api.github.com/repos/tightenco/ziggy/zipball/4c4b29bc658153f0771b0a145173ce83a7b6b885",
7854
+
"url": "https://api.github.com/repos/tighten/ziggy/zipball/4c4b29bc658153f0771b0a145173ce83a7b6b885",
7906
7855
"reference": "4c4b29bc658153f0771b0a145173ce83a7b6b885",
7907
7856
"shasum": ""
7908
7857
},
···
8727
8676
"authors": [
8728
8677
{
8729
8678
"name": "Arne Blankerts",
8730
-
"email": "arne@blankerts.de",
8731
-
"role": "Developer"
8679
+
"role": "Developer",
8680
+
"email": "arne@blankerts.de"
8732
8681
},
8733
8682
{
8734
8683
"name": "Sebastian Heuer",
8735
-
"email": "sebastian@phpeople.de",
8736
-
"role": "Developer"
8684
+
"role": "Developer",
8685
+
"email": "sebastian@phpeople.de"
8737
8686
},
8738
8687
{
8739
8688
"name": "Sebastian Bergmann",
8740
-
"email": "sebastian@phpunit.de",
8741
-
"role": "Developer"
8689
+
"role": "Developer",
8690
+
"email": "sebastian@phpunit.de"
8742
8691
}
8743
8692
],
8744
8693
"description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)",
···
8774
8723
"authors": [
8775
8724
{
8776
8725
"name": "Arne Blankerts",
8777
-
"email": "arne@blankerts.de",
8778
-
"role": "Developer"
8726
+
"role": "Developer",
8727
+
"email": "arne@blankerts.de"
8779
8728
},
8780
8729
{
8781
8730
"name": "Sebastian Heuer",
8782
-
"email": "sebastian@phpeople.de",
8783
-
"role": "Developer"
8731
+
"role": "Developer",
8732
+
"email": "sebastian@phpeople.de"
8784
8733
},
8785
8734
{
8786
8735
"name": "Sebastian Bergmann",
8787
-
"email": "sebastian@phpunit.de",
8788
-
"role": "Developer"
8736
+
"role": "Developer",
8737
+
"email": "sebastian@phpunit.de"
8789
8738
}
8790
8739
],
8791
8740
"description": "Library for handling version information and constraints",
···
9169
9118
"authors": [
9170
9119
{
9171
9120
"name": "Sebastian Bergmann",
9172
-
"email": "sebastian@phpunit.de",
9173
-
"role": "lead"
9121
+
"role": "lead",
9122
+
"email": "sebastian@phpunit.de"
9174
9123
}
9175
9124
],
9176
9125
"description": "FilterIterator implementation that filters files based on a list of suffixes.",
···
9260
9209
"authors": [
9261
9210
{
9262
9211
"name": "Sebastian Bergmann",
9263
-
"email": "sebastian@phpunit.de",
9264
-
"role": "lead"
9212
+
"role": "lead",
9213
+
"email": "sebastian@phpunit.de"
9265
9214
}
9266
9215
],
9267
9216
"description": "Utility class for timing",
···
10171
10120
],
10172
10121
"aliases": [],
10173
10122
"minimum-stability": "stable",
10174
-
"stability-flags": {
10175
-
"maknz/slack": 20
10176
-
},
10123
+
"stability-flags": [],
10177
10124
"prefer-stable": false,
10178
10125
"prefer-lowest": false,
10179
10126
"platform": [],
-2
config/app.php
-2
config/app.php
···
194
194
* Package Service Providers...
195
195
*/
196
196
GrahamCampbell\GitHub\GitHubServiceProvider::class,
197
-
Maknz\Slack\SlackServiceProvider::class,
198
197
Mariuzzo\LaravelJsLocalization\LaravelJsLocalizationServiceProvider::class,
199
198
Laravel\Tinker\TinkerServiceProvider::class,
200
199
···
277
276
278
277
'GitHub' => GrahamCampbell\GitHub\Facades\GitHub::class,
279
278
280
-
'Slack' => Maknz\Slack\Facades\Slack::class,
281
279
'Datadog' => ChaseConey\LaravelDatadogHelper\Datadog::class,
282
280
],
283
281
-63
config/slack.php
-63
config/slack.php
···
14
14
*/
15
15
16
16
'endpoint' => env('SLACK_ENDPOINT'),
17
-
18
-
/*
19
-
|-------------------------------------------------------------
20
-
| Default channel
21
-
|-------------------------------------------------------------
22
-
|
23
-
| The default channel we should post to. The channel can either be a
24
-
| channel like #general, a private #group, or a @username. Set to
25
-
| null to use the default set on the Slack webhook
26
-
|
27
-
*/
28
-
29
-
'channel' => 'store',
30
-
31
-
/*
32
-
|-------------------------------------------------------------
33
-
| Default username
34
-
|-------------------------------------------------------------
35
-
|
36
-
| The default username we should post as. Set to null to use
37
-
| the default set on the Slack webhook
38
-
|
39
-
*/
40
-
41
-
'username' => 'osu!web',
42
-
43
-
/*
44
-
|-------------------------------------------------------------
45
-
| Default icon
46
-
|-------------------------------------------------------------
47
-
|
48
-
| The default icon to use. This can either be a URL to an image or Slack
49
-
| emoji like :ghost: or :heart_eyes:. Set to null to use the default
50
-
| set on the Slack webhook
51
-
|
52
-
*/
53
-
54
-
'icon' => null,
55
-
56
-
/*
57
-
|-------------------------------------------------------------
58
-
| Link names
59
-
|-------------------------------------------------------------
60
-
|
61
-
| Whether names like @regan should be converted into links
62
-
| by Slack
63
-
|
64
-
*/
65
-
66
-
'link_names' => false,
67
-
68
-
/*
69
-
|-------------------------------------------------------------
70
-
| Unfurl links
71
-
|-------------------------------------------------------------
72
-
|
73
-
| By default, Slack will unfurl links from well known media
74
-
| sources like YouTube and Twitter. If you want Slack to unfurl
75
-
| other URLs, enable this option
76
-
|
77
-
*/
78
-
79
-
'unfurl_links' => false,
80
17
];