Skip to content

Commit

Permalink
Merge pull request #55 from BigWhaleLabs/check-if-post-was-hidden
Browse files Browse the repository at this point in the history
don't send notification event for banned comment
  • Loading branch information
MixailE authored Dec 5, 2023
2 parents 65d60a1 + b0b7c61 commit c6cc28a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
30 changes: 22 additions & 8 deletions src/helpers/isBannedPost.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import axios from 'axios'
import env from '@/helpers/env'

function isContentNotHidden(e: unknown) {
return axios.isAxiosError(e) && e.response?.status === 404
}

export async function isBannedPost(feedId: number, postId: number) {
const { data } = await axios.get<boolean>(
`${env.KETL_MODERATION_BACKEND}/hidden/${feedId}/${postId}/post`
)
try {
const { data } = await axios.get<boolean>(
`${env.KETL_MODERATION_BACKEND}/hidden/${feedId}/${postId}/post`
)

return data
return data
} catch (e) {
if (isContentNotHidden(e)) return false
console.error(e)
}
}

export async function isBannedComment(
feedId: number,
postId: number,
commendId: number
) {
const { data } = await axios.get<boolean>(
`${env.KETL_MODERATION_BACKEND}/hidden/${feedId}/${postId}/${commendId}`
)
try {
const { data } = await axios.get<boolean>(
`${env.KETL_MODERATION_BACKEND}/hidden/${feedId}/${postId}/${commendId}`
)

return data
return data
} catch (e) {
if (isContentNotHidden(e)) return false
console.error(e)
}
}

export default function isBanned(
Expand Down
14 changes: 12 additions & 2 deletions src/helpers/runNotificationListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ ketlAttestationContract.on(

getFeedsContract.on(
'CommentAdded',
async (feedId: BigNumber, postId: BigNumber, commentId: BigNumber) => {
async (
feedId: BigNumber,
postId: BigNumber,
commentId: BigNumber,
comment: PostStructOutput
) => {
try {
const numberFeedId = feedId.toNumber()
const numberPostId = postId.toNumber()
const numberCommentId = commentId.toNumber()
if (await isBanned(numberFeedId, numberPostId)) return
const replyTo = comment.replyTo.toNumber()
if (
(await isBanned(numberFeedId, numberPostId)) ||
(await isBanned(numberFeedId, numberPostId, replyTo))
)
return
const tokens = await getTokens({ repliesEnabled: true })
await sendFirebaseNotification({ tokens })

Expand Down

0 comments on commit c6cc28a

Please sign in to comment.