Skip to content

Commit

Permalink
adding block domain to other user's profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
John Oberhauser committed May 20, 2024
1 parent fe91d3b commit 080f46c
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/ui/common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

<string name="block_domain_confirmation">Are you sure you want to block the entire domain %s?</string>
<string name="block_domain_confirmed">Block</string>
<string name="block_domain">Block domain %s</string>
<string name="unblock_domain">Unblock domain %s</string>

<string name="mute_user_confirmation">Are you sure you want to mute %s?</string>
<string name="mute_user_confirmed">Mute</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fun Account.toUiState(relationship: Relationship) =
AccountUiState(
accountId = accountId,
username = username,
domain = acct.substringAfter(
delimiter = "@",
missingDelimiterValue = ""
),
webFinger = acct,
displayName = displayName,
accountUrl = url,
Expand All @@ -29,6 +33,7 @@ fun Account.toUiState(relationship: Relationship) =
},
isMuted = relationship.isMuting,
isBlocked = relationship.isBlocking,
isDomainBlocked = relationship.isDomainBlocking,
joinDate = createdAt.toLocalDateTime(TimeZone.currentSystemDefault()),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ val accountModule =
muteAccount = get(),
unmuteAccount = get(),
timelineRepository = get(),
blockDomain = get(),
unblockDomain = get(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import social.firefly.core.ui.common.button.FfButtonSecondary
import social.firefly.core.ui.common.button.FfToggleButton
import social.firefly.core.ui.common.button.ToggleButtonState
import social.firefly.core.ui.common.dialog.blockAccountConfirmationDialog
import social.firefly.core.ui.common.dialog.blockDomainConfirmationDialog
import social.firefly.core.ui.common.dialog.muteAccountConfirmationDialog
import social.firefly.core.ui.common.dropdown.FfDropDownItem
import social.firefly.core.ui.common.dropdown.FfIconButtonDropDownMenu
Expand Down Expand Up @@ -397,6 +398,10 @@ private fun OverflowMenu(
overflowInteractions.onOverflowMuteClicked()
}

val blockDomainDialog = blockDomainConfirmationDialog(domain = account.domain) {
overflowInteractions.onOverflowBlockDomainClicked()
}

FfIconButtonDropDownMenu(
expanded = overflowMenuExpanded,
dropDownMenuContent = {
Expand Down Expand Up @@ -487,6 +492,28 @@ private fun OverflowMenu(
expanded = overflowMenuExpanded,
onClick = { overflowInteractions.onOverflowReportClicked() },
)

if (account.domain.isNotBlank()) {
if (account.isDomainBlocked) {
FfDropDownItem(
text = stringResource(
id = social.firefly.core.ui.common.R.string.unblock_domain,
account.domain,
),
expanded = overflowMenuExpanded,
onClick = { overflowInteractions.onOverflowUnblockDomainClicked() },
)
} else {
FfDropDownItem(
text = stringResource(
id = social.firefly.core.ui.common.R.string.block_domain,
account.domain,
),
expanded = overflowMenuExpanded,
onClick = { blockDomainDialog.open() },
)
}
}
}
}
) {
Expand Down Expand Up @@ -713,6 +740,7 @@ fun AccountScreenPreview() {
accountId = "",
username = "Coolguy",
webFinger = "coolguy",
domain = "",
displayName = "Cool Guy",
accountUrl = "",
bio = "I'm pretty cool",
Expand All @@ -726,8 +754,8 @@ fun AccountScreenPreview() {
followStatus = FollowStatus.NOT_FOLLOWING,
isMuted = false,
isBlocked = false,
joinDate =
LocalDateTime(
isDomainBlocked = false,
joinDate = LocalDateTime(
LocalDate(2023, 7, 3),
LocalTime(0, 0, 0),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class AccountUiState(
val accountId: String,
val username: String,
val webFinger: String,
val domain: String, // if the domain is the user's domain, value will be blank
val displayName: String,
val accountUrl: String,
val bio: String,
Expand All @@ -24,6 +25,7 @@ data class AccountUiState(
val followStatus: FollowStatus,
val isMuted: Boolean,
val isBlocked: Boolean,
val isDomainBlocked: Boolean,
val joinDate: LocalDateTime,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import social.firefly.core.repository.paging.remotemediators.AccountTimelineRemo
import social.firefly.core.ui.postcard.PostCardDelegate
import social.firefly.core.ui.postcard.toPostCardUiState
import social.firefly.core.usecase.mastodon.account.BlockAccount
import social.firefly.core.usecase.mastodon.account.BlockDomain
import social.firefly.core.usecase.mastodon.account.FollowAccount
import social.firefly.core.usecase.mastodon.account.GetDetailedAccount
import social.firefly.core.usecase.mastodon.account.GetLoggedInUserAccountId
import social.firefly.core.usecase.mastodon.account.MuteAccount
import social.firefly.core.usecase.mastodon.account.UnblockAccount
import social.firefly.core.usecase.mastodon.account.UnblockDomain
import social.firefly.core.usecase.mastodon.account.UnfollowAccount
import social.firefly.core.usecase.mastodon.account.UnmuteAccount
import timber.log.Timber
Expand All @@ -46,6 +48,8 @@ class AccountViewModel(
private val unblockAccount: UnblockAccount,
private val muteAccount: MuteAccount,
private val unmuteAccount: UnmuteAccount,
private val blockDomain: BlockDomain,
private val unblockDomain: UnblockDomain,
initialAccountId: String?,
) : ViewModel(), AccountInteractions, KoinComponent {

Expand Down Expand Up @@ -220,6 +224,30 @@ class AccountViewModel(
}
}

override fun onOverflowBlockDomainClicked() {
viewModelScope.launch {
(uiState.value as? Resource.Loaded)?.data?.domain?.let { domain ->
try {
blockDomain(domain)
} catch (e: BlockDomain.BlockDomainFailedException) {
Timber.e(e)
}
}
}
}

override fun onOverflowUnblockDomainClicked() {
viewModelScope.launch {
(uiState.value as? Resource.Loaded)?.data?.domain?.let { domain ->
try {
unblockDomain(domain)
} catch (e: UnblockDomain.UnblockDomainFailedException) {
Timber.e(e)
}
}
}
}

override fun onOverflowReportClicked() {
analytics.overflowReportClicked()
(uiState.value as? Resource.Loaded)?.data?.webFinger?.let { webFinger ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface OverflowInteractions {
fun onOverflowReportClicked() = Unit
fun onOverflowFollowedHashTagsClicked() = Unit
fun onOverflowBookmarksClicked() = Unit
fun onOverflowBlockDomainClicked() = Unit
fun onOverflowUnblockDomainClicked() = Unit
}

0 comments on commit 080f46c

Please sign in to comment.