WIP:refactor
authorKai Moritz <kai@juplo.de>
Wed, 25 Jan 2023 17:51:38 +0000 (18:51 +0100)
committerKai Moritz <kai@juplo.de>
Wed, 25 Jan 2023 17:51:38 +0000 (18:51 +0100)
src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java

index 9ea4cef..da5eba2 100644 (file)
@@ -66,30 +66,30 @@ public class ChatRoom
       throw new InvalidUsernameException(user);
 
     Message.MessageKey key = Message.MessageKey.of(user, id);
-
     return service
-      .getMessage(key)
-      .handle((Message existing, SynchronousSink<Message> sink) ->
-      {
-        if (existing.getMessageText().equals(text))
-        {
-          sink.next(existing);
-        }
-        else
-        {
-          sink.error(new MessageMutationException(existing, text));
-        }
-      })
-      .switchIfEmpty(Mono.defer(() -> service
-        .persistMessage(key, LocalDateTime.now(clock), text)
-        .doOnNext(m ->
+        .getMessage(key)
+        .handle((Message existing, SynchronousSink<Message> sink) ->
         {
-          Sinks.EmitResult result = sink.tryEmitNext(m);
-          if (result.isFailure())
+          if (existing.getMessageText().equals(text))
+          {
+            sink.next(existing);
+          }
+          else
           {
-            log.warn("Emitting of message failed with {} for {}", result.name(), m);
+            sink.error(new MessageMutationException(existing, text));
           }
-        })));
+        })
+        .switchIfEmpty(
+            Mono
+                .defer(() -> service.persistMessage(key, LocalDateTime.now(clock), text))
+                .doOnNext(m ->
+                {
+                  Sinks.EmitResult result = sink.tryEmitNext(m);
+                  if (result.isFailure())
+                  {
+                    log.warn("Emitting of message failed with {} for {}", result.name(), m);
+                  }
+                }));
   }