Skip to content

Commit

Permalink
fix(api): hasMutedWord for facets with multiple features (#2570)
Browse files Browse the repository at this point in the history
* Fix hasMutedWord for facets with multiple features

* Add changeset
  • Loading branch information
sugyan authored Jul 19, 2024
1 parent 7e88f6f commit 12dcdb6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-teachers-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@atproto/api": patch
---

Fix `hasMutedWord` for facets with multiple features
10 changes: 3 additions & 7 deletions packages/api/src/moderation/mutewords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ export function hasMutedWord({
const tags = ([] as string[])
.concat(outlineTags || [])
.concat(
facets
?.filter((facet) => {
return facet.features.find((feature) =>
AppBskyRichtextFacet.isTag(feature),
)
})
.map((t) => t.features[0].tag as string) || [],
(facets || []).flatMap((facet) =>
facet.features.filter(AppBskyRichtextFacet.isTag).map((tag) => tag.tag),
),
)
.map((t) => t.toLowerCase())

Expand Down
54 changes: 54 additions & 0 deletions packages/api/tests/moderation-mutewords.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,60 @@ describe(`hasMutedWord`, () => {
})
})

describe(`facet with multiple features`, () => {
it(`multiple tags`, () => {
const match = hasMutedWord({
mutedWords: [{ value: 'bad', targets: ['content'] }],
text: 'tags',
facets: [
{
features: [
{
$type: 'app.bsky.richtext.facet#tag',
tag: 'good',
},
{
$type: 'app.bsky.richtext.facet#tag',
tag: 'bad',
},
],
index: {
byteEnd: 4,
byteStart: 0,
},
},
],
})
expect(match).toBe(true)
})

it(`other features`, () => {
const match = hasMutedWord({
mutedWords: [{ value: 'bad', targets: ['content'] }],
text: 'test',
facets: [
{
features: [
{
$type: 'com.example.richtext.facet#other',
foo: 'bar',
},
{
$type: 'app.bsky.richtext.facet#tag',
tag: 'bad',
},
],
index: {
byteEnd: 4,
byteStart: 0,
},
},
],
})
expect(match).toBe(true)
})
})

describe(`doesn't mute own post`, () => {
it(`does mute if it isn't own post`, () => {
const res = moderatePost(
Expand Down

0 comments on commit 12dcdb6

Please sign in to comment.