Removing unecessary livedata objects for translation services

This commit is contained in:
Vitor Pamplona 2024-08-16 17:10:02 -04:00
parent 239f973e89
commit ec83ad9d20
3 changed files with 3 additions and 10 deletions

View File

@ -219,7 +219,6 @@ class Account(
// Observers line up here.
val live: AccountLiveData = AccountLiveData(this)
val liveLanguages: AccountLiveData = AccountLiveData(this)
val saveable: AccountLiveData = AccountLiveData(this)
@Immutable
@ -2831,21 +2830,16 @@ class Account(
fun updateLocalRelayServers(servers: Set<String>) {
localRelayServers = servers
liveLanguages.invalidateData()
saveable.invalidateData()
}
fun addDontTranslateFrom(languageCode: String) {
dontTranslateFrom = dontTranslateFrom.plus(languageCode)
liveLanguages.invalidateData()
saveable.invalidateData()
}
fun updateTranslateTo(languageCode: String) {
translateTo = languageCode
liveLanguages.invalidateData()
saveable.invalidateData()
}

View File

@ -148,7 +148,6 @@ class AccountViewModel(
) : ViewModel(),
Dao {
val accountLiveData: LiveData<AccountState> = account.live.map { it }
val accountLanguagesLiveData: LiveData<AccountState> = account.liveLanguages.map { it }
// TODO: contact lists are not notes yet
// val kind3Relays: StateFlow<ContactListEvent?> = observeByAuthor(ContactListEvent.KIND, account.signer.pubKey)

View File

@ -42,7 +42,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
@ -366,9 +365,10 @@ fun TranslateAndWatchLanguageChanges(
accountViewModel: AccountViewModel,
onTranslated: (TranslationConfig) -> Unit,
) {
val accountState by accountViewModel.accountLanguagesLiveData.observeAsState()
// Don't automatically update translations.
// val accountState by accountViewModel.accountLanguagesLiveData.observeAsState()
LaunchedEffect(accountState) {
LaunchedEffect(Unit) {
// This takes some time. Launches as a Composition scope to make sure this gets cancel if this
// item gets out of view.
withContext(Dispatchers.IO) {