mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-20 10:43:37 +00:00
use ntfy JSON API so notification titles support non-ASCII characters (#2398)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user