feat: filter out comments that are too short in length in the activities

This commit is contained in:
DIYgod
2023-05-23 15:23:54 +01:00
parent f776e082a0
commit 1571bd7dce
2 changed files with 20 additions and 1 deletions
+7 -1
View File
@@ -19,7 +19,7 @@ import { useDate } from "~/hooks/useDate"
import { useTranslation } from "~/lib/i18n/client"
import { getStorage, setStorage } from "~/lib/storage"
import { ExpandedNote } from "~/lib/types"
import { cn } from "~/lib/utils"
import { cn, getStringLength } from "~/lib/utils"
import type { FeedType, SearchType } from "~/models/home.model"
import { useGetFeed } from "~/queries/home"
@@ -146,6 +146,12 @@ const Post = ({
if (post.toNote?.metadata?.content?.tags?.includes("comment")) {
return null
}
if (
!post.metadata?.content?.summary ||
getStringLength(post.metadata.content.summary) < 6
) {
return null
}
}
return (
+13
View File
@@ -48,3 +48,16 @@ export const calculateElementTop = (el: HTMLElement) => {
}
return top
}
export function getStringLength(str: string) {
let len = 0
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i)
if (code >= 0 && code <= 128) {
len += 1
} else {
len += 2
}
}
return len
}