diff --git a/assets/controllers/notification_controller.js b/assets/controllers/notification_controller.js index 65df6df..16576c5 100644 --- a/assets/controllers/notification_controller.js +++ b/assets/controllers/notification_controller.js @@ -4,7 +4,8 @@ export default class extends Controller { static targets = ['badge', 'list']; static values = { userId: Number, - mercureUrl: String + mercureUrl: String, + url: String, }; connect() { @@ -39,7 +40,7 @@ export default class extends Controller { // Use server-provided topic if available, otherwise fallback to default per-user topic - const topic = data.topic || `http://portail.solutions-easy.moi/notifications/user/${this.userIdValue}`; + const topic = data.topic || `${this.urlValue}/notifications/user/${this.userIdValue}`; const url = new URL(this.mercureUrlValue); url.searchParams.append('topic', topic); diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 19608e6..604995e 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -5,6 +5,7 @@ twig: globals: application: '%env(APPLICATION)%' aws_url: '%env(AWS_S3_PORTAL_URL)%' + app_url: '%env(APP_URL)%' version: '0.5' paths: diff --git a/config/services.yaml b/config/services.yaml index 0d3aa13..b6113ee 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -7,6 +7,7 @@ parameters: aws_url: '%env(AWS_ENDPOINT)%' aws_public_url: '%env(AWS_ENDPOINT)%' aws_bucket: '%env(S3_PORTAL_BUCKET)%' + app_url: '%env(APP_URL)%' mercure_secret: '%env(MERCURE_JWT_SECRET)%' logos_directory: '%kernel.project_dir%/public/uploads/logos' @@ -24,6 +25,9 @@ services: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' + App\MessageHandler\NotificationMessageHandler: + arguments: + $appUrl: '%app_url%' App\EventSubscriber\: resource: '../src/EventSubscriber/' tags: ['kernel.event_subscriber'] diff --git a/src/MessageHandler/NotificationMessageHandler.php b/src/MessageHandler/NotificationMessageHandler.php index 3647ed6..29e1f3b 100644 --- a/src/MessageHandler/NotificationMessageHandler.php +++ b/src/MessageHandler/NotificationMessageHandler.php @@ -16,7 +16,8 @@ class NotificationMessageHandler { public function __construct( private readonly EntityManagerInterface $entityManager, - private readonly HubInterface $hub + private readonly HubInterface $hub, + private string $appUrl ) { } @@ -48,7 +49,7 @@ class NotificationMessageHandler private function publishToMercure(Notification $notification): void { - $topic = sprintf('http://portail.solutions-easy.moi/notifications/user/%d', $notification->getUser()->getId()); + $topic = sprintf('%s/notifications/user/%d', $this->appUrl, $notification->getUser()->getId()); $update = new Update( $topic, diff --git a/templates/elements/navbar.html.twig b/templates/elements/navbar.html.twig index a701010..b92e280 100644 --- a/templates/elements/navbar.html.twig +++ b/templates/elements/navbar.html.twig @@ -43,6 +43,7 @@