import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
+import java.time.Clock;
import java.time.LocalDateTime;
import java.util.*;
private final UUID id;
@Getter
private final String name;
+ private final Clock clock;
private final ChatRoomService service;
private final int bufferSize;
private Sinks.Many<Message> sink;
public ChatRoom(
UUID id,
String name,
+ Clock clock,
ChatRoomService service,
int bufferSize)
{
this.id = id;
this.name = name;
+ this.clock = clock;
this.service = service;
this.bufferSize = bufferSize;
this.sink = createSink();
synchronized public Mono<Message> addMessage(
Long id,
- LocalDateTime timestamp,
String user,
String text)
{
return service
- .persistMessage(Message.MessageKey.of(user, id), timestamp, text)
+ .persistMessage(Message.MessageKey.of(user, id), LocalDateTime.now(clock), text)
.doOnNext(message ->
{
Sinks.EmitResult result = sink.tryEmitNext(message);