mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-20 02:33:33 +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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleRequestBuilder request = SimpleRequestBuilder.post(serverUrl + "/" + topic);
|
JsonObject json = new JsonObject();
|
||||||
request.addHeader("Title", feedTitle);
|
json.put("topic", topic);
|
||||||
request.setBody(entryTitle, ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8));
|
json.put("title", feedTitle);
|
||||||
|
json.put("message", entryTitle);
|
||||||
if (StringUtils.isNotBlank(entryUrl)) {
|
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())) {
|
if (StringUtils.isNotBlank(settings.getUserSecret())) {
|
||||||
request.addHeader("Authorization", "Bearer " + settings.getUserSecret());
|
request.addHeader("Authorization", "Bearer " + settings.getUserSecret());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,16 +64,25 @@ class PushNotificationServiceTest {
|
|||||||
userSettings.setServerUrl("http://localhost:" + mockServerClient.getPort());
|
userSettings.setServerUrl("http://localhost:" + mockServerClient.getPort());
|
||||||
userSettings.setTopic("test-topic");
|
userSettings.setTopic("test-topic");
|
||||||
userSettings.setUserSecret("test-secret");
|
userSettings.setUserSecret("test-secret");
|
||||||
|
subscription.setTitle("ąćęłńóśźż 📰 Test Feed");
|
||||||
|
|
||||||
mockServerClient
|
mockServerClient
|
||||||
.when(
|
.when(
|
||||||
HttpRequest.request()
|
HttpRequest.request()
|
||||||
.withMethod("POST")
|
.withMethod("POST")
|
||||||
.withPath("/test-topic")
|
.withPath("/")
|
||||||
.withHeader("Title", "Test Feed")
|
|
||||||
.withHeader("Click", "http://example.com/entry")
|
|
||||||
.withHeader("Authorization", "Bearer test-secret")
|
.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));
|
.respond(HttpResponse.response().withStatusCode(200));
|
||||||
|
|
||||||
Assertions.assertDoesNotThrow(() -> pushNotificationService.notify(userSettings, subscription, entry));
|
Assertions.assertDoesNotThrow(() -> pushNotificationService.notify(userSettings, subscription, entry));
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class PushNotificationIT extends BaseIT {
|
|||||||
@Test
|
@Test
|
||||||
void receivedPushNotifications() throws IOException {
|
void receivedPushNotifications() throws IOException {
|
||||||
// mock ntfy server
|
// 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));
|
getMockServerClient().when(ntfyPost).respond(HttpResponse.response().withStatusCode(200));
|
||||||
|
|
||||||
// enable push notifications
|
// enable push notifications
|
||||||
|
|||||||
Reference in New Issue
Block a user