api code global jain
This commit is contained in:
102
app/Jobs/Notifications/Shravak/SendAcceptFriendRequest.php
Normal file
102
app/Jobs/Notifications/Shravak/SendAcceptFriendRequest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Notifications\Shravak;
|
||||
|
||||
use App\Constant\Constant;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use App\Models\UserDeviceToken;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Traits\PushNotificationTraits;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class SendAcceptFriendRequest implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $loggedInUser;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $receiver;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $roleName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct($loggedInUser, $receiver)
|
||||
{
|
||||
$this->loggedInUser = $loggedInUser;
|
||||
$this->receiver = $receiver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
//Push Notification to user when someone accepts friend request
|
||||
$tokens = UserDeviceToken::where('user_id', $this->receiver->id)->get()->toArray();
|
||||
$pushData = [];
|
||||
$users = [];
|
||||
|
||||
if($tokens && $tokens > 0) {
|
||||
foreach ($tokens as $token) {
|
||||
$pushData['userToken'] = $token['token'] ?? [];
|
||||
$pushData['title'] = trans('notifications.notification_title.friend_request_accepted',['user' => $this->loggedInUser->name]);
|
||||
$pushData['body'] = trans('notifications.push_friend_request.accept_request',['user' => $this->loggedInUser->name]);
|
||||
$pushData['image'] = ($this->loggedInUser->avatar) ? $this->loggedInUser->avatar : "";
|
||||
$pushData['from_id'] = $this->loggedInUser->id;
|
||||
$extraData = [];
|
||||
$extraData['user_id'] = $this->loggedInUser->id ?? '';
|
||||
$extraData['user_name'] = $this->loggedInUser->name ?? '';
|
||||
$extraData['user_type'] = 'friendRequest';
|
||||
$extraData['type'] = trans('notifications.friend_request_notification_type.friend-request-accepted');
|
||||
$extraData['created_at'] = date('Y/m/d H:i:s');
|
||||
$extraData['os'] = $token['os'] ? getPlatform($token['os']) : [];
|
||||
|
||||
$pushData['extraData'] = $extraData ?? [];
|
||||
$this->pushNotification($pushData, $extraData);
|
||||
}
|
||||
}
|
||||
//Store Notification
|
||||
$notificationData = [];
|
||||
$notificationData['body'] = trans('notifications.friend_request.accept_request');
|
||||
$notificationData['user_id'] = $this->receiver->id;
|
||||
$notificationData['type'] = trans('notifications.friend_request_notification_type.friend-request-accepted');
|
||||
$notificationData['title'] = trans('notifications.notification_title.friend_request_accepted',['user' => $this->loggedInUser->name]);
|
||||
$extraNotificationData = [];
|
||||
$extraNotificationData['from_id'] = $this->loggedInUser->id ?? '';
|
||||
$extraNotificationData['user_id'] = $this->loggedInUser->id ?? '';
|
||||
$extraNotificationData['name'] = $this->loggedInUser->name ?? '';
|
||||
$extraNotificationData['avatar'] = ($this->loggedInUser->avatar) ? $this->loggedInUser->avatar : "";
|
||||
$extraNotificationData['notification_type'] = Constant::STATUS_ONE;
|
||||
$extraNotificationData['user_type'] = 'shravak';
|
||||
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
|
||||
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
|
||||
|
||||
if (!in_array($this->receiver->id, $users)) {
|
||||
$users[$this->receiver->id] = $this->receiver->id;
|
||||
$this->storeNotification($notificationData);
|
||||
//Unread count increament
|
||||
unreadNotificationCounter($this->receiver->id);
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user