File tree Expand file tree Collapse file tree
src/main/java/com/example/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ public class ChatModel {
1717 private final String ntfyUrl ;
1818
1919 public ChatModel () {
20- // Hämta backend-url från env variable
2120 String url = System .getenv ("NTFY_URL" );
2221 if (url == null || url .isBlank ()) {
2322 url = "http://localhost:8080/topic/test" ; // fallback
@@ -47,7 +46,6 @@ private void sendToBackend(String message) {
4746 .build ();
4847
4948 HttpResponse <String > response = client .send (request , HttpResponse .BodyHandlers .ofString ());
50-
5149 if (response .statusCode () >= 400 ) {
5250 Platform .runLater (() -> messages .add ("Error sending message: " + response .statusCode ()));
5351 }
@@ -63,14 +61,13 @@ private void startListening() {
6361 while (true ) {
6462 HttpRequest request = HttpRequest .newBuilder ()
6563 .uri (URI .create (ntfyUrl + "/events" ))
66- .GET ()
6764 .build ();
6865
6966 client .send (request , HttpResponse .BodyHandlers .ofLines ())
7067 .body ()
7168 .forEach (line -> {
72- if (!line .isBlank () && line . startsWith ( "data:" ) ) {
73- String content = line .replaceFirst ("data:" , "" ).trim ();
69+ if (!line .isBlank ()) {
70+ String content = line .contains ( "data:" ) ? line . replaceFirst ("data:" , "" ).trim () : line ;
7471 if (!content .isEmpty ()) {
7572 Platform .runLater (() -> messages .add ("Other: " + content ));
7673 }
You can’t perform that action at this time.
0 commit comments