Skip to content
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

[Notifier] [Mercure] Add options #54961

Open
wants to merge 19 commits into
base: 7.2
Choose a base branch
from
Open

Conversation

ernie76
Copy link

@ernie76 ernie76 commented May 17, 2024

Q A
Branch? 7.1
Bug fix? no
New feature? yes
Deprecations? no
License MIT

Added body, icon, tag ,renotify for desktop notifications in Symfony UX
This pull-request are need changes in src/Notify/assets/dist/controller.js I have made a pull request there too.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 17, 2024
@ernie76
Copy link
Author

ernie76 commented May 17, 2024

this PR connect to this PR symfony/ux#1853

@ernie76 ernie76 changed the title Notifier mercure [Notifier] mercure add body, icon, tag ,renotify May 17, 2024
@OskarStark OskarStark changed the title [Notifier] mercure add body, icon, tag ,renotify [Notifier][Mercure] Add body, icon, tag ,renotify May 21, 2024
Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
@chapterjason
Copy link
Contributor

chapterjason commented May 21, 2024

I just noticed that renotify is not supported in Firefox and Safari according to developer.mozilla.org; and there seem to be more properties than just those 4.

@ernie76
Copy link
Author

ernie76 commented May 21, 2024

I just noticed that renotify is not supported in Firefox and Safari according to developer.mozilla.org; and there seem to be more properties than just those 4.

you need this option in google chrome

@chapterjason
Copy link
Contributor

chapterjason commented May 21, 2024

I just noticed that renotify is not supported in Firefox and Safari according to developer.mozilla.org; and there seem to be more properties than just those 4.

you need this option in google chrome

Might be the case, couldn't find any example/issue that this is the case, but why excluding other browsers and not use just a simple array to dynamically pass the possible options?

My recommendation:

  • Replace args for the options with an array
  • Add type doc with a reference to developer.mozilla.org, optionally define array shape
  • Just pass the array (Also reduces the named arguments and multiple JSON.parse calls in ux package)

It also looks like the resulting activity stream doesn't fit the spec: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce.

This might fit the spec more:

{
   "@context":"https://www.w3.org/ns/activitystreams",
   "type":"Announce",
   "summary":"subject",
   "mediaType": "application/json",
   "content": "{\"body\":null,\"icon\":null,\"tag\":null,\"renotify\":false}"
}

@ernie76
Copy link
Author

ernie76 commented May 22, 2024

@chapterjason it's a good idea
i close this PR and the PR on the ux side, and try it again.
is this ok?

@chapterjason
Copy link
Contributor

@ernie76 You don't need to create new ones, just modify it, that's what PRs are about, they are evolving. I really like the initial idea, as it gives more control without creating any JS.

Sven Scholz added 2 commits May 22, 2024 10:23
@OskarStark OskarStark changed the title [Notifier][Mercure] Add body, icon, tag ,renotify [Notifier][Mercure] Add body, icon, tag ,renotify May 22, 2024
@ernie76 ernie76 changed the title [Notifier][Mercure] Add body, icon, tag ,renotify [Notifier][Mercure] Add options May 22, 2024
@ernie76
Copy link
Author

ernie76 commented May 23, 2024

@chapterjason is this so ok now?

$this->topics = $topics ?? 'https://symfony.com/notifier';

parent::__construct($client, $dispatcher);
}

public function __toString(): string
{
return sprintf('mercure://%s%s', $this->hubId, '?'.http_build_query(['topic' => $this->topics], '', '&'));
return sprintf('mercure://%s%s', $this->hubId, null !== $this->topics ? '?'.http_build_query(['topic' => $this->topics], '', '&') : '');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why checking for null if constructor always sets a topic in that case?

@@ -30,18 +30,17 @@
*/
final class MercureTransport extends AbstractTransport
{
private HubInterface $hub;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be reverted, we already had promoted properties

@ernie76 ernie76 requested a review from OskarStark May 29, 2024 07:14
@@ -30,18 +30,16 @@
*/
final class MercureTransport extends AbstractTransport
{
private string $hubId;
Copy link
Contributor

Choose a reason for hiding this comment

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

can be removed

Comment on lines 38 to 44
public function __construct(
private HubInterface $hub,
private string $hubId,
string|array|null $topics = null,
?HttpClientInterface $client = null,
?EventDispatcherInterface $dispatcher = null,
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please keep this

]);
}

public function testConstructWithParameters()
{
$options = (new MercureOptions('/topic/1', true, 'id', 'type', 1));
$options = (new MercureOptions('/topic/1', true, 'id', 'type', 1, null));
Copy link
Contributor

Choose a reason for hiding this comment

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

I would provide a text here, rather than null

optionstest with options
ernie76 and others added 2 commits May 29, 2024 13:42
…ionsTest.php

Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
…ionsTest.php

Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
@@ -1,6 +1,9 @@
CHANGELOG
=========

* Add content to MercureOptions.php for Symfony UX Notify
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a new 7.2 section and add only

 * Add `content` option

Sven Scholz and others added 3 commits May 29, 2024 13:46
….php

Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
….php

Co-authored-by: Oskar Stark <oskarstark@googlemail.com>
@@ -77,6 +77,8 @@ protected function doSend(MessageInterface $message): SentMessage
'@context' => 'https://www.w3.org/ns/activitystreams',
'type' => 'Announce',
'summary' => $message->getSubject(),
'mediaType' => 'application/json',
'content' => $options->getContent(),
Copy link
Contributor

Choose a reason for hiding this comment

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

To make it fit correctly it should be serialized to json here. (Only the value of the content entry)

For now I think it is enough to just inject the Serializer and always encode to json. To keep this PR simple.

I would also add an test to cover this case.

@carsonbot carsonbot changed the title [Notifier][Mercure] Add options [Mercure] Add options May 29, 2024
@chapterjason
Copy link
Contributor

Hey @ernie76 a bit busy the last days, only one thing, everything else looks good. 👍🏼

@carsonbot carsonbot changed the title [Mercure] Add options [Notifier] [Mercure] Add options May 29, 2024
@ernie76 ernie76 requested a review from chapterjason June 3, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants