-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new instant notifications need tests
- Loading branch information
1 parent
bcdf616
commit 56d4562
Showing
5 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Comment; | ||
use App\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Support\HtmlString; | ||
|
||
class CommentCreated extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new notification instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Comment $comment, User $user) | ||
{ | ||
$this->comment = $comment; | ||
$this->user = $user; | ||
} | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @param mixed $notifiable | ||
* | ||
* @return array | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return ['mail', 'database']; | ||
} | ||
|
||
/** | ||
* Get the mail representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* | ||
* @return \Illuminate\Notifications\Messages\MailMessage | ||
*/ | ||
public function toMail($notifiable) | ||
{ | ||
|
||
$message = (new MailMessage()) | ||
->greeting(' ') | ||
->salutation(' ') | ||
->subject('[' . $this->comment->discussion->group->name . '] ' . $this->comment->discussion->name) | ||
->line(new HtmlString(filter($this->comment->body))) | ||
->line($this->comment->user->name) | ||
->action(trans('messages.reply'), route('groups.discussions.show', [$this->comment->discussion->group, $this->comment->discussion])); | ||
$message->from(config('mail.noreply'), $this->comment->user->name); | ||
|
||
|
||
// send notification directly from discussion inbox if there is one | ||
if ($this->comment->discussion->inbox()) { | ||
$message->replyTo($this->comment->discussion->inbox(), $this->comment->discussion->group->name); | ||
} else { | ||
$message->line(trans('messages.dont_reply_to_this_email')); | ||
$message->from(config('mail.noreply'), config('mail.from.name')); | ||
} | ||
|
||
$message->withSwiftMessage(function ($message) { | ||
$message->getHeaders()->addTextHeader('Message-ID', 'comment-'. $this->comment->id . '@' . config('app.url')); | ||
$message->getHeaders()->addTextHeader('References', 'discussion-'. $this->comment->discussion->id . '@' . config('app.url')); | ||
}); | ||
|
||
return $message; | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* | ||
* @return array | ||
*/ | ||
public function toArray($notifiable) | ||
{ | ||
return [ | ||
'comment' => $this->comment->toArray(), | ||
'user' => $this->user->toArray(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Discussion; | ||
use App\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Support\HtmlString; | ||
|
||
class DiscussionCreated extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new notification instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Discussion $discussion, User $user) | ||
{ | ||
$this->discussion = $discussion; | ||
$this->user = $user; | ||
} | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @param mixed $notifiable | ||
* | ||
* @return array | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return ['mail', 'database']; | ||
} | ||
|
||
/** | ||
* Get the mail representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* | ||
* @return \Illuminate\Notifications\Messages\MailMessage | ||
*/ | ||
public function toMail($notifiable) | ||
{ | ||
|
||
$message = (new MailMessage()) | ||
->greeting(' ') | ||
->salutation(' ') | ||
->subject('[' . $this->discussion->group->name . '] ' . $this->discussion->name) | ||
->line(new HtmlString(filter($this->discussion->body))) | ||
->line($this->discussion->user->name) | ||
->action(trans('messages.reply'), route('groups.discussions.show', [$this->discussion->group, $this->discussion])); | ||
$message->from(config('mail.noreply'), $this->discussion->user->name); | ||
|
||
|
||
// send notification directly from discussion inbox if there is one | ||
if ($this->discussion->inbox()) { | ||
$message->replyTo($this->discussion->inbox(), $this->discussion->group->name); | ||
} else { | ||
$message->line(trans('messages.dont_reply_to_this_email')); | ||
$message->from(config('mail.noreply'), config('mail.from.name')); | ||
} | ||
|
||
$message->withSwiftMessage(function ($message) { | ||
$message->getHeaders()->addTextHeader('Message-ID', 'discussion-'. $this->discussion->id . '@' . config('app.url')); | ||
}); | ||
|
||
return $message; | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* | ||
* @return array | ||
*/ | ||
public function toArray($notifiable) | ||
{ | ||
return [ | ||
'discussion' => $this->discussion->toArray(), | ||
'user' => $this->user->toArray(), | ||
]; | ||
} | ||
} |