Skip to content

Commit

Permalink
Merge pull request #2295 from CachetHQ/new-notifications
Browse files Browse the repository at this point in the history
Notifications
  • Loading branch information
jbrooksuk authored Jan 4, 2017
2 parents 55de8d0 + 7269dd1 commit 8b92704
Show file tree
Hide file tree
Showing 61 changed files with 1,549 additions and 1,131 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ REDIS_DATABASE=null
REDIS_PORT=null

GITHUB_TOKEN=null

NEXMO_KEY=null
NEXMO_SECRET=null
NEXMO_SMS_FROM=Cachet
41 changes: 0 additions & 41 deletions app/Bus/Commands/System/Mail/TestMailCommand.php

This file was deleted.

11 changes: 10 additions & 1 deletion app/Bus/Events/Incident/IncidentWasReportedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ final class IncidentWasReportedEvent implements IncidentEventInterface
*/
public $incident;

/**
* Whether to notify that the incident was reported.
*
* @var bool
*/
public $notify;

/**
* Create a new incident has reported event instance.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
* @param bool $notify
*
* @return void
*/
public function __construct(Incident $incident)
public function __construct(Incident $incident, $notify = false)
{
$this->incident = $incident;
$this->notify = $notify;
}
}
51 changes: 51 additions & 0 deletions app/Bus/Events/User/UserAcceptedInviteEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Bus\Events\User;

use CachetHQ\Cachet\Models\Invite;
use CachetHQ\Cachet\Models\User;

/**
* This is the user accepted invite event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class UserAcceptedInviteEvent implements UserEventInterface
{
/**
* The user that accepted the invite.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;

/**
* The invite that the user accepted.
*
* @var \CachetHQ\Cachet\Models\Invite
*/
public $invite;

/**
* Create a new user accepted invite event class.
*
* @param \CachetHQ\Cachet\Models\User $user
* @param \CachetHQ\Cachet\Models\Invite $invite
*
* @return void
*/
public function __construct(User $user, Invite $invite)
{
$this->user = $user;
$this->invite = $invite;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public function handle(ReportIncidentCommand $command)
));
}

$incident->update(['notify' => (bool) $command->notify]);

event(new IncidentWasReportedEvent($incident));
event(new IncidentWasReportedEvent($incident, (bool) $command->notify));

return $incident;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\Subscription;
use CachetHQ\Cachet\Notifications\Subscriber\VerifySubscriptionNotification;

/**
* This is the subscribe subscriber command handler.
Expand Down Expand Up @@ -49,7 +50,7 @@ public function handle(SubscribeSubscriberCommand $command)
$components = Component::all();
}

$components->map(function ($component) use ($subscriber) {
$components->each(function ($component) use ($subscriber) {
Subscription::create([
'subscriber_id' => $subscriber->id,
'component_id' => $component->id,
Expand All @@ -59,9 +60,11 @@ public function handle(SubscribeSubscriberCommand $command)
if ($command->verified) {
dispatch(new VerifySubscriberCommand($subscriber));
} else {
event(new SubscriberHasSubscribedEvent($subscriber));
$subscriber->notify(new VerifySubscriptionNotification());
}

event(new SubscriberHasSubscribedEvent($subscriber));

$subscriber->load('subscriptions');

return $subscriber;
Expand Down
64 changes: 0 additions & 64 deletions app/Bus/Handlers/Commands/System/Mail/TestMailCommandHandler.php

This file was deleted.

3 changes: 3 additions & 0 deletions app/Bus/Handlers/Commands/User/InviteUserCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use CachetHQ\Cachet\Bus\Commands\User\InviteUserCommand;
use CachetHQ\Cachet\Bus\Events\User\UserWasInvitedEvent;
use CachetHQ\Cachet\Models\Invite;
use CachetHQ\Cachet\Notifications\User\InviteUserNotification;

/**
* This is the invite user command handler.
Expand All @@ -36,6 +37,8 @@ public function handle(InviteUserCommand $command)
'email' => $email,
]);

$invite->notify(new InviteUserNotification());

event(new UserWasInvitedEvent($invite));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasUpdatedEvent;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Subscriber;
use Illuminate\Contracts\Mail\MailQueue;
use McCool\LaravelAutoPresenter\Facades\AutoPresenter;
use CachetHQ\Cachet\Notifications\Component\ComponentStatusChangedNotification;

class SendComponentUpdateEmailNotificationHandler
{
/**
* The mailer instance.
*
* @var \Illuminate\Contracts\Mail\Mailer
*/
protected $mailer;

/**
* The subscriber instance.
*
Expand All @@ -36,14 +28,12 @@ class SendComponentUpdateEmailNotificationHandler
/**
* Create a new send incident email notification handler.
*
* @param \Illuminate\Contracts\Mail\Mailer $mailer
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
*
* @return void
*/
public function __construct(MailQueue $mailer, Subscriber $subscriber)
public function __construct(Subscriber $subscriber)
{
$this->mailer = $mailer;
$this->subscriber = $subscriber;
}

Expand All @@ -66,9 +56,9 @@ public function handle(ComponentStatusWasUpdatedEvent $event)
// First notify all global subscribers.
$globalSubscribers = $this->subscriber->isVerified()->isGlobal()->get();

foreach ($globalSubscribers as $subscriber) {
$this->notify($component, $subscriber);
}
$globalSubscribers->each(function ($subscriber) use ($component, $event) {
$subscriber->notify(new ComponentStatusChangedNotification($component, $event->new_status));
});

$notified = $globalSubscribers->pluck('id')->all();

Expand All @@ -81,37 +71,8 @@ public function handle(ComponentStatusWasUpdatedEvent $event)
return in_array($subscriber->id, $notified);
});

foreach ($componentSubscribers as $subscriber) {
$this->notify($component, $subscriber);
}
}

/**
* Send notification to subscriber.
*
* @param \CachetHQ\Cachet\Models\Component $component
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function notify(Component $component, Subscriber $subscriber)
{
$component = AutoPresenter::decorate($component);

$mail = [
'subject' => trans('cachet.subscriber.email.component.subject'),
'component_name' => $component->name,
'component_human_status' => $component->human_status,
];

$mail['email'] = $subscriber->email;
$mail['manage_link'] = cachet_route('subscribe.manage', [$subscriber->verify_code]);

$this->mailer->queue([
'html' => 'emails.components.update-html',
'text' => 'emails.components.update-text',
], $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
$componentSubscribers->each(function ($subscriber) use ($component, $event) {
$subscriber->notify(new ComponentStatusChangedNotification($component, $event->new_status));
});
}
}
Loading

0 comments on commit 8b92704

Please sign in to comment.