3891: Only mute the actual hashtag (with #)

This commit is contained in:
Lakoja 2023-07-27 17:16:01 +02:00
parent b0a50f9f50
commit a883ec71d5
2 changed files with 10 additions and 9 deletions

View File

@ -174,6 +174,7 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
*/
private fun updateMuteTagMenuItems() {
val tag = hashtag ?: return
val hashedTag = if (tag.startsWith('#')) tag else "#" + tag
muteTagItem?.isVisible = true
muteTagItem?.isEnabled = false
@ -184,7 +185,7 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
{ filters ->
mutedFilter = filters.firstOrNull { filter ->
filter.context.contains(Filter.Kind.HOME.kind) && filter.keywords.any {
it.keyword == tag
it.keyword == hashedTag
}
}
updateTagMuteState(mutedFilter != null)
@ -194,7 +195,7 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
mastodonApi.getFiltersV1().fold(
{ filters ->
mutedFilterV1 = filters.firstOrNull { filter ->
tag == filter.phrase && filter.context.contains(FilterV1.HOME)
hashedTag == filter.phrase && filter.context.contains(FilterV1.HOME)
}
updateTagMuteState(mutedFilterV1 != null)
},
@ -224,10 +225,10 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
private fun muteTag(): Boolean {
val tag = hashtag ?: return true
val hashedTag = if (tag.startsWith('#')) tag else "#" + tag
lifecycleScope.launch {
var filterCreateSuccess = false
val hashedTag = if (tag.startsWith('#')) tag else "#" + tag
mastodonApi.createFilter(
title = "#$tag",
@ -236,7 +237,7 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
expiresInSeconds = null
).fold(
{ filter ->
if (mastodonApi.addFilterKeyword(filterId = filter.id, keyword = tag, wholeWord = true).isSuccess) {
if (mastodonApi.addFilterKeyword(filterId = filter.id, keyword = hashedTag, wholeWord = true).isSuccess) {
mutedFilter = filter
// TODO the preference key here ("home") is not meaningful; should probably be another event if any
eventHub.dispatch(PreferenceChangedEvent(filter.context[0]))
@ -249,7 +250,7 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
{ throwable ->
if (throwable is HttpException && throwable.code() == 404) {
mastodonApi.createFilterV1(
tag,
hashedTag,
listOf(FilterV1.HOME),
irreversible = false,
wholeWord = true,

View File

@ -614,11 +614,11 @@
<string name="notifications_apply_filter">Filter</string>
<string name="filter_apply">Apply</string>
<string name="muting_hashtag_success_format">Muting %s as a warning</string>
<string name="unmuting_hashtag_success_format">Unmuting %s</string>
<string name="muting_hashtag_success_format">Muting hashtag #%s as a warning</string>
<string name="unmuting_hashtag_success_format">Unmuting hashtag #%s</string>
<string name="action_view_filters">View filters</string>
<string name="following_hashtag_success_format">Now following hashtag %s</string>
<string name="unfollowing_hashtag_success_format">No longer following hashtag %s</string>
<string name="following_hashtag_success_format">Now following hashtag #%s</string>
<string name="unfollowing_hashtag_success_format">No longer following hashtag #%s</string>
<string name="compose_shortcut_long_label">Compose post</string>
<string name="compose_shortcut_short_label">Compose</string>