This commit is contained in:
2026-07-13 08:03:32 +07:00
parent 40da451f4e
commit bbfaedf429
3 changed files with 2 additions and 38 deletions

View File

@@ -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<Profile?> = 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)
}
}

View File

@@ -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<ChatState> = repository.state
val newEvents: SharedFlow<UnsignedEvent> = repository.newEvents
val chatRooms: StateFlow<List<Room>> = repository.chatRooms
val isSyncing: StateFlow<Boolean> = repository.isSyncing
val isPartialProcessedGiftWrap: StateFlow<Boolean> = repository.isPartialProcessedGiftWrap
fun createChatRoom(to: List<PublicKey>): Long = repository.createChatRoom(to)
fun getChatRoom(id: Long): Room? = repository.getChatRoom(id)
fun refreshChatRooms() = repository.refreshChatRooms()
fun loadChatRoomMessages(roomId: Long, onResult: (List<UnsignedEvent>) -> Unit) =
repository.loadChatRoomMessages(roomId, onResult)
fun chatRoomConnect(roomId: Long) = repository.chatRoomConnect(roomId)
fun sendMessage(roomId: Long, message: String, replies: List<EventId> = emptyList()) =
repository.sendMessage(roomId, message, replies)
fun sendFileMessage(
roomId: Long,
file: ByteArray?,
contentType: String? = "image/jpeg",
replies: List<EventId> = emptyList()
) = repository.sendFileMessage(roomId, file, contentType, replies)
fun isMessageSent(id: EventId): Boolean = repository.isMessageSent(id)
fun resetInternalState() = repository.resetInternalState()
}

View File

@@ -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() {