chore: clean up codebase #42

Merged
reya merged 6 commits from cleanup into master 2026-07-13 01:04:16 +00:00
3 changed files with 2 additions and 38 deletions
Showing only changes of commit bbfaedf429 - Show all commits

View File

@@ -9,7 +9,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import rust.nostr.sdk.EventId
import rust.nostr.sdk.UnsignedEvent import rust.nostr.sdk.UnsignedEvent
import su.reya.coop.Profile import su.reya.coop.Profile
import su.reya.coop.Room import su.reya.coop.Room
@@ -19,8 +18,8 @@ import su.reya.coop.roomId
class ChatScreenViewModel( class ChatScreenViewModel(
val id: Long, val id: Long,
val screening: Boolean, screening: Boolean,
private val accountRepository: AccountRepository, accountRepository: AccountRepository,
private val chatRepository: ChatRepository, private val chatRepository: ChatRepository,
) : ViewModel(), ErrorHost by chatRepository { ) : ViewModel(), ErrorHost by chatRepository {
val currentUser: StateFlow<Profile?> = accountRepository.currentUserProfile val currentUser: StateFlow<Profile?> = accountRepository.currentUserProfile
@@ -70,8 +69,4 @@ class ChatScreenViewModel(
fun sendFileMessage(file: ByteArray?, type: String?) { fun sendFileMessage(file: ByteArray?, type: String?) {
chatRepository.sendFileMessage(id, file, type) 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 package su.reya.coop.viewmodel
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import rust.nostr.sdk.EventId
import rust.nostr.sdk.PublicKey import rust.nostr.sdk.PublicKey
import rust.nostr.sdk.UnsignedEvent
import su.reya.coop.Room import su.reya.coop.Room
import su.reya.coop.repository.ChatRepository import su.reya.coop.repository.ChatRepository
import su.reya.coop.repository.ChatState import su.reya.coop.repository.ChatState
@@ -14,28 +11,11 @@ class ChatViewModel(
private val repository: ChatRepository, private val repository: ChatRepository,
) : ViewModel(), ErrorHost by repository { ) : ViewModel(), ErrorHost by repository {
val state: StateFlow<ChatState> = repository.state val state: StateFlow<ChatState> = repository.state
val newEvents: SharedFlow<UnsignedEvent> = repository.newEvents
val chatRooms: StateFlow<List<Room>> = repository.chatRooms val chatRooms: StateFlow<List<Room>> = repository.chatRooms
val isSyncing: StateFlow<Boolean> = repository.isSyncing val isSyncing: StateFlow<Boolean> = repository.isSyncing
val isPartialProcessedGiftWrap: StateFlow<Boolean> = repository.isPartialProcessedGiftWrap val isPartialProcessedGiftWrap: StateFlow<Boolean> = repository.isPartialProcessedGiftWrap
fun createChatRoom(to: List<PublicKey>): Long = repository.createChatRoom(to) fun createChatRoom(to: List<PublicKey>): Long = repository.createChatRoom(to)
fun getChatRoom(id: Long): Room? = repository.getChatRoom(id)
fun refreshChatRooms() = repository.refreshChatRooms() 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() fun resetInternalState() = repository.resetInternalState()
} }

View File

@@ -17,17 +17,6 @@ import su.reya.coop.Profile
import su.reya.coop.nostr.Nostr import su.reya.coop.nostr.Nostr
import kotlin.time.Duration.Companion.milliseconds 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( class ProfileCache(
private val nostr: Nostr, private val nostr: Nostr,
) : ErrorHost by createErrorHost() { ) : ErrorHost by createErrorHost() {