Refactoring calls to check if a user is the signed in user.

This commit is contained in:
Vitor Pamplona
2023-03-15 13:12:21 -04:00
parent 2bf36f1cfe
commit a9490e1299
3 changed files with 8 additions and 9 deletions

View File

@@ -820,7 +820,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit,
expanded = popupExpanded,
onDismissRequest = onDismiss
) {
if (!accountViewModel.isFollowing(note.author!!)) {
if (!accountViewModel.isFollowing(note.author)) {
DropdownMenuItem(onClick = {
accountViewModel.follow(
note.author ?: return@DropdownMenuItem
@@ -860,14 +860,12 @@ fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit,
DropdownMenuItem(onClick = { accountViewModel.broadcast(note); onDismiss() }) {
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() }) {
Text(stringResource(R.string.request_deletion))
}
}
if (note.author != accountViewModel.accountLiveData.value?.account?.userProfile()) {
Divider()
} else {
DropdownMenuItem(onClick = { reportDialogShowing = true }) {
Text("Block / Report")
}

View File

@@ -98,7 +98,7 @@ fun NoteQuickActionMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Uni
var showDeleteAlertDialog by remember { mutableStateOf(false) }
var showBlockAlertDialog 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 backgroundColor = if (MaterialTheme.colors.isLight) {

View File

@@ -125,11 +125,12 @@ class AccountViewModel(private val account: Account) : ViewModel() {
account.unfollow(user)
}
fun isLoggedUser(user: User): Boolean {
fun isLoggedUser(user: User?): Boolean {
return account.userProfile() == user
}
fun isFollowing(user: User): Boolean {
fun isFollowing(user: User?): Boolean {
if (user == null) return false
return account.userProfile().isFollowingCached(user)
}