mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-25 19:56:47 +02:00
Moves Show And Hide user functions from ComposeScoped to ViewModel Scoped
This commit is contained in:
@@ -253,10 +253,8 @@ private fun RenderMainPopup(
|
||||
stringResource(R.string.quick_action_block)
|
||||
) {
|
||||
if (accountViewModel.hideBlockAlertDialog) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
note.author?.let { accountViewModel.hide(it) }
|
||||
onDismiss()
|
||||
}
|
||||
note.author?.let { accountViewModel.hide(it) }
|
||||
onDismiss()
|
||||
} else {
|
||||
showBlockAlertDialog.value = true
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.FollowButton
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ShowUserButton
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.UnfollowButton
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.WatchIsHiddenUser
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.showAmountAxis
|
||||
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size55dp
|
||||
@@ -172,24 +173,14 @@ fun UserActionOptions(
|
||||
baseAuthor: User,
|
||||
accountViewModel: AccountViewModel
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||
val blockList by accountViewModel.account.getBlockListNote().live().metadata.observeAsState()
|
||||
|
||||
val isHidden by remember(accountState, blockList) {
|
||||
derivedStateOf {
|
||||
accountState?.account?.isHidden(baseAuthor) ?: false
|
||||
}
|
||||
}
|
||||
|
||||
if (isHidden) {
|
||||
ShowUserButton {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
WatchIsHiddenUser(baseAuthor, accountViewModel) { isHidden ->
|
||||
if (isHidden) {
|
||||
ShowUserButton {
|
||||
accountViewModel.show(baseAuthor)
|
||||
}
|
||||
} else {
|
||||
ShowFollowingOrUnfollowingButton(baseAuthor, accountViewModel)
|
||||
}
|
||||
} else {
|
||||
ShowFollowingOrUnfollowingButton(baseAuthor, accountViewModel)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -252,14 +252,6 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
||||
return account.decryptZapContentAuthor(note)
|
||||
}
|
||||
|
||||
fun hide(user: User) {
|
||||
account.hideUser(user.pubkeyHex)
|
||||
}
|
||||
|
||||
fun show(user: User) {
|
||||
account.showUser(user.pubkeyHex)
|
||||
}
|
||||
|
||||
fun translateTo(lang: Locale) {
|
||||
account.updateTranslateTo(lang.language)
|
||||
}
|
||||
@@ -360,6 +352,24 @@ class AccountViewModel(val account: Account) : ViewModel() {
|
||||
return account.unseal(event)
|
||||
}
|
||||
|
||||
fun show(user: User) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
account.showUser(user.pubkeyHex)
|
||||
}
|
||||
}
|
||||
|
||||
fun hide(user: User) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
account.hideUser(user.pubkeyHex)
|
||||
}
|
||||
}
|
||||
|
||||
fun showUser(pubkeyHex: String) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
account.showUser(pubkeyHex)
|
||||
}
|
||||
}
|
||||
|
||||
class Factory(val account: Account) : ViewModelProvider.Factory {
|
||||
override fun <AccountViewModel : ViewModel> create(modelClass: Class<AccountViewModel>): AccountViewModel {
|
||||
return AccountViewModel(account) as AccountViewModel
|
||||
|
@@ -717,11 +717,8 @@ private fun ProfileActions(
|
||||
|
||||
WatchIsHiddenUser(baseUser, accountViewModel) { isHidden ->
|
||||
if (isHidden) {
|
||||
val scope = rememberCoroutineScope()
|
||||
ShowUserButton {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.account.showUser(baseUser.pubkeyHex)
|
||||
}
|
||||
accountViewModel.showUser(baseUser.pubkeyHex)
|
||||
}
|
||||
} else {
|
||||
DisplayFollowUnfollowButton(baseUser, accountViewModel)
|
||||
@@ -805,7 +802,7 @@ private fun DisplayFollowUnfollowButton(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WatchIsHiddenUser(baseUser: User, accountViewModel: AccountViewModel, content: @Composable (Boolean) -> Unit) {
|
||||
fun WatchIsHiddenUser(baseUser: User, accountViewModel: AccountViewModel, content: @Composable (Boolean) -> Unit) {
|
||||
val isHidden by accountViewModel.account.liveHiddenUsers.map {
|
||||
it.hiddenUsers.contains(baseUser.pubkeyHex) || it.spammers.contains(baseUser.pubkeyHex)
|
||||
}.observeAsState(accountViewModel.account.isHidden(baseUser))
|
||||
@@ -1654,79 +1651,56 @@ fun UserProfileDropDownMenu(user: User, popupExpanded: Boolean, onDismiss: () ->
|
||||
onDismissRequest = onDismiss
|
||||
) {
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
||||
val account = accountState?.account!!
|
||||
val blockList by accountViewModel.account.getBlockListNote().live().metadata.observeAsState()
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
DropdownMenuItem(onClick = { clipboardManager.setText(AnnotatedString(user.pubkeyNpub())); onDismiss() }) {
|
||||
Text(stringResource(R.string.copy_user_id))
|
||||
}
|
||||
|
||||
if (account.userProfile() != user) {
|
||||
if (accountViewModel.userProfile() != user) {
|
||||
Divider()
|
||||
if (account.isHidden(user)) {
|
||||
if (accountViewModel.account.isHidden(user)) {
|
||||
DropdownMenuItem(onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.show(user)
|
||||
onDismiss()
|
||||
}
|
||||
accountViewModel.show(user)
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(stringResource(R.string.unblock_user))
|
||||
}
|
||||
} else {
|
||||
DropdownMenuItem(onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.hide(user)
|
||||
onDismiss()
|
||||
}
|
||||
accountViewModel.hide(user)
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(stringResource(id = R.string.block_hide_user))
|
||||
}
|
||||
}
|
||||
Divider()
|
||||
DropdownMenuItem(onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.report(user, ReportEvent.ReportType.SPAM)
|
||||
accountViewModel.hide(user)
|
||||
}
|
||||
accountViewModel.report(user, ReportEvent.ReportType.SPAM)
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(stringResource(id = R.string.report_spam_scam))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.report(user, ReportEvent.ReportType.PROFANITY)
|
||||
accountViewModel.hide(user)
|
||||
}
|
||||
accountViewModel.report(user, ReportEvent.ReportType.PROFANITY)
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(stringResource(R.string.report_hateful_speech))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.report(user, ReportEvent.ReportType.IMPERSONATION)
|
||||
accountViewModel.hide(user)
|
||||
}
|
||||
accountViewModel.report(user, ReportEvent.ReportType.IMPERSONATION)
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(stringResource(id = R.string.report_impersonation))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.report(user, ReportEvent.ReportType.NUDITY)
|
||||
accountViewModel.hide(user)
|
||||
}
|
||||
accountViewModel.report(user, ReportEvent.ReportType.NUDITY)
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(stringResource(R.string.report_nudity_porn))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
accountViewModel.report(user, ReportEvent.ReportType.ILLEGAL)
|
||||
accountViewModel.hide(user)
|
||||
}
|
||||
accountViewModel.report(user, ReportEvent.ReportType.ILLEGAL)
|
||||
onDismiss()
|
||||
}) {
|
||||
Text(stringResource(id = R.string.report_illegal_behaviour))
|
||||
|
Reference in New Issue
Block a user