Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Fix receiving POST message push requests on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
mklkj committed Feb 11, 2024
1 parent d3bbd4e commit 352b769
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ConversationClient(
fun sendMessage(message: MessageRequest) {
val chatId = chatId ?: return

// todo: add error handler!
scope.launch {
when (chatSession) {
null -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ fun Route.chatRoutes() {
post("/{id}/messages") {
val userId = call.principalId ?: error("Invalid JWT token")
val chatId = call.parameters.getOrFail("id").toUUID()
val message = call.receive<MessagePush>()
val message = call.receive<MessageEvent>()
val participants = chatService.getParticipants(chatId)

// todo: add verification whether a given user can write to that chat!!!
if (message !is MessagePush) return@post

val entity = MessageEntity(
id = message.id,
chatId = chatId,
userId = userId,
timestamp = Clock.System.now(),
content = message.content,
)
// todo: add verification whether a given user can write to that chat!!!
messageService.saveMessage(entity)

val connections = chatConnections.getConnections(chatId)
Expand Down Expand Up @@ -185,7 +187,7 @@ fun Route.chatWebsockets() {

// not handled on server
is MessageBroadcast -> Unit
is TypingBroadcast -> TODO()
is TypingBroadcast -> Unit
}
}
.collect()
Expand Down

0 comments on commit 352b769

Please sign in to comment.