Skip to content

Commit

Permalink
Optimizing UserProfile status
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed May 28, 2023
1 parent 013eedd commit b513877
Showing 1 changed file with 22 additions and 3 deletions.
Expand Up @@ -439,20 +439,39 @@ private fun ProfileActions(
coroutineScope: CoroutineScope
) {
val accountUserState by account.userProfile().live().follows.observeAsState()
val accountLocalUserState by account.live.observeAsState()
val accountUser = remember(accountUserState) { accountUserState?.user } ?: return

val isHidden by remember(accountUserState, accountLocalUserState) {
derivedStateOf {
account.isHidden(baseUser)
}
}

val isLoggedInFollowingUser by remember(accountUserState, accountLocalUserState) {
derivedStateOf {
accountUser.isFollowingCached(baseUser)
}
}

val isUserFollowingLoggedIn by remember(accountUserState, accountLocalUserState) {
derivedStateOf {
baseUser.isFollowingCached(accountUser)
}
}

if (accountUser == baseUser) {
EditButton(account)
}

if (account.isHidden(baseUser)) {
if (isHidden) {
ShowUserButton {
account.showUser(baseUser.pubkeyHex)
}
} else if (accountUser.isFollowingCached(baseUser)) {
} else if (isLoggedInFollowingUser) {
UnfollowButton { coroutineScope.launch(Dispatchers.IO) { account.unfollow(baseUser) } }
} else {
if (baseUser.isFollowingCached(accountUser)) {
if (isUserFollowingLoggedIn) {
FollowButton(
{ coroutineScope.launch(Dispatchers.IO) { account.follow(baseUser) } },
R.string.follow_back
Expand Down

0 comments on commit b513877

Please sign in to comment.