-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27d3f62
commit fa17c6b
Showing
2 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Foxhound\Channels; | ||
|
||
use Foxhound\Data; | ||
use RuntimeException; | ||
use Foxhound\Manifest; | ||
use Foxhound\Support\ChannelType; | ||
use Illuminate\Mail\Events\MessageSending; | ||
use Illuminate\Notifications\Events\NotificationSending; | ||
|
||
class MessageMedia extends Vonage | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function intercept(NotificationSending | MessageSending $event, Manifest $manifest): void | ||
{ | ||
// Message Media can only be intercepted when sending a notification. | ||
if (!($event instanceof NotificationSending)) { | ||
return; | ||
} | ||
|
||
throw_unless(method_exists($event->notification, 'toMessageMedia'), new RuntimeException('Notification does not have a "toMessageMedia" method.')); | ||
|
||
$message = $event->notification->toMessageMedia($event->notifiable); | ||
|
||
$manifest->data('message', $message->message); | ||
$manifest->data('to', $event->notifiable->routeNotificationFor('messagemedia', $event->notification)); | ||
$manifest->data('from', $message->from); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function data(): Data\Response\ChannelData | ||
{ | ||
return Data\Response\ChannelData::from([ | ||
'key' => $this->key(), | ||
'name' => 'Message Media', | ||
'type' => ChannelType::Sms, | ||
'unreadMessagesCount' => $this->storage->getUnreadMessagesCount($this), | ||
]); | ||
} | ||
} |