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