Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Firebase Cloud Messaging support #141

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

siwymilek
Copy link

No description provided.

@@ -95,13 +95,27 @@ protected function setAndroidConfig(array $config)
$this->container->setParameter("rms_push_notifications.android.c2dm.password", $password);
$this->container->setParameter("rms_push_notifications.android.c2dm.source", $source);

// DEFINE PARAMETERS
$this->container->setParameter("rms_push_notifications.android.gcm.api_key", null);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these being set as null and then directly overwritten further down?

@@ -136,7 +150,9 @@ public function setDeviceIdentifier($identifier)
*/
public function getTargetOS()
{
return ($this->isGCM ? Types::OS_ANDROID_GCM : Types::OS_ANDROID_C2DM);
if($this->isGCM) return Types::OS_ANDROID_GCM;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reformat this as per PSR-2 if possible - makes it a bit easier to read :-)

@@ -44,6 +44,9 @@ only be available if you provide configuration respectively for them.
api_key: <string_android_gcm_api_key> # This is titled "Server Key" when creating it
use_multi_curl: <boolean_android_gcm_use_multi_curl> # default is true
dry_run: <bool_use_gcm_dry_run>
fcm:
api_key: <string_android_fcm_api_key> # This is titled "Server Key" when creating it
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that familiar with FCM - is the comment still relevant here about "Server Key" being how the Firebase control panels name the API key?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still called "Server Key"

@@ -35,7 +35,6 @@ public function send(MessageInterface $message)
if (!$this->supports($message->getTargetOS())) {
throw new \RuntimeException("OS type {$message->getTargetOS()} not supported");
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change


to send as a GCM message rather than C2DM.
to send as a FCM message rather than GCM or C2DM.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slightly unclear I think, as you should be specifying only one of GCM or FCM - you don't need to specify both. Could you reword this so that it's clear you only need to use one of the set*() methods, depending on your use case?

@richsage
Copy link
Owner

Firstly, thanks for this PR! :-)

Aside from the inline comments above, could you also please add some detail or external reference about the setFCMOptions() method and what it can be used for.

And is the dry_run flag available for FCM at all? I'm not familiar with it, but as it seems to be based closely on GCM...

@EmmanuelVella
Copy link
Contributor

@siwymilek Very interested with this PR, thank you ! Do you plan to finalize it ?

@EmmanuelVella
Copy link
Contributor

EmmanuelVella commented Jan 18, 2017

@siwymilek Did you test it for real ? Currently, the data format is :
{"data": {"message": "My message"}}

According to the FCM doc, it should be : {"notification": {"body": "My message"}}

https://firebase.google.com/docs/cloud-messaging/http-server-ref

@siwymilek
Copy link
Author

siwymilek commented Jan 18, 2017

@EmmanuelVella As far as I understand the notification parameter is going to show notification immediately, but the data parameter is passing payload to application and developer should handle it by himself.

@EmmanuelVella
Copy link
Contributor

That sound right ! Thank you 👍

@siwymilek
Copy link
Author

@richsage could I please you to review this PR?

$this->container->setParameter("rms_push_notifications.android.gcm.use_multi_curl", $config["android"]["gcm"]["use_multi_curl"]);
$this->container->setParameter('rms_push_notifications.android.gcm.dry_run', $config["android"]["gcm"]["dry_run"]);
}
// if (isset($config["android"]["gcm"])) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure on the reasoning behind this.

If the user is not interested in GCM configuration (for example, they are only using iOS push notifications), this forces them to supply configuration options. That is why the conditional check is in place, to enable them to leave out the android.gcm key and similar (see the Configuration class which permits the key to be unset/not supplied if not needed).

Commenting this check out will force the user to supply dummy details. Therefore I'd like this to be left in.

This is the same for the FCM change on line 108.

@andreiciceu
Copy link

@siwymilek interested in your PR, do you plan to finalize it?

);
$data = array_merge(
$message->getFCMOptions(),
array("data" => $message->getData())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with the FCM documentation and also tried it out. The Key here must be called "notification" instead of the old "data"

Copy link

@alyamovsky alyamovsky Apr 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also in this case of FCM the $message->getData() method should return an array with the 'body' key instead of 'message'.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants