Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Conversation

@Tak
Copy link
Collaborator

@Tak Tak commented Apr 5, 2025

Add support for the blur filter action added in mastodon 4.4.0.
Images and videos on matched posts are hidden by default, and the label reads "Filtered: ${title of applied filter}".
If a matched post has a preview card, the preview image is also blurred.

This is draft for now until I upgrade my instance and test, I've tested so far with spoofed data.

Screenshot of two posts in the timeline with blurred media. The label reads: Filtered: BLUR

val filter = status.getApplicableFilter(viewModel.kind.toFilterKind())
val expanded = oldStatus?.expanded ?: activeAccount.alwaysOpenSpoiler
val contentShowing = oldStatus?.contentShowing ?: (activeAccount.alwaysShowSensitiveMedia || !status.actionableStatus.sensitive)
val contentShowing = oldStatus?.contentShowing ?: (activeAccount.alwaysShowSensitiveMedia || (!status.actionableStatus.sensitive && filter?.action != Filter.Action.BLUR))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is repeated in a bunch of places, but I didn't find a nice way to extract it 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a new method shouldShowContent(alwaysShowSensitiveMedia, filterKind: Filter.Kind) on Status,
then it is "just"

val contentShowing = oldStatus?.contentShowing ?: status.shouldShowContent(activeAccount.alwaysShowSensitiveMedia, viewModel.kind.toFilterKind())

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had exactly that in one iteration and couldn't decide if it was better or not - if you think it's an improvement, then I'll readd it

@Tak Tak marked this pull request as ready for review April 9, 2025 09:35
@Tak
Copy link
Collaborator Author

Tak commented Apr 9, 2025

Tested with glitch.taks.garden

@Tak Tak requested review from charlag and connyduck April 9, 2025 09:36
Copy link
Collaborator

@connyduck connyduck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I'm wondering if we could detect this feature somehow? Or at least have a nice error message when a user tries to set a blur filter on an instance that does not support it?

) : Parcelable {
enum class Action(val action: String) {
NONE("none"),
BLUR("blur"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val context: List<String>,

@Json(name = "filter_action") val filterAction: String,

We could parse these directly as enums? Seems like that would simplify a few things


if (status.poll?.options?.any { matcher.reset(it.title).find() } == true) {
return Filter.Action.HIDE
return Filter("", "", listOf(kind.kind), filterAction = Filter.Action.HIDE.action)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like id & title could need "" default params

if (oldStatus != null) break
}

val filter = viewModel.kind?.let { status.getApplicableFilter(it.toFilterKind()) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val filter = viewModel.kind?.let { status.getApplicableFilter(it.toFilterKind()) }
val filter = status.getApplicableFilter(viewModel.kind.toFilterKind())

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one failed a bunch of tests because kind was null on the test viewModel (maybe I should fix the tests 🤷)

val filter = status.getApplicableFilter(viewModel.kind.toFilterKind())
val expanded = oldStatus?.expanded ?: activeAccount.alwaysOpenSpoiler
val contentShowing = oldStatus?.contentShowing ?: (activeAccount.alwaysShowSensitiveMedia || !status.actionableStatus.sensitive)
val contentShowing = oldStatus?.contentShowing ?: (activeAccount.alwaysShowSensitiveMedia || (!status.actionableStatus.sensitive && filter?.action != Filter.Action.BLUR))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a new method shouldShowContent(alwaysShowSensitiveMedia, filterKind: Filter.Kind) on Status,
then it is "just"

val contentShowing = oldStatus?.contentShowing ?: status.shouldShowContent(activeAccount.alwaysShowSensitiveMedia, viewModel.kind.toFilterKind())

@Tak
Copy link
Collaborator Author

Tak commented Apr 10, 2025

It doesn't look like the capability is advertised anywhere? It also doesn't look like we get a useful error when we send an unknown value.

@Tak Tak force-pushed the blur-filter-type branch from f3bb03f to 49140d6 Compare April 10, 2025 08:42
@connyduck
Copy link
Collaborator

connyduck commented Apr 10, 2025

/api/v2/instance has a new api_versions attribute that can be used to detect the supported features 🧐
mastodon/documentation#1631
api_versions.mastodon >= 5 means blur filter is supported

@Tak
Copy link
Collaborator Author

Tak commented Apr 11, 2025

Is other software (e.g. gts) going to support api_versions?

@tsmethurst
Copy link
Contributor

tsmethurst commented Apr 11, 2025

Is other software (e.g. gts) going to support api_versions?

GtS not yet, maybe in future.

https://github.com/superseriousbusiness/gotosocial/issues/3466

@connyduck
Copy link
Collaborator

@Tak Do you want to add feature detection? I'd prefer it but I'm also fine if we leave it out.

@Tak
Copy link
Collaborator Author

Tak commented Apr 22, 2025

I can add it, was just on vacation last week and didn't get to it

@connyduck connyduck merged commit dc79348 into develop Apr 29, 2025
1 check passed
@connyduck connyduck deleted the blur-filter-type branch April 29, 2025 17:35
connyduck added a commit that referenced this pull request May 10, 2025
Since #5038 the option to filter
boosts was ignored and boosts never filtered.

The issue here was that the `HomeTimelineData.status` holds no reblog
information, so `timelineData.status?.toStatus(it)` will always return a
unreblogged status. `timelineData.toViewData` constructs the correct
structure as it considers `HomeTimelineData.reblogAccount` as well.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants