Skip to content

Commit

Permalink
Removing unecessary livedata objects for translation services
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Aug 16, 2024
1 parent 239f973 commit ec83ad9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ec83ad9

Please sign in to comment.