Skip to content

Commit

Permalink
add title column in notification. (#5)
Browse files Browse the repository at this point in the history
* add title column in notification.

* refactor code.
  • Loading branch information
SaifiKhambhati authored and yashbarot committed Aug 7, 2019
1 parent 0ad9814 commit 48f5eca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/Adapters/Fcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ public function __construct()
$this->authKey = config('push-notification.services.fcm.auth_key');
}

public function pushNotification($deviceTokens, $message, $action)
public function pushNotification($deviceTokens, $message, $action, $title = null)
{
foreach ($deviceTokens as $deviceToken) {
$response = $this->callService($deviceToken, $message, $action);
$response = $this->callService($deviceToken, $message, $action, $title);
$this->logResponse($response, $deviceToken, $message, $action);
}
}

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

public function setStream($deviceToken, $message, $action)
public function setStream($deviceToken, $message, $action, $title = null)
{
$postData['to'] = $deviceToken;
$postData['data']['message'] = $message;
$postData['notification']['body'] = $message;
$postData['notification']['title'] = $title;
$postData['data']['body'] = $message;
$postData['data']['title'] = $title;
$postData['data']['click_action'] = $action;

$streamOptions = [
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/PushNotificationClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*/
class PushNotificationClass
{
public function send($deviceTokens, $message, $action)
public function send($deviceTokens, $message, $action, $title = null)
{
$notificationEnable = config('push-notification.moduleEnable.notification');

if ($notificationEnable) {
Queue::push(new PushNotificationJob($deviceTokens, $message, $action));
Queue::push(new PushNotificationJob($deviceTokens, $message, $action, $title));
}

return response()->json(['message' => $message]);
Expand Down
6 changes: 4 additions & 2 deletions src/Jobs/PushNotificationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ class PushNotificationJob implements ShouldQueue
protected $deviceTokens;
protected $message;
protected $action;
protected $title;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct($deviceTokens, $message, $action)
public function __construct($deviceTokens, $message, $action, $title = null)
{
$this->deviceTokens = $deviceTokens;
$this->message = $message;
$this->action = $action;
$this->title = $title;
}

/**
Expand All @@ -37,6 +39,6 @@ public function handle()
{
$adapter = config('push-notification.adapter');
$objAdapter = new $adapter();
$objAdapter->pushNotification($this->deviceTokens, $this->message, $this->action);
$objAdapter->pushNotification($this->deviceTokens, $this->message, $this->action, $this->title);
}
}

0 comments on commit 48f5eca

Please sign in to comment.