Last active
July 13, 2021 04:46
-
-
Save amencke/09f553514c62dd3b38108568e3792daa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override def onMessage(msg: SessionCommand): Behavior[SessionCommand] = | |
msg match { | |
case PostMessage(conversationID, sender, message) => | |
context.log.info(s"${sender} posted to conversation ${conversationID}: ${message}") | |
persistentEventSourcedActor ! PostMessage(conversationID, sender, message) | |
idle() | |
case GetHistory(conversationID, requester, replyTo) => | |
context.log.info(s"Retrieving history of conversation ${conversationID} for ${requester}") | |
val maybeHistory: Future[ConversationHistory] = | |
persistentEventSourcedActor.ask(GetHistory(conversationID, requester, _)) | |
maybeHistory.onComplete { | |
case Success(conversationHistory) => | |
replyTo ! conversationHistory | |
case Failure(_) => | |
replyTo ! ConversationHistory(Map.empty[ConversationID, List[(UserID, String)]]) | |
case _ => | |
} | |
Await.ready(maybeHistory, requestTimeout) | |
idle() | |
case DeleteConversation(conversationID, replyTo) => | |
context.log.info(s"Deleting history of conversation ${conversationID}") | |
val maybeDeleted = persistentEventSourcedActor.askWithStatus(DeleteConversation(conversationID, _)) | |
maybeDeleted onComplete { | |
case Success(res) => replyTo ! StatusReply.Success(res) | |
case Failure(res) => replyTo ! StatusReply.error(res) | |
} | |
Await.ready(maybeDeleted, requestTimeout) | |
idle() | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment