Skip to content

Commit 25ab84f

Browse files
committed
Remove all parts for sending to multiple E-Mails.
After a little Chat with the OneSignal Team, it isn't possible to use the filter with more than one "email" filter.
1 parent da19342 commit 25ab84f

File tree

4 files changed

+4
-69
lines changed

4 files changed

+4
-69
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function routeNotificationForOneSignal()
104104
}
105105
```
106106

107-
If you want to send the notification based on the OneSignal "syncHashedEmail" feature just return an array with the index "email" and the E-Mail or an Array with E-Mails.
107+
If you want to send the notification based on the OneSignal "syncHashedEmail" feature just return an array with the index "email". **It isn't possible to use multiple E-Mails on one filter because of a limitation of the OneSignal API.**
108108

109109
```php
110110
public function routeNotificationForOneSignal()

src/OneSignalChannel.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,15 @@ public function send($notifiable, Notification $notification)
3434

3535
$payload = $notification->toOneSignal($notifiable)->toArray();
3636
if (is_array($userIds) && array_key_exists('email', $userIds)) {
37-
$payload['filters'] = collect($this->parseEmailsToFilters($userIds['email']));
37+
$payload['filters'] = collect([["field" => "email", "value" => $userIds['email']]]);
3838
} else {
3939
$payload['include_player_ids'] = collect($userIds);
4040
}
41+
4142
/** @var ResponseInterface $response */
4243
$response = $this->oneSignal->sendNotificationCustom($payload);
43-
4444
if ($response->getStatusCode() !== 200) {
4545
throw CouldNotSendNotification::serviceRespondedWithAnError($response);
4646
}
4747
}
48-
49-
/**
50-
* Parse the given E-Mails to the array-format that OneSignal needs.
51-
*
52-
* @param mixed $userEmails
53-
*
54-
* @return array
55-
*/
56-
public function parseEmailsToFilters($userEmails)
57-
{
58-
if (is_array($userEmails)) {
59-
return collect($userEmails)->map(function ($email, $key) use ($userEmails) {
60-
if ($key < (count($userEmails) - 1)) {
61-
return [["field" => "email", "relation" => "=", "value" => $email], ['operator' => 'OR']];
62-
} else {
63-
return [["field" => "email", "relation" => "=", "value" => $email]];
64-
}
65-
})->flatten(1)->toArray();
66-
}
67-
68-
return [["field" => "email", "relation" => "=", "value" => $userEmails]];
69-
70-
}
7148
}

tests/ChannelTest.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,36 +101,11 @@ public function it_can_send_a_notification_with_email()
101101
'chrome_icon' => 'Icon',
102102
'adm_small_icon' => 'Icon',
103103
'small_icon' => 'Icon',
104-
'filters' => collect([["field" => "email", "relation" => "=", "value" => '[email protected]']]),
104+
'filters' => collect([["field" => "email", "value" => '[email protected]']]),
105105
])
106106
->andReturn($response);
107107

108108
$this->channel->send(new NotifiableEMail(), new TestNotification());
109109
}
110110

111-
/**
112-
* @test
113-
*/
114-
public function it_can_send_a_notification_with_multiple_email()
115-
{
116-
$response = new Response(200);
117-
118-
$this->oneSignal->shouldReceive('sendNotificationCustom')
119-
->once()
120-
->with([
121-
'contents' => ['en' => 'Body'],
122-
'headings' => ['en' => 'Subject'],
123-
'url' => 'URL',
124-
'buttons' => [],
125-
'web_buttons' => [],
126-
'chrome_web_icon' => 'Icon',
127-
'chrome_icon' => 'Icon',
128-
'adm_small_icon' => 'Icon',
129-
'small_icon' => 'Icon',
130-
'filters' => collect([["field" => "email", "relation" => "=", "value" => '[email protected]'], ['operator' => 'OR'], ["field" => "email", "relation" => "=", "value" => '[email protected]']]),
131-
])
132-
->andReturn($response);
133-
134-
$this->channel->send(new NotifiableMultipleEMail(), new TestNotification());
135-
}
136111
}

tests/NotifiableMultipleEMail.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)