mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix spam whoopsie.
This commit is contained in:
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
@@ -15,11 +14,13 @@ use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
|
||||
class SubscriptionOverdueReminder extends Notification
|
||||
class SubscriptionsOverdueReminder extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(private Bill $bill, private array $dates) {}
|
||||
public function __construct(private array $overdue)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
|
||||
@@ -35,23 +36,31 @@ class SubscriptionOverdueReminder extends Notification
|
||||
*/
|
||||
public function toMail(User $notifiable): MailMessage
|
||||
{
|
||||
// format the dates in a human-readable way
|
||||
$this->dates['pay_dates'] = array_map(
|
||||
static function (string $date): string {
|
||||
return new Carbon($date)->isoFormat((string) trans('config.month_and_day_moment_js'));
|
||||
},
|
||||
$this->dates['pay_dates']
|
||||
);
|
||||
|
||||
// format the data
|
||||
$info = [];
|
||||
$count = 0;
|
||||
foreach ($this->overdue as $item) {
|
||||
$current = [
|
||||
'bill' => $item['bill'],
|
||||
];
|
||||
$current['pay_dates'] = array_map(
|
||||
static function (string $date): string {
|
||||
return new Carbon($date)->isoFormat((string)trans('config.month_and_day_moment_js'));
|
||||
}, $item['dates']['pay_dates']);
|
||||
$info[] = $current;
|
||||
$count++;
|
||||
}
|
||||
return new MailMessage()
|
||||
->markdown('emails.subscription-overdue-warning', ['bill' => $this->bill, 'dates' => $this->dates])
|
||||
->subject($this->getSubject())
|
||||
;
|
||||
->markdown('emails.subscriptions-overdue-warning', ['info' => $info,'count' => $count])
|
||||
->subject($this->getSubject());
|
||||
}
|
||||
|
||||
private function getSubject(): string
|
||||
{
|
||||
return (string) trans('email.subscription_overdue_subject', ['name' => $this->bill->name]);
|
||||
if (count($this->overdue) > 1) {
|
||||
return (string)trans('email.subscriptions_overdue_subject_multi', ['count' => count($this->overdue)]);
|
||||
}
|
||||
return (string)trans('email.subscriptions_overdue_subject_single');
|
||||
}
|
||||
|
||||
public function toNtfy(User $notifiable): Message
|
||||
@@ -60,7 +69,7 @@ class SubscriptionOverdueReminder extends Notification
|
||||
$message = new Message();
|
||||
$message->topic($settings['ntfy_topic']);
|
||||
$message->title($this->getSubject());
|
||||
$message->body((string) trans('email.bill_warning_please_action'));
|
||||
$message->body((string)trans('email.bill_warning_please_action'));
|
||||
|
||||
return $message;
|
||||
}
|
||||
@@ -70,9 +79,8 @@ class SubscriptionOverdueReminder extends Notification
|
||||
*/
|
||||
public function toPushover(User $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.bill_warning_please_action'))
|
||||
->title($this->getSubject())
|
||||
;
|
||||
return PushoverMessage::create((string)trans('email.bill_warning_please_action'))
|
||||
->title($this->getSubject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,10 +94,9 @@ class SubscriptionOverdueReminder extends Notification
|
||||
return new SlackMessage()
|
||||
->warning()
|
||||
->attachment(static function ($attachment) use ($bill, $url): void {
|
||||
$attachment->title((string) trans('firefly.visit_bill', ['name' => $bill->name]), $url);
|
||||
$attachment->title((string)trans('firefly.visit_bill', ['name' => $bill->name]), $url);
|
||||
})
|
||||
->content($this->getSubject())
|
||||
;
|
||||
->content($this->getSubject());
|
||||
}
|
||||
|
||||
/**
|
Reference in New Issue
Block a user