mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-27 21:47:07 +02:00
Refactoring calls to check if a user is the signed in user.
This commit is contained in:
@@ -820,7 +820,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit,
|
|||||||
expanded = popupExpanded,
|
expanded = popupExpanded,
|
||||||
onDismissRequest = onDismiss
|
onDismissRequest = onDismiss
|
||||||
) {
|
) {
|
||||||
if (!accountViewModel.isFollowing(note.author!!)) {
|
if (!accountViewModel.isFollowing(note.author)) {
|
||||||
DropdownMenuItem(onClick = {
|
DropdownMenuItem(onClick = {
|
||||||
accountViewModel.follow(
|
accountViewModel.follow(
|
||||||
note.author ?: return@DropdownMenuItem
|
note.author ?: return@DropdownMenuItem
|
||||||
@@ -860,14 +860,12 @@ fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit,
|
|||||||
DropdownMenuItem(onClick = { accountViewModel.broadcast(note); onDismiss() }) {
|
DropdownMenuItem(onClick = { accountViewModel.broadcast(note); onDismiss() }) {
|
||||||
Text(stringResource(R.string.broadcast))
|
Text(stringResource(R.string.broadcast))
|
||||||
}
|
}
|
||||||
if (note.author == accountViewModel.accountLiveData.value?.account?.userProfile()) {
|
|
||||||
Divider()
|
Divider()
|
||||||
|
if (accountViewModel.isLoggedUser(note.author)) {
|
||||||
DropdownMenuItem(onClick = { accountViewModel.delete(note); onDismiss() }) {
|
DropdownMenuItem(onClick = { accountViewModel.delete(note); onDismiss() }) {
|
||||||
Text(stringResource(R.string.request_deletion))
|
Text(stringResource(R.string.request_deletion))
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if (note.author != accountViewModel.accountLiveData.value?.account?.userProfile()) {
|
|
||||||
Divider()
|
|
||||||
DropdownMenuItem(onClick = { reportDialogShowing = true }) {
|
DropdownMenuItem(onClick = { reportDialogShowing = true }) {
|
||||||
Text("Block / Report")
|
Text("Block / Report")
|
||||||
}
|
}
|
||||||
|
@@ -98,7 +98,7 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
|
|||||||
var showDeleteAlertDialog by remember { mutableStateOf(false) }
|
var showDeleteAlertDialog by remember { mutableStateOf(false) }
|
||||||
var showBlockAlertDialog by remember { mutableStateOf(false) }
|
var showBlockAlertDialog by remember { mutableStateOf(false) }
|
||||||
var showReportDialog by remember { mutableStateOf(false) }
|
var showReportDialog by remember { mutableStateOf(false) }
|
||||||
val isOwnNote = note.author == accountViewModel.accountLiveData.value?.account?.userProfile()
|
val isOwnNote = accountViewModel.isLoggedUser(note.author)
|
||||||
val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author!!)
|
val isFollowingUser = !isOwnNote && accountViewModel.isFollowing(note.author!!)
|
||||||
|
|
||||||
val backgroundColor = if (MaterialTheme.colors.isLight) {
|
val backgroundColor = if (MaterialTheme.colors.isLight) {
|
||||||
|
@@ -125,11 +125,12 @@ class AccountViewModel(private val account: Account) : ViewModel() {
|
|||||||
account.unfollow(user)
|
account.unfollow(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isLoggedUser(user: User): Boolean {
|
fun isLoggedUser(user: User?): Boolean {
|
||||||
return account.userProfile() == user
|
return account.userProfile() == user
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isFollowing(user: User): Boolean {
|
fun isFollowing(user: User?): Boolean {
|
||||||
|
if (user == null) return false
|
||||||
return account.userProfile().isFollowingCached(user)
|
return account.userProfile().isFollowingCached(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user