Don't mute your own posts (#3037)

* Don't mute your own posts.

* fix and add tests
zio/stable
Hailey 2024-02-28 18:41:23 -08:00 committed by GitHub
parent 2440975bd2
commit a35976cdc9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 98 additions and 0 deletions

View File

@ -16,6 +16,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: ['outlineTag'],
isOwnPost: false,
})
expect(match).toBe(true)
@ -32,6 +33,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: ['outlineTag'],
isOwnPost: false,
})
expect(match).toBe(true)
@ -48,6 +50,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: ['outlineTag'],
isOwnPost: false,
})
expect(match).toBe(true)
@ -64,6 +67,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(false)
@ -85,6 +89,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -101,6 +106,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(false)
@ -117,6 +123,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -135,6 +142,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -151,6 +159,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(false)
@ -167,6 +176,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -183,6 +193,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -202,6 +213,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -213,6 +225,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -231,6 +244,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -243,6 +257,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -261,6 +276,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -272,6 +288,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -291,6 +308,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -309,6 +327,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -320,6 +339,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -336,6 +356,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(false)
@ -354,6 +375,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -365,6 +387,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -383,6 +406,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -394,6 +418,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -405,6 +430,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -416,6 +442,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(false)
@ -434,6 +461,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -448,6 +476,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(false)
@ -460,6 +489,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -471,6 +501,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(false)
@ -489,6 +520,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -500,6 +532,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -511,6 +544,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -522,6 +556,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -540,6 +575,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -560,6 +596,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -571,6 +608,7 @@ describe(`hasMutedWord`, () => {
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
@ -594,10 +632,61 @@ describe(`hasMutedWord`, () => {
facets: rt.facets,
outlineTags: [],
languages: ['ja'],
isOwnPost: false,
})
expect(match).toBe(true)
})
})
})
describe(`doesn't mute own post`, () => {
it(`does mute if it isn't own post`, () => {
const rt = new RichText({
text: `Mute words!`,
})
const match = hasMutedWord({
mutedWords: [{value: 'words', targets: ['content']}],
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: false,
})
expect(match).toBe(true)
})
it(`doesn't mute own post when muted word is in text`, () => {
const rt = new RichText({
text: `Mute words!`,
})
const match = hasMutedWord({
mutedWords: [{value: 'words', targets: ['content']}],
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: true,
})
expect(match).toBe(false)
})
it(`doesn't mute own post when muted word is in tags`, () => {
const rt = new RichText({
text: `Mute #words!`,
})
const match = hasMutedWord({
mutedWords: [{value: 'words', targets: ['tags']}],
text: rt.text,
facets: rt.facets,
outlineTags: [],
isOwnPost: true,
})
expect(match).toBe(false)
})
})
})

View File

@ -41,13 +41,17 @@ export function hasMutedWord({
facets,
outlineTags,
languages,
isOwnPost,
}: {
mutedWords: AppBskyActorDefs.MutedWord[]
text: string
facets?: AppBskyRichtextFacet.Main[]
outlineTags?: string[]
languages?: string[]
isOwnPost: boolean
}) {
if (isOwnPost) return false
const exception = LANGUAGE_EXCEPTIONS.includes(languages?.[0] || '')
const tags = ([] as string[])
.concat(outlineTags || [])
@ -142,6 +146,7 @@ export function moderatePost_wrapped(
) {
const {hiddenPosts = [], mutedWords = [], ...options} = opts
const moderations = moderatePost(subject, options)
const isOwnPost = subject.author.did === opts.userDid
if (hiddenPosts.includes(subject.uri)) {
moderations.content.filter = true
@ -163,6 +168,7 @@ export function moderatePost_wrapped(
facets: subject.record.facets || [],
outlineTags: subject.record.tags || [],
languages: subject.record.langs,
isOwnPost,
})
if (
@ -178,6 +184,7 @@ export function moderatePost_wrapped(
facets: [],
outlineTags: [],
languages: subject.record.langs,
isOwnPost,
})
}
}
@ -210,6 +217,7 @@ export function moderatePost_wrapped(
facets: subject.embed.record.value.facets,
outlineTags: subject.embed.record.value.tags,
languages: subject.embed.record.value.langs,
isOwnPost,
})
if (AppBskyEmbedImages.isMain(subject.embed.record.value.embed)) {
@ -222,6 +230,7 @@ export function moderatePost_wrapped(
facets: [],
outlineTags: [],
languages: subject.embed.record.value.langs,
isOwnPost,
})
}
}