-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathCommentNotification.php
executable file
·99 lines (88 loc) · 2.46 KB
/
CommentNotification.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace App\Notifications;
use App\Models\Comment;
use App\Models\IdeaKey;
use App\Models\User;
use App\Notifications\Channels\SiteChannel;
use App\Notifications\Channels\SiteMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;
class CommentNotification extends Notification implements ShouldQueue
{
use Queueable;
private Comment $comment;
/**
* FriendlyHugs constructor.
*
* @param IdeaKey $ideaKey
*/
public function __construct(Comment $comment)
{
$this->comment = $comment;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
*/
public function via(User $user)
{
return [
SiteChannel::class,
WebPushChannel::class,
];
}
/**
* Get the app representation of the notification.
*
* @param mixed $user
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toSite(User $user)
{
$url = route('post.show', $this->comment->post).'#'.dom_id($this->comment);
return (new SiteMessage())
->title('оставил комментарий к вашей публикации')
->setCommentAuthor($this->comment->author->name)
->img($this->comment->author->avatar)
->action($url, $this->comment->post->title);
}
/**
* @param \App\Models\User $user
*
* @return \NotificationChannels\WebPush\WebPushMessage
*/
public function toWebPush(User $user)
{
$url = route('post.show', $this->comment->post).'#'.dom_id($this->comment);
return (new WebPushMessage)
->title('Новый комментарий')
->icon($this->comment->author->avatar)
->body($this->comment->content)
->action('Посмотреть', $url)
->vibrate([300, 200, 300])
->options([
'TTL' => 86400, // in seconds - 24 hours,
'urgency' => 'high',
]);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}