Fix extra notification

This commit is contained in:
James Cole
2022-09-24 12:17:55 +02:00
parent 45d7042405
commit 600fa388c1
4 changed files with 41 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Notifications\User;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
class UserLogin extends Notification
@@ -51,7 +52,7 @@ class UserLogin extends Notification
*/
public function via($notifiable)
{
return ['mail'];
return ['mail', 'slack'];
}
/**
@@ -78,6 +79,27 @@ class UserLogin extends Notification
->subject((string) trans('email.login_from_new_ip'));
}
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
* @return SlackMessage
*/
public function toSlack($notifiable)
{
$host = '';
try {
$hostName = gethostbyaddr($this->ip);
} catch (Exception $e) {
$hostName = $this->ip;
}
if ($hostName !== $this->ip) {
$host = $hostName;
}
return (new SlackMessage)->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));
}
/**
* Get the array representation of the notification.
*