2
2
3
3
namespace App \Notifications ;
4
4
5
- use App \Casts \FriendlyHugsType ;
6
5
use App \Models \Comment ;
7
6
use App \Models \IdeaKey ;
8
7
use App \Models \Post ;
9
8
use App \Models \User ;
10
- use App \Notifications \Channels \EmotionTrackerChannel ;
11
- use App \Notifications \Channels \EmotionTrackerMessage ;
12
9
use App \Notifications \Channels \SiteChannel ;
13
10
use App \Notifications \Channels \SiteMessage ;
14
11
use Illuminate \Bus \Queueable ;
15
12
use Illuminate \Contracts \Queue \ShouldQueue ;
16
13
use Illuminate \Notifications \Notification ;
14
+ use NotificationChannels \WebPush \WebPushChannel ;
15
+ use NotificationChannels \WebPush \WebPushMessage ;
17
16
18
17
class ReplyCommentNotification extends Notification implements ShouldQueue
19
18
{
20
19
use Queueable;
21
20
22
- private User $ author ;
23
- private Comment $ comment ;
24
- private Post $ post ;
21
+ private Comment $ reply ;
25
22
26
23
/**
27
24
* FriendlyHugs constructor.
28
25
*
29
- * @param IdeaKey $ideaKey
26
+ * @param Comment $reply
30
27
*/
31
- public function __construct (User $ author , Comment $ comment , Post $ post )
28
+ public function __construct (Comment $ reply )
32
29
{
33
- $ this ->author = $ author ;
34
- $ this ->comment = $ comment ;
35
- $ this ->post = $ post ;
30
+ $ this ->reply = $ reply ;
36
31
}
37
32
38
33
/**
@@ -42,9 +37,12 @@ public function __construct(User $author, Comment $comment, Post $post)
42
37
*
43
38
* @return array
44
39
*/
45
- public function via ($ notifiable )
40
+ public function via (User $ user )
46
41
{
47
- return [SiteChannel::class];
42
+ return [
43
+ SiteChannel::class,
44
+ WebPushChannel::class,
45
+ ];
48
46
}
49
47
50
48
/**
@@ -56,12 +54,33 @@ public function via($notifiable)
56
54
*/
57
55
public function toSite (User $ user )
58
56
{
59
- $ url = route ('post.show ' ,$ this ->post ). '# ' . dom_id ($ this ->comment );
57
+ $ url = route ('post.show ' , $ this ->reply -> post ) . '# ' . dom_id ($ this ->reply );
60
58
return (new SiteMessage ())
61
59
->title ('ответил на ваш комментарий ' )
62
- ->setCommentAuthor ($ this ->author ->name )
63
- ->img ($ this ->author ->avatar )
64
- ->action ($ url , $ this ->post ->title );
60
+ ->setCommentAuthor ($ this ->reply ->author ->name )
61
+ ->img ($ this ->reply ->author ->avatar )
62
+ ->action ($ url , $ this ->reply ->post ->title );
63
+ }
64
+
65
+ /**
66
+ * @param \App\Models\User $user
67
+ *
68
+ * @return \NotificationChannels\WebPush\WebPushMessage
69
+ */
70
+ public function toWebPush (User $ user )
71
+ {
72
+ $ url = route ('post.show ' , $ this ->reply ->post ) . '# ' . dom_id ($ this ->reply );
73
+
74
+ return (new WebPushMessage )
75
+ ->title ('Пользователь ' . $ this ->reply ->author ->name . ' ответил на ваш комментарий ' )
76
+ ->icon ($ this ->reply ->author ->avatar )
77
+ //->body('Пользователь '.$this->author->name." ответил на ваш комментарий")
78
+ ->action ('посмотреть ' , $ url )
79
+ ->vibrate ([300 , 200 , 300 ])
80
+ ->options ([
81
+ 'TTL ' => 86400 , // in seconds - 24 hours,
82
+ 'urgency ' => 'high ' ,
83
+ ]);
65
84
}
66
85
67
86
/**
0 commit comments