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

View File

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