Skip to content

Commit 48f5eca

Browse files
SaifiKhambhatiyashbarot
authored andcommitted
add title column in notification. (#5)
* add title column in notification. * refactor code.
1 parent 0ad9814 commit 48f5eca

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/Adapters/Fcm.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,26 @@ public function __construct()
1818
$this->authKey = config('push-notification.services.fcm.auth_key');
1919
}
2020

21-
public function pushNotification($deviceTokens, $message, $action)
21+
public function pushNotification($deviceTokens, $message, $action, $title = null)
2222
{
2323
foreach ($deviceTokens as $deviceToken) {
24-
$response = $this->callService($deviceToken, $message, $action);
24+
$response = $this->callService($deviceToken, $message, $action, $title);
2525
$this->logResponse($response, $deviceToken, $message, $action);
2626
}
2727
}
2828

29-
public function callService($deviceToken, $message, $action)
29+
public function callService($deviceToken, $message, $action, $title = null)
3030
{
31-
return file_get_contents($this->url, false, $this->setStream($deviceToken, $message, $action));
31+
return file_get_contents($this->url, false, $this->setStream($deviceToken, $message, $action, $title));
3232
}
3333

34-
public function setStream($deviceToken, $message, $action)
34+
public function setStream($deviceToken, $message, $action, $title = null)
3535
{
3636
$postData['to'] = $deviceToken;
37-
$postData['data']['message'] = $message;
37+
$postData['notification']['body'] = $message;
38+
$postData['notification']['title'] = $title;
39+
$postData['data']['body'] = $message;
40+
$postData['data']['title'] = $title;
3841
$postData['data']['click_action'] = $action;
3942

4043
$streamOptions = [

src/Classes/PushNotificationClass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*/
1111
class PushNotificationClass
1212
{
13-
public function send($deviceTokens, $message, $action)
13+
public function send($deviceTokens, $message, $action, $title = null)
1414
{
1515
$notificationEnable = config('push-notification.moduleEnable.notification');
1616

1717
if ($notificationEnable) {
18-
Queue::push(new PushNotificationJob($deviceTokens, $message, $action));
18+
Queue::push(new PushNotificationJob($deviceTokens, $message, $action, $title));
1919
}
2020

2121
return response()->json(['message' => $message]);

src/Jobs/PushNotificationJob.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ class PushNotificationJob implements ShouldQueue
1515
protected $deviceTokens;
1616
protected $message;
1717
protected $action;
18+
protected $title;
1819

1920
/**
2021
* Create a new job instance.
2122
*
2223
* @return void
2324
*/
24-
public function __construct($deviceTokens, $message, $action)
25+
public function __construct($deviceTokens, $message, $action, $title = null)
2526
{
2627
$this->deviceTokens = $deviceTokens;
2728
$this->message = $message;
2829
$this->action = $action;
30+
$this->title = $title;
2931
}
3032

3133
/**
@@ -37,6 +39,6 @@ public function handle()
3739
{
3840
$adapter = config('push-notification.adapter');
3941
$objAdapter = new $adapter();
40-
$objAdapter->pushNotification($this->deviceTokens, $this->message, $this->action);
42+
$objAdapter->pushNotification($this->deviceTokens, $this->message, $this->action, $this->title);
4143
}
4244
}

0 commit comments

Comments
 (0)