Skip to content

Commit

Permalink
Fix auto approve wrong checker
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jul 22, 2024
1 parent bd9c23d commit a5b4391
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/components/chats/ChatItem/ChatItemMenus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export default function ChatItemMenus({
getSocialProfileQuery.useQuery(ownerId, {
enabled: inView && isAdmin,
})
const isVerifiedUser =
socialProfile?.allowedCreateCommentRootPostIds.includes(chatId)

const { mutate: approveUser } = useApproveUser()
const setMessageToEdit = useMessageData((state) => state.setMessageToEdit)
const openExtensionModal = useExtensionData(
Expand Down Expand Up @@ -128,18 +131,16 @@ export default function ChatItemMenus({
if (isMessageOwner && !isOptimisticMessage) {
menus.unshift(hideMenu)

const approvedTime = message?.struct.approvedInRootPostAtTime
const createdTime = message?.struct.createdAtTime
const isApproved = message?.struct.approvedInRootPost

const isAutoApproved = isApproved && approvedTime === createdTime
const isAfter5MinsOfCreation =
dayjs(createdTime).diff(dayjs(), 'minute') < 5

if (
(message?.content?.body.trim().length ?? 0) > 0 &&
((!isAutoApproved && isAfter5MinsOfCreation && !isApproved) ||
(isAutoApproved && isAfter5MinsOfCreation))
((!isVerifiedUser && isAfter5MinsOfCreation && !isApproved) ||
(isVerifiedUser && isAfter5MinsOfCreation))
)
menus.unshift(editItem)
}
Expand Down Expand Up @@ -187,10 +188,7 @@ export default function ChatItemMenus({
})
},
})
if (
!loadingSocialProfile &&
!socialProfile?.allowedCreateCommentRootPostIds.includes(chatId)
) {
if (!loadingSocialProfile && !isVerifiedUser) {
menus.unshift({
text: 'Approve User',
icon: FaCheck,
Expand Down

0 comments on commit a5b4391

Please sign in to comment.