From abf9e2cd85b52a9c966425683e70693b1122e2de Mon Sep 17 00:00:00 2001 From: Athou Date: Thu, 19 Nov 2026 21:27:51 +0100 Subject: [PATCH] use ntfy JSON API so notification titles support non-ASCII characters (#2398) --- .../service/PushNotificationService.java | 13 ++++++++----- .../service/PushNotificationServiceTest.java | 17 +++++++++++++---- .../integration/PushNotificationIT.java | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java b/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java index f118074d..f5f11998 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/service/PushNotificationService.java @@ -95,14 +95,17 @@ public class PushNotificationService { return; } - SimpleRequestBuilder request = SimpleRequestBuilder.post(serverUrl + "/" + topic); - request.addHeader("Title", feedTitle); - request.setBody(entryTitle, ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)); - + JsonObject json = new JsonObject(); + json.put("topic", topic); + json.put("title", feedTitle); + json.put("message", entryTitle); if (StringUtils.isNotBlank(entryUrl)) { - request.addHeader("Click", entryUrl); + json.put("click", entryUrl); } + SimpleRequestBuilder request = SimpleRequestBuilder.post(serverUrl); + request.setBody(json.toString(), ContentType.APPLICATION_JSON); + if (StringUtils.isNotBlank(settings.getUserSecret())) { request.addHeader("Authorization", "Bearer " + settings.getUserSecret()); } diff --git a/commafeed-server/src/test/java/com/commafeed/backend/service/PushNotificationServiceTest.java b/commafeed-server/src/test/java/com/commafeed/backend/service/PushNotificationServiceTest.java index f91fb5eb..750210c7 100644 --- a/commafeed-server/src/test/java/com/commafeed/backend/service/PushNotificationServiceTest.java +++ b/commafeed-server/src/test/java/com/commafeed/backend/service/PushNotificationServiceTest.java @@ -64,16 +64,25 @@ class PushNotificationServiceTest { userSettings.setServerUrl("http://localhost:" + mockServerClient.getPort()); userSettings.setTopic("test-topic"); userSettings.setUserSecret("test-secret"); + subscription.setTitle("ąćęłńóśźż 📰 Test Feed"); mockServerClient .when( HttpRequest.request() .withMethod("POST") - .withPath("/test-topic") - .withHeader("Title", "Test Feed") - .withHeader("Click", "http://example.com/entry") + .withPath("/") .withHeader("Authorization", "Bearer test-secret") - .withBody("Test Entry")) + .withContentType(MediaType.APPLICATION_JSON_UTF_8) + .withBody( + JsonBody.json( + """ + { + "topic": "test-topic", + "title": "ąćęłńóśźż 📰 Test Feed", + "message": "Test Entry", + "click": "http://example.com/entry" + } + """))) .respond(HttpResponse.response().withStatusCode(200)); Assertions.assertDoesNotThrow(() -> pushNotificationService.notify(userSettings, subscription, entry)); diff --git a/commafeed-server/src/test/java/com/commafeed/integration/PushNotificationIT.java b/commafeed-server/src/test/java/com/commafeed/integration/PushNotificationIT.java index a46d8c68..13c236b9 100644 --- a/commafeed-server/src/test/java/com/commafeed/integration/PushNotificationIT.java +++ b/commafeed-server/src/test/java/com/commafeed/integration/PushNotificationIT.java @@ -40,7 +40,7 @@ class PushNotificationIT extends BaseIT { @Test void receivedPushNotifications() throws IOException { // mock ntfy server - HttpRequest ntfyPost = HttpRequest.request().withMethod("POST").withPath("/ntfy/integration-test"); + HttpRequest ntfyPost = HttpRequest.request().withMethod("POST").withPath("/ntfy"); getMockServerClient().when(ntfyPost).respond(HttpResponse.response().withStatusCode(200)); // enable push notifications