Removing LiveData Redirections

This commit is contained in:
Vitor Pamplona
2023-08-31 19:04:07 -04:00
parent 3423626c60
commit 451c5d1648
2 changed files with 13 additions and 19 deletions

View File

@@ -73,9 +73,7 @@ fun NoteAuthorPicture(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onClick: ((User) -> Unit)? = null onClick: ((User) -> Unit)? = null
) { ) {
val author by baseNote.live().metadata.map { val author by baseNote.live().authorChanges.observeAsState(baseNote.author)
it.note.author
}.distinctUntilChanged().observeAsState(baseNote.author)
Crossfade(targetState = author) { Crossfade(targetState = author) {
if (it == null) { if (it == null) {
@@ -112,23 +110,19 @@ fun UserPicture(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
val route by remember { val route by remember(user) {
derivedStateOf { derivedStateOf {
"User/${user.pubkeyHex}" "User/${user.pubkeyHex}"
} }
} }
val scope = rememberCoroutineScope()
ClickableUserPicture( ClickableUserPicture(
baseUser = user, baseUser = user,
size = size, size = size,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
modifier = pictureModifier, modifier = pictureModifier,
onClick = { onClick = {
scope.launch { nav(route)
nav(route)
}
} }
) )
} }
@@ -274,9 +268,7 @@ fun InnerBaseUserPicture(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
modifier: Modifier modifier: Modifier
) { ) {
val userProfile by baseUser.live().metadata.map { val userProfile by baseUser.live().profilePictureChanges.observeAsState(baseUser.profilePicture())
it.user.profilePicture()
}.distinctUntilChanged().observeAsState(baseUser.profilePicture())
PictureAndFollowingMark( PictureAndFollowingMark(
userHex = baseUser.pubkeyHex, userHex = baseUser.pubkeyHex,
@@ -508,9 +500,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: MutableState<Boolean>, accountVi
fun WatchBookmarksFollowsAndAccount(note: Note, accountViewModel: AccountViewModel, onNew: (DropDownParams) -> Unit) { fun WatchBookmarksFollowsAndAccount(note: Note, accountViewModel: AccountViewModel, onNew: (DropDownParams) -> Unit) {
val followState by accountViewModel.userProfile().live().follows.observeAsState() val followState by accountViewModel.userProfile().live().follows.observeAsState()
val bookmarkState by accountViewModel.userProfile().live().bookmarks.observeAsState() val bookmarkState by accountViewModel.userProfile().live().bookmarks.observeAsState()
val showSensitiveContent by accountViewModel.accountLiveData.map { val showSensitiveContent by accountViewModel.showSensitiveContentChanges.observeAsState(accountViewModel.account.showSensitiveContent)
it.account.showSensitiveContent
}.distinctUntilChanged().observeAsState(accountViewModel.account.showSensitiveContent)
LaunchedEffect(key1 = followState, key2 = bookmarkState, key3 = showSensitiveContent) { LaunchedEffect(key1 = followState, key2 = bookmarkState, key3 = showSensitiveContent) {
launch(Dispatchers.IO) { launch(Dispatchers.IO) {

View File

@@ -57,22 +57,26 @@ class AccountViewModel(val account: Account) : ViewModel() {
val userFollows: LiveData<UserState> = account.userProfile().live().follows.map { it } val userFollows: LiveData<UserState> = account.userProfile().live().follows.map { it }
val userRelays: LiveData<UserState> = account.userProfile().live().relays.map { it } val userRelays: LiveData<UserState> = account.userProfile().live().relays.map { it }
val discoveryListLiveData = accountLiveData.map { val discoveryListLiveData = account.live.map {
it.account.defaultDiscoveryFollowList it.account.defaultDiscoveryFollowList
}.distinctUntilChanged() }.distinctUntilChanged()
val homeListLiveData = accountLiveData.map { val homeListLiveData = account.live.map {
it.account.defaultHomeFollowList it.account.defaultHomeFollowList
}.distinctUntilChanged() }.distinctUntilChanged()
val notificationListLiveData = accountLiveData.map { val notificationListLiveData = account.live.map {
it.account.defaultNotificationFollowList it.account.defaultNotificationFollowList
}.distinctUntilChanged() }.distinctUntilChanged()
val storiesListLiveData = accountLiveData.map { val storiesListLiveData = account.live.map {
it.account.defaultStoriesFollowList it.account.defaultStoriesFollowList
}.distinctUntilChanged() }.distinctUntilChanged()
val showSensitiveContentChanges = account.live.map {
it.account.showSensitiveContent
}.distinctUntilChanged()
fun updateAutomaticallyStartPlayback( fun updateAutomaticallyStartPlayback(
automaticallyStartPlayback: ConnectivityType automaticallyStartPlayback: ConnectivityType
) { ) {