use ntfy JSON API so notification titles support non-ASCII characters (#2398)

This commit is contained in:
Athou
2026-11-19 21:27:51 +01:00
parent fe5ff7f721
commit abf9e2cd85
3 changed files with 22 additions and 10 deletions

View File

@@ -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());
}

View File

@@ -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));

View File

@@ -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