From bbfaedf42911c33d2fef80234d404de3a16a5a47 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Mon, 13 Jul 2026 08:03:32 +0700 Subject: [PATCH] clean up --- .../coop/viewmodel/ChatScreenViewModel.kt | 9 ++------- .../su/reya/coop/viewmodel/ChatViewModel.kt | 20 ------------------- .../su/reya/coop/viewmodel/ProfileCache.kt | 11 ---------- 3 files changed, 2 insertions(+), 38 deletions(-) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatScreenViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatScreenViewModel.kt index 376717c..44b300f 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatScreenViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatScreenViewModel.kt @@ -9,7 +9,6 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch -import rust.nostr.sdk.EventId import rust.nostr.sdk.UnsignedEvent import su.reya.coop.Profile import su.reya.coop.Room @@ -19,8 +18,8 @@ import su.reya.coop.roomId class ChatScreenViewModel( val id: Long, - val screening: Boolean, - private val accountRepository: AccountRepository, + screening: Boolean, + accountRepository: AccountRepository, private val chatRepository: ChatRepository, ) : ViewModel(), ErrorHost by chatRepository { val currentUser: StateFlow = accountRepository.currentUserProfile @@ -70,8 +69,4 @@ class ChatScreenViewModel( fun sendFileMessage(file: ByteArray?, type: String?) { chatRepository.sendFileMessage(id, file, type) } - - fun isMessageSent(id: EventId): Boolean { - return chatRepository.isMessageSent(id) - } } diff --git a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt index 0ce0e83..570ce07 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ChatViewModel.kt @@ -1,11 +1,8 @@ package su.reya.coop.viewmodel import androidx.lifecycle.ViewModel -import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow -import rust.nostr.sdk.EventId import rust.nostr.sdk.PublicKey -import rust.nostr.sdk.UnsignedEvent import su.reya.coop.Room import su.reya.coop.repository.ChatRepository import su.reya.coop.repository.ChatState @@ -14,28 +11,11 @@ class ChatViewModel( private val repository: ChatRepository, ) : ViewModel(), ErrorHost by repository { val state: StateFlow = repository.state - val newEvents: SharedFlow = repository.newEvents val chatRooms: StateFlow> = repository.chatRooms val isSyncing: StateFlow = repository.isSyncing val isPartialProcessedGiftWrap: StateFlow = repository.isPartialProcessedGiftWrap fun createChatRoom(to: List): Long = repository.createChatRoom(to) - fun getChatRoom(id: Long): Room? = repository.getChatRoom(id) fun refreshChatRooms() = repository.refreshChatRooms() - fun loadChatRoomMessages(roomId: Long, onResult: (List) -> Unit) = - repository.loadChatRoomMessages(roomId, onResult) - - fun chatRoomConnect(roomId: Long) = repository.chatRoomConnect(roomId) - fun sendMessage(roomId: Long, message: String, replies: List = emptyList()) = - repository.sendMessage(roomId, message, replies) - - fun sendFileMessage( - roomId: Long, - file: ByteArray?, - contentType: String? = "image/jpeg", - replies: List = emptyList() - ) = repository.sendFileMessage(roomId, file, contentType, replies) - - fun isMessageSent(id: EventId): Boolean = repository.isMessageSent(id) fun resetInternalState() = repository.resetInternalState() } diff --git a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ProfileCache.kt b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ProfileCache.kt index dd51ea8..8e6a638 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ProfileCache.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/viewmodel/ProfileCache.kt @@ -17,17 +17,6 @@ import su.reya.coop.Profile import su.reya.coop.nostr.Nostr import kotlin.time.Duration.Companion.milliseconds -/** - * Application-level singleton cache for Nostr user profiles. - * - * Replaces [NostrViewModel] as a non-ViewModel component with its own lifecycle scope. - * This is appropriate because profile caching is not screen-specific — it's a shared - * concern used by every screen that displays user metadata. - * - * Long-running tasks ([runObserver], [runMetadataBatching]) run in a dedicated - * [CoroutineScope] that outlives any individual screen, ensuring continuous operation - * regardless of navigation. - */ class ProfileCache( private val nostr: Nostr, ) : ErrorHost by createErrorHost() {