-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]Refactor to Traits and add some little more Parameters #58
Conversation
You know I was thinking something similar to this when I was adding my PR's. I was thinking you could ditch all the protected properties and just having a public function icon($value)
{
$this->icon = $value;
return $this;
} becomes public function icon($value)
{
return $this->setParameter('chrome_web_icon', $value)
->setParameter('chrome_icon', $value)
->setParameter('adm_small_icon', $value)
->setParameter('small_icon', $value);
} Because now that you've added the parameter helper, its like there is these "special" parameters that have instance properties - and everything else would just be set via Cause at the end of the day - they are all just parameters - even the public function setData($key, $value)
{
return $this->setParameter("data.{$key}", $value);
} then in the |
Keep Backward Compatibility
haha, judging by the PR's coming in - I spoke too soon haha - your all over it 😅 |
Yeah, your right :) I've refactored it, so there aren't any unused protected variables there anymore. I'd leave the "setData" Method on the Class, since it could be usefull for some people to set the data and because auf the Backward Compability i'd leave the body, subject & url method Edit: Ha what a good idea with the data :D, did it :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! This code organization is very beatufiul 🙂
I'll pull it down and check it out - looks nice :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope you don't mind the feedback. I know I'm not a maintainer - so it's probably not my place - but thought I'd throw my thoughts in the mix.
src/OneSignalMessage.php
Outdated
|
||
/** @var string */ | ||
protected $icon; | ||
use OneSignalHelpers; | ||
|
||
/** @var array */ | ||
protected $data = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can ditch this var now as we're going straight onto the parameter in the setData
method
src/OneSignalMessage.php
Outdated
public function icon($value) | ||
{ | ||
$this->icon = $value; | ||
if (is_array($value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could ditch the else
here if you wanted to with an early return
public function body($value)
{
if (is_array($value)) {
return $this->setParameter('contents', $value);
}
return $this->setParameter('contents', ['en' => $value]);
}
src/OneSignalMessage.php
Outdated
$this->setParameter('headings', $value); | ||
} else { | ||
$this->setParameter('headings', ['en' => $value]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as with body - however if going with the array check version, you might want to introduce a parseLocale()
method to remove the duplicate code...
protected function parseLocale($value)
{
return is_array($value) ? $value : ['en' => $value];
}
// then subject / body etc with localisation could just be
public function subject()
{
$this->setParameter('headings', $this->parseLocale($value));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah thats a better solution!
* | ||
* @return $this | ||
*/ | ||
public function setIosSound(string $soundUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda feel like "sound" is not "appearance" ...maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used the "categories" from the OneSignal Documentation for the "grouping" of the methods:
https://documentation.onesignal.com/reference
And there are the sound Settings under "Appearance" :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh - that makes way more sense haha - sorry should have checked that :) I like that 👍
*/ | ||
public function setWindowsSound(string $soundUrl) | ||
{ | ||
return $this->setParameter('wp_sound', $soundUrl)->setParameter('wp_wns_sound', $soundUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->setParameter('wp_wns_sound', $soundUrl);
on a new line here for consistency.
* | ||
* @return $this | ||
*/ | ||
public function button(OneSignalButton $button) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think maybe this should be prefixed. For example - take the notifications conversation we had:
incrementBadgeCount()
sound like it will do it everywhere.
incrementIosBadgeCount()
sound like it will do it on iOS.
webButtons
sounds like it is for the web (which is it)
buttons
sounds like it will do it everywhere - web + native
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah i agree with you, but i think this is something that should clarify first, since they named it "web buttons" and "buttons"
https://documentation.onesignal.com/reference#section-action-buttons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh! yea - thats tough because I think matching their docs is good!
* | ||
* @return $this | ||
*/ | ||
public function setTTL(int $ttl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are going with Ios
of iOS
, might want to do Ttl
. I hate this capitalisation stuff with acronyms like that i.e Html
etc. always feels weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you are right :)
{ | ||
/** | ||
* Set the Android Grouping Parameters. | ||
* @param string $group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line between description and @param
|
||
/** | ||
* Set the Amazon (FireOS) Grouping Parameters. | ||
* @param string $group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line between description and @param
src/Traits/OneSignalHelpers.php
Outdated
@@ -0,0 +1,14 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are probably better off just use
ing these in the OneSignalMessage
class rather than using a trait that is only there to use other traits IMO
Please note - I don't maintain anything like this - so I feel bad for leaving so much feedback as just a random contributor - but I want to say this is awesome and will really clean things up |
As all the introduced methods are actionThing i.e. icon()
webButton()
webButtons()
button()
buttons()
body()
subject() |
@timacdonald the problem with this methods is the backward compability... i don't want to break alle applications. But you are right, |
@timacdonald should be done now :) Thank you really for all your help and ideas on this! |
No worries - thanks for keeping this package alive and kicking. I’ll take another looksy with fresh eyes this morning. Yea I was thinking alias the old methods to the new ones to keep that backwards compat is a good idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally fine - but I made a couple of comments. They are probably just personal preference things - so might not really benefit the code at all. Looking good!
src/OneSignalMessage.php
Outdated
* | ||
* @deprecated use setBody instead | ||
* | ||
* @return $this | ||
*/ | ||
public function body($value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be good to move these deprecated methods to Traits\Deprecated
to clean things up?
*/ | ||
public function setWebButtons(array $buttons) | ||
{ | ||
return $this->setParameter('web_buttons', collect($buttons)->map(function ($button) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably fine - but you could just make use of the existing method here:
collect($buttons)->each(function ($button) {
$this->setWebButton($button);
});
That way if the key every changes you only have one place to manage it - but again, probably not needed - just an idea :)
Could also apply to setButtons
?
src/OneSignalMessage.php
Outdated
|
||
/** @var array */ | ||
protected $buttons = []; | ||
use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use relative trait names here - then you could remove all of the top use
imports.
i.e.
class OneSignalMessage
{
use Traits\Categories\ButtonHelpers,
Traits\Categories\GroupingHelpers,
Traits\Categories\DeliveryHelpers,
Traits\Categories\AppearanceHelpers,
Traits\Categories\AttachmentHelpers;
But that is just a style thing - and not really needed
Thats probably the extent of my feedback - it's looking good and tests are passing! Edit: Maybe one last thing to consider is if there are any other methods that you previously could |
Add Test for Chaning Buttons (close #60)
@timacdonald Thank you for all your comments & feedback! I'v edit the points. The next days i'll add tests for all of the new methods and i'll try to refactor the tests as well |
No probs at all! |
Fixed Maximum function nesting level of '256' reached, aborting!
Sorry guys, that i currently do nothing here. This week was a little bit crazy and i haven't time for it. |
A defensive change in message class adding support for silent push notifications (in the traits branch now).
@kjostling Can you test this branch? When you can't find an error too, we can release it as a rc :) |
@timacdonald @kjostling have you tested this? Can we release it :)? |
Hey, I haven't had a chance to test this myself - but I trust you 👍 |
* Add method to set the template_id of the message * Fix typo on method for setting template * Remove contents when using a template Remove any contents set by the constructor when using the `setTemplate()` method.
Sorry for late reply, im already using this in a production env. Believe its tested from my point of view. |
Okay good :) Then i will fix the styleci errors and then i will prepare the release |
…uded) (#72) * implemented sending of notifications based on segments (included and excluded) * styleci linting * Apply fixes from StyleCI
* ability of user to send notification , filtering for multiple tags * added linting * Apply fixes from StyleCI
This PR aims to provide a cleaner Codebase and make it possible to natively set more Parameters on the Notification Creation.
Since this PR isn't ready yet, it should be a little bit a discussion between all users. Feel free to checkout the branch and make Changes too or just test it :)
Actually, i think this could be a complete rewrite known as 2.0 or what do you think?
CC @timacdonald @Lloople
// StyleCi will be fixed after this PR is feature complete