From 8f7eccec050843b0764ae45c4b9ee0cd4d1591e3 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Wed, 27 May 2026 11:32:00 +0700 Subject: [PATCH] update create chat room --- .../commonMain/kotlin/su/reya/coop/NostrViewModel.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index a33c00e..241090d 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -417,8 +417,19 @@ class NostrViewModel( .tags(to.map { Tag.publicKey(it) }) .build(nostr.signer.currentUser!!) + // Check if the room already exists + val id = rumor.roomId() + val existingRoom = _chatRooms.value.firstOrNull { it.id == id } + + // If the room already exists, return its ID + if (existingRoom != null) { + return existingRoom.id + } + // Create a room from the rumor event val room = Room.new(rumor, nostr.signer.currentUser!!) + + // Update the chat rooms state _chatRooms.update { currentRooms -> currentRooms + room }