Skip to content

Commit

Permalink
add mute block report to mastodon misskey and bluesky
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Nov 17, 2023
1 parent 187bc27 commit 51e6dd9
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 8 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ dependencies {
ksp(libs.ktorfit.ksp)
implementation(libs.bundles.coil)
implementation(libs.bundles.ktor)
implementation(libs.twitter.parser)
implementation(libs.material.icons.extended)
implementation(libs.molecule.runtime)
implementation(libs.ktml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fun HtmlText2(
) {
with(element) {
RenderElement(context)
context.RenderTextAndReset()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package dev.dimension.flare.ui.screen.profile

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand Down Expand Up @@ -66,8 +68,8 @@ internal fun BlueskyProfileHeader(
text =
stringResource(
when {
data.following -> R.string.profile_header_button_following
data.blocking -> R.string.profile_header_button_blocked
data.following -> R.string.profile_header_button_following
else -> R.string.profile_header_button_follow
},
),
Expand Down Expand Up @@ -129,3 +131,32 @@ internal fun BlueskyProfileHeader(
modifier = modifier,
)
}

@Composable
internal fun ColumnScope.BlueskyUserMenu(
user: UiUser,
relation: UiRelation.Bluesky,
onBlockClick: () -> Unit,
onMuteClick: () -> Unit,
) {
DropdownMenuItem(
text = {
if (relation.muting) {
Text(text = stringResource(R.string.user_unmute, user.handle))
} else {
Text(text = stringResource(R.string.user_mute, user.handle))
}
},
onClick = onMuteClick,
)
DropdownMenuItem(
text = {
if (relation.blocking) {
Text(text = stringResource(R.string.user_unblock, user.handle))
} else {
Text(text = stringResource(R.string.user_block, user.handle))
}
},
onClick = onBlockClick,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.dimension.flare.ui.screen.profile

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -10,6 +11,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -84,6 +86,7 @@ internal fun MastodonProfileHeader(
text =
stringResource(
when {
data.blocking -> R.string.profile_header_button_blocked
data.following -> R.string.profile_header_button_following
data.requested -> R.string.profile_header_button_requested
else -> R.string.profile_header_button_follow
Expand Down Expand Up @@ -145,3 +148,32 @@ internal fun MastodonProfileHeader(
modifier = modifier,
)
}

@Composable
internal fun ColumnScope.MastodonUserMenu(
user: UiUser,
relation: UiRelation.Mastodon,
onBlockClick: () -> Unit,
onMuteClick: () -> Unit,
) {
DropdownMenuItem(
text = {
if (relation.muting) {
Text(text = stringResource(R.string.user_unmute, user.handle))
} else {
Text(text = stringResource(R.string.user_mute, user.handle))
}
},
onClick = onMuteClick,
)
DropdownMenuItem(
text = {
if (relation.blocking) {
Text(text = stringResource(R.string.user_unblock, user.handle))
} else {
Text(text = stringResource(R.string.user_block, user.handle))
}
},
onClick = onBlockClick,
)
}
32 changes: 32 additions & 0 deletions app/src/main/java/dev/dimension/flare/ui/screen/profile/Misskey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package dev.dimension.flare.ui.screen.profile

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand Down Expand Up @@ -77,6 +79,7 @@ internal fun MisskeyProfileHeader(
text =
stringResource(
when {
data.blocking -> R.string.profile_header_button_blocked
data.following -> R.string.profile_header_button_following
data.hasPendingFollowRequestFromYou -> R.string.profile_header_button_requested
else -> R.string.profile_header_button_follow
Expand Down Expand Up @@ -140,3 +143,32 @@ internal fun MisskeyProfileHeader(
modifier = modifier,
)
}

@Composable
internal fun ColumnScope.MisskeyUserMenu(
user: UiUser,
relation: UiRelation.Misskey,
onBlockClick: () -> Unit,
onMuteClick: () -> Unit,
) {
DropdownMenuItem(
text = {
if (relation.muted) {
Text(text = stringResource(R.string.user_unmute, user.handle))
} else {
Text(text = stringResource(R.string.user_mute, user.handle))
}
},
onClick = onMuteClick,
)
DropdownMenuItem(
text = {
if (relation.blocking) {
Text(text = stringResource(R.string.user_unblock, user.handle))
} else {
Text(text = stringResource(R.string.user_block, user.handle))
}
},
onClick = onBlockClick,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -42,7 +44,9 @@ import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -329,13 +333,76 @@ fun ProfileScreen(
}
},
actions = {
state.state.userState.onSuccess {
IconButton(onClick = { /*TODO*/ }) {
state.state.userState.onSuccess { user ->
IconButton(onClick = {
state.setShowMoreMenus(true)
}) {
Icon(
imageVector = Icons.Default.MoreVert,
contentDescription = null,
)
}
DropdownMenu(
expanded = state.showMoreMenus,
onDismissRequest = { state.setShowMoreMenus(false) },
) {
state.state.isMe.onSuccess { isMe ->
if (!isMe) {
state.state.relationState.onSuccess { relation ->
when (relation) {
is UiRelation.Bluesky ->
BlueskyUserMenu(
user = user,
relation = relation,
onBlockClick = {
state.setShowMoreMenus(false)
state.state.block(user, relation)
},
onMuteClick = {
state.setShowMoreMenus(false)
state.state.mute(user, relation)
},
)
is UiRelation.Mastodon ->
MastodonUserMenu(
user = user,
relation = relation,
onBlockClick = {
state.setShowMoreMenus(false)
state.state.block(user, relation)
},
onMuteClick = {
state.setShowMoreMenus(false)
state.state.mute(user, relation)
},
)
is UiRelation.Misskey ->
MisskeyUserMenu(
user = user,
relation = relation,
onBlockClick = {
state.setShowMoreMenus(false)
state.state.block(user, relation)
},
onMuteClick = {
state.setShowMoreMenus(false)
state.state.mute(user, relation)
},
)
}
}
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.user_report, user.handle))
},
onClick = {
state.setShowMoreMenus(false)
state.state.report(user)
},
)
}
}
}
}
},
)
Expand Down Expand Up @@ -644,8 +711,16 @@ private fun profilePresenter(
userKey = userKey,
)
}.invoke()
var showMoreMenus by remember {
mutableStateOf(false)
}
object {
val state = state
val statusEvent = statusEvent
val showMoreMenus = showMoreMenus

fun setShowMoreMenus(value: Boolean) {
showMoreMenus = value
}
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<string name="profile_header_button_follow">关注</string>
<string name="profile_header_button_following">正在关注</string>
<string name="profile_header_button_requested">已申请</string>
<string name="profile_header_button_blocked">已屏蔽</string>

<string name="compose_poll_expiration_at">截止日期:%1$s</string>
<string name="compose_poll_expiration_5_minutes">5 分钟后</string>
<string name="compose_poll_expiration_30_minutes">30 分钟后</string>
Expand Down Expand Up @@ -165,4 +167,10 @@

<string name="misskey_item_action_delete">删除</string>
<string name="misskey_item_action_report">举报</string>

<string name="user_report">举报 %1$s</string>
<string name="user_block">屏蔽 %1$s</string>
<string name="user_unblock">取消屏蔽 %1$s</string>
<string name="user_mute">静音 %1$s</string>
<string name="user_unmute">取消静音 %1$s</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,10 @@

<string name="misskey_item_action_delete">Delete</string>
<string name="misskey_item_action_report">Report</string>

<string name="user_report">Report %1$s</string>
<string name="user_block">Block %1$s</string>
<string name="user_unblock">Unblock %1$s</string>
<string name="user_mute">Mute %1$s</string>
<string name="user_unmute">Unmute %1$s</string>
</resources>
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ kotlin {
implementation(libs.ktml)
implementation(libs.mfm.multiplatform)
api(libs.bluesky)
implementation(libs.twitter.parser)
}
}
val androidMain by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class MastodonDataSource(
)
}
runCatching {
service.mute(userKey.id)
service.muteUser(userKey.id)
}.onFailure {
MemCacheable.updateWith<UiRelation.Mastodon>(
key = key,
Expand All @@ -614,7 +614,7 @@ class MastodonDataSource(
)
}
runCatching {
service.unmute(userKey.id)
service.unmuteUser(userKey.id)
}.onFailure {
MemCacheable.updateWith<UiRelation.Mastodon>(
key = key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ class MisskeyDataSource(
runCatching {
service.blockingCreate(AdminAccountsDeleteRequest(userId = userKey.id))
}.onFailure {
it.printStackTrace()
MemCacheable.updateWith<UiRelation.Misskey>(
key = key,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ interface FriendshipResources {
@Path(value = "id") id: String,
): RelationshipResponse

@POST("api/v1/accounts/{id}/mute")
suspend fun muteUser(
@Path(value = "id") id: String,
): RelationshipResponse

@POST("api/v1/accounts/{id}/unmute")
suspend fun unmuteUser(
@Path(value = "id") id: String,
): RelationshipResponse

@POST("api/v1/reports")
suspend fun report(
@Body data: PostReport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ data class UserDetailedNotMe(
@SerialName(value = "pinnedNoteIds") val pinnedNoteIds: kotlin.collections.List<kotlin.String>,
@SerialName(value = "pinnedNotes") val pinnedNotes: kotlin.collections.List<@Contextual Note>,
@SerialName(value = "pinnedPageId") val pinnedPageId: kotlin.String? = null,
@SerialName(value = "pinnedPage") val pinnedPage: Page,
@SerialName(value = "pinnedPage") val pinnedPage: Page? = null,
@SerialName(value = "publicReactions") val publicReactions: kotlin.Boolean,
@SerialName(value = "twoFactorEnabled") val twoFactorEnabled: kotlin.Boolean = false,
@SerialName(value = "usePasswordLessLogin") val usePasswordLessLogin: kotlin.Boolean = false,
Expand Down
Loading

0 comments on commit 51e6dd9

Please sign in to comment.