Skip to content

Commit 6938805

Browse files
authoredSep 6, 2021
Merge pull request #736 from bakaphp/refact-onesignal-notification-counter
[0.3] refact: add notifiction badgets
2 parents fbbfaf9 + 0c12e24 commit 6938805

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed
 

‎src/Cli/Jobs/PushNotifications.php

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Baka\Contracts\Queue\QueueableJobInterface;
66
use Baka\Jobs\Job;
7+
use Canvas\Models\Notifications;
78
use Canvas\Models\UserLinkedSources;
89
use Canvas\Models\Users;
910
use Canvas\Notifications\PushNotification;
@@ -21,6 +22,8 @@ class PushNotifications extends Job implements QueueableJobInterface
2122
protected Users $users;
2223
protected string $message;
2324
protected string $title;
25+
protected const IOS = 3;
26+
protected const ANDROID = 2;
2427
/**
2528
* Realtime params.
2629
*
@@ -72,6 +75,12 @@ public function handle()
7275
$pushBody['data'] = $this->params;
7376
}
7477

78+
//if IOS add badge
79+
if (!empty($userDevicesArray[self::IOS])) {
80+
$pushBody['ios_badgeType'] = 'SetTo';
81+
$pushBody['ios_badgeCount'] = Notifications::totalUnRead($this->users);
82+
}
83+
7584
/**
7685
* @todo We need to use external_users_id instead of player_id in the future
7786
* for proper multi-device notification.

‎src/Notifications/Notification.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,29 @@ class Notification implements NotificationInterface
3535
protected bool $useQueue = false;
3636

3737
/**
38-
* Save the notifications into the db
38+
* Save the notifications into the db.
3939
*
4040
* @var bool
4141
*/
4242
protected bool $saveNotification = true;
4343

4444
/**
45-
* Send this notification to pusher
46-
*
45+
* Send this notification to pusher.
46+
*
4747
* @var bool
4848
*/
4949
protected bool $toPusher = true;
5050

5151
/**
52-
* Send this notification to mail
53-
*
52+
* Send this notification to mail.
53+
*
5454
* @var bool
5555
*/
5656
protected bool $toMail = true;
5757

5858
/**
59-
* Send this notification to push notification
60-
*
59+
* Send this notification to push notification.
60+
*
6161
* @var bool
6262
*/
6363
protected bool $toPushNotification = true;
@@ -293,11 +293,11 @@ public function sendToQueue() : bool
293293
}
294294

295295
/**
296-
* Save the notification used to the database
296+
* Save the notification used to the database.
297297
*
298-
* @return boolean
298+
* @return bool
299299
*/
300-
public function saveNotification(): bool
300+
public function saveNotification() : bool
301301
{
302302
$content = $this->message();
303303
$app = Di::getDefault()->getApp();
@@ -325,29 +325,29 @@ public function saveNotification(): bool
325325
*/
326326
public function trigger() : bool
327327
{
328-
if($this->saveNotification) {
328+
if ($this->saveNotification) {
329329
$this->saveNotification();
330330
}
331331

332-
if($this->toPusher) {
332+
if ($this->toPusher) {
333333
$this->toPusher();
334334
}
335335

336-
if($this->toMail) {
336+
if ($this->toMail) {
337337
$this->toMailNotification();
338338
}
339339

340-
if($this->toPushNotification) {
340+
if ($this->toPushNotification) {
341341
$this->toSendPushNotification();
342342
}
343343

344344
return true;
345345
}
346346

347347
/**
348-
* Send to pusher the notification
348+
* Send to pusher the notification.
349349
*
350-
* @return boolean
350+
* @return bool
351351
*/
352352
public function toPusher() : bool
353353
{
@@ -360,9 +360,9 @@ public function toPusher() : bool
360360
}
361361

362362
/**
363-
* Send notification to mail
363+
* Send notification to mail.
364364
*
365-
* @return boolean
365+
* @return bool
366366
*/
367367
public function toMailNotification() : bool
368368
{
@@ -375,9 +375,9 @@ public function toMailNotification() : bool
375375
}
376376

377377
/**
378-
* Send Push notification
378+
* Send Push notification.
379379
*
380-
* @return boolean
380+
* @return bool
381381
*/
382382
public function toSendPushNotification() : bool
383383
{

0 commit comments

Comments
 (0)
Please sign in to comment.