filter messages by also looking at media descriptions (#2285)
This commit is contained in:
parent
a221a7b916
commit
c0c8eec36b
|
@ -29,9 +29,16 @@ class FilterModel @Inject constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
val spoilerText = status.actionableStatus.spoilerText
|
val spoilerText = status.actionableStatus.spoilerText
|
||||||
|
val attachmentsDescriptions = status.attachments
|
||||||
|
.mapNotNull { it.description }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
matcher.reset(status.actionableStatus.content).find() ||
|
matcher.reset(status.actionableStatus.content).find() ||
|
||||||
spoilerText.isNotEmpty() && matcher.reset(spoilerText).find()
|
(spoilerText.isNotEmpty() && matcher.reset(spoilerText).find()) ||
|
||||||
|
(
|
||||||
|
attachmentsDescriptions.isNotEmpty() &&
|
||||||
|
matcher.reset(attachmentsDescriptions.joinToString("\n")).find()
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.keylesspalace.tusky
|
||||||
|
|
||||||
import android.text.SpannedString
|
import android.text.SpannedString
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.keylesspalace.tusky.entity.Attachment
|
||||||
import com.keylesspalace.tusky.entity.Filter
|
import com.keylesspalace.tusky.entity.Filter
|
||||||
import com.keylesspalace.tusky.entity.Poll
|
import com.keylesspalace.tusky.entity.Poll
|
||||||
import com.keylesspalace.tusky.entity.PollOption
|
import com.keylesspalace.tusky.entity.PollOption
|
||||||
|
@ -14,6 +15,7 @@ import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
|
import java.util.ArrayList
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@Config(sdk = [28])
|
@Config(sdk = [28])
|
||||||
|
@ -125,6 +127,19 @@ class FilterTest {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldFilter_whenMediaDescriptionDoesMatch() {
|
||||||
|
assertTrue(
|
||||||
|
filterModel.shouldFilterStatus(
|
||||||
|
mockStatus(
|
||||||
|
content = "should not be filtered",
|
||||||
|
spoilerText = "should not be filtered",
|
||||||
|
attachmentsDescriptions = listOf("should not be filtered", "badWord"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldFilterPartialWord_whenWholeWordFilterContainsNonAlphanumericCharacters() {
|
fun shouldFilterPartialWord_whenWholeWordFilterContainsNonAlphanumericCharacters() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
|
@ -137,7 +152,8 @@ class FilterTest {
|
||||||
private fun mockStatus(
|
private fun mockStatus(
|
||||||
content: String = "",
|
content: String = "",
|
||||||
spoilerText: String = "",
|
spoilerText: String = "",
|
||||||
pollOptions: List<String>? = null
|
pollOptions: List<String>? = null,
|
||||||
|
attachmentsDescriptions: List<String>? = null
|
||||||
): Status {
|
): Status {
|
||||||
return Status(
|
return Status(
|
||||||
id = "123",
|
id = "123",
|
||||||
|
@ -157,7 +173,21 @@ class FilterTest {
|
||||||
sensitive = false,
|
sensitive = false,
|
||||||
spoilerText = spoilerText,
|
spoilerText = spoilerText,
|
||||||
visibility = Status.Visibility.PUBLIC,
|
visibility = Status.Visibility.PUBLIC,
|
||||||
attachments = arrayListOf(),
|
attachments = if (attachmentsDescriptions != null) {
|
||||||
|
ArrayList(
|
||||||
|
attachmentsDescriptions.map {
|
||||||
|
Attachment(
|
||||||
|
id = "1234",
|
||||||
|
url = "",
|
||||||
|
previewUrl = null,
|
||||||
|
meta = null,
|
||||||
|
type = Attachment.Type.IMAGE,
|
||||||
|
description = it,
|
||||||
|
blurhash = null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else arrayListOf(),
|
||||||
mentions = listOf(),
|
mentions = listOf(),
|
||||||
application = null,
|
application = null,
|
||||||
pinned = false,
|
pinned = false,
|
||||||
|
|
Loading…
Reference in New Issue