Skip to content

Commit

Permalink
enable send message using firebase id
Browse files Browse the repository at this point in the history
  • Loading branch information
LaercioSantana committed Oct 14, 2016
1 parent aaa965b commit 7d7fffb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 14 additions & 4 deletions application/controllers/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,27 @@ function addMessage($idRoute, $idBus){
if(!$this->routes_model->existRoute($idRoute))
return $this->makeJsonRespose(["error" => "NOT_FOUND_ROUTE"], 404);

$notification->id = $this->messages_model->insert($notification);
if($notification->id == null)
return $this->makeJsonRespose(["error" => "INTERNAL_ERROR"], 500);
//get firebase id, to send message
$listenersFirebaseIds = $this->messages_model->getNotificationRegistration($idRoute);

//set tokens, to send for users specific
//debug purpose only
if(!empty($notification->registration_token_firebase)){
$listenersFirebaseIds = $notification->registration_token_firebase;
}
else{//save notification in database
$notification->id = $this->messages_model->insert($notification);
if($notification->id == null)
return $this->makeJsonRespose(["error" => "INTERNAL_ERROR"], 500);
}

if(empty($idBus))
unset($notification->id_bus);

//put date on the firebase message
$notification->date = date('Y-m-d H:i:s');

$this->notify($this->messages_model->getNotificationRegistration($idRoute), $notification);
$this->notify($listenersFirebaseIds, $notification);

return $this->makeJsonRespose($notification, 201);
}else
Expand Down
8 changes: 7 additions & 1 deletion application/controllers/Schemas/MessageAdd.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
},
"message": {
"type": "string"
},
"registration_token_firebase": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"title"
]
}
}

0 comments on commit 7d7fffb

Please sign in to comment.