mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Expand notifications
This commit is contained in:
parent
d2c52b47f1
commit
4ca346fc4d
@ -44,8 +44,6 @@ class AdminEventHandler
|
|||||||
* @param AdminRequestedTestMessage $event
|
* @param AdminRequestedTestMessage $event
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws FireflyException
|
|
||||||
* @deprecated
|
|
||||||
*/
|
*/
|
||||||
public function sendTestMessage(AdminRequestedTestMessage $event): bool
|
public function sendTestMessage(AdminRequestedTestMessage $event): bool
|
||||||
{
|
{
|
||||||
|
@ -25,8 +25,10 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Handlers\Events;
|
namespace FireflyIII\Handlers\Events;
|
||||||
|
|
||||||
use FireflyIII\Events\WarnUserAboutBill;
|
use FireflyIII\Events\WarnUserAboutBill;
|
||||||
use FireflyIII\Mail\BillWarningMail;
|
use FireflyIII\Notifications\User\BillReminder;
|
||||||
use Log;
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Mail;
|
use Mail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,24 +44,17 @@ class BillEventHandler
|
|||||||
*/
|
*/
|
||||||
public function warnAboutBill(WarnUserAboutBill $event): void
|
public function warnAboutBill(WarnUserAboutBill $event): void
|
||||||
{
|
{
|
||||||
$bill = $event->bill;
|
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||||
$field = $event->field;
|
|
||||||
$diff = $event->diff;
|
|
||||||
$user = $bill->user;
|
|
||||||
$address = $user->email;
|
|
||||||
$ipAddress = request()?->ip();
|
|
||||||
|
|
||||||
// see if user has alternative email address:
|
$bill = $event->bill;
|
||||||
$pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');
|
$preference = Preferences::getForUser($bill->user, 'notification_bill_reminder', true)->data;
|
||||||
if (null !== $pref) {
|
|
||||||
$address = $pref->data;
|
if (true === $preference) {
|
||||||
|
Log::debug('Bill reminder is true!');
|
||||||
|
Notification::send($bill->user, new BillReminder($bill, $event->field, $event->diff));
|
||||||
|
}
|
||||||
|
if (false === $preference) {
|
||||||
|
Log::debug('User has disabled bill reminders.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// send message:
|
|
||||||
Mail::to($address)->send(new BillWarningMail($bill, $field, $diff, $ipAddress));
|
|
||||||
|
|
||||||
|
|
||||||
Log::debug('warnAboutBill');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ class WarnAboutBills implements ShouldQueue
|
|||||||
private Carbon $date;
|
private Carbon $date;
|
||||||
private bool $force;
|
private bool $force;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
@ -54,16 +53,16 @@ class WarnAboutBills implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function __construct(?Carbon $date)
|
public function __construct(?Carbon $date)
|
||||||
{
|
{
|
||||||
|
$newDate = new Carbon;
|
||||||
|
$newDate->startOfDay();
|
||||||
|
$this->date = $newDate;
|
||||||
|
|
||||||
if (null !== $date) {
|
if (null !== $date) {
|
||||||
$newDate = clone $date;
|
$newDate = clone $date;
|
||||||
$newDate->startOfDay();
|
$newDate->startOfDay();
|
||||||
$this->date = $newDate;
|
$this->date = $newDate;
|
||||||
}
|
}
|
||||||
if (null === $date) {
|
|
||||||
$newDate = new Carbon;
|
|
||||||
$newDate->startOfDay();
|
|
||||||
$this->date = $newDate;
|
|
||||||
}
|
|
||||||
$this->force = false;
|
$this->force = false;
|
||||||
|
|
||||||
Log::debug(sprintf('Created new WarnAboutBills("%s")', $this->date->format('Y-m-d')));
|
Log::debug(sprintf('Created new WarnAboutBills("%s")', $this->date->format('Y-m-d')));
|
||||||
|
@ -22,7 +22,73 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Notifications\User;
|
namespace FireflyIII\Notifications\User;
|
||||||
|
|
||||||
class BillReminder
|
use FireflyIII\Models\Bill;
|
||||||
{
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BillReminder
|
||||||
|
*/
|
||||||
|
class BillReminder extends Notification
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
private Bill $bill;
|
||||||
|
private string $field;
|
||||||
|
private int $diff;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Bill $bill, string $field, int $diff)
|
||||||
|
{
|
||||||
|
$this->bill = $bill;
|
||||||
|
$this->field = $field;
|
||||||
|
$this->diff = $diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification's delivery channels.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail($notifiable)
|
||||||
|
{
|
||||||
|
$subject = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||||
|
if (0 === $this->diff) {
|
||||||
|
$subject = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new MailMessage)
|
||||||
|
->markdown('emails.bill-warning', ['field' => $this->field, 'diff' => $this->diff, 'bill' => $this->bill])
|
||||||
|
->subject($subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,60 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Notifications\User;
|
namespace FireflyIII\Notifications\User;
|
||||||
|
|
||||||
class NewAccessToken
|
use Illuminate\Bus\Queueable;
|
||||||
{
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class NewAccessToken extends Notification
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
private string $address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(string $address)
|
||||||
|
{
|
||||||
|
$this->address = $address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification's delivery channels.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail($notifiable)
|
||||||
|
{
|
||||||
|
return (new MailMessage)
|
||||||
|
->markdown('emails.admin-test', ['email' => $this->address])
|
||||||
|
->subject((string) trans('email.admin_test_subject'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,13 @@ use FireflyIII\Mail\OAuthTokenCreatedMail;
|
|||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Models\PiggyBankRepetition;
|
use FireflyIII\Models\PiggyBankRepetition;
|
||||||
|
use FireflyIII\Notifications\Admin\TestNotification;
|
||||||
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Illuminate\Auth\Events\Login;
|
use Illuminate\Auth\Events\Login;
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Laravel\Passport\Client;
|
use Laravel\Passport\Client;
|
||||||
use Laravel\Passport\Events\AccessTokenCreated;
|
use Laravel\Passport\Events\AccessTokenCreated;
|
||||||
use Log;
|
use Log;
|
||||||
@ -231,6 +233,8 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// HERE WE ARE
|
||||||
|
Notification::send($event->user, new TestNotification($event->user->email));
|
||||||
|
|
||||||
$email = $user->email;
|
$email = $user->email;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user