Skip to content

Commit

Permalink
Merge branch 'approval' into deploy/epic
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jul 11, 2024
2 parents 46982b5 + 9eedfe0 commit 93a7cbf
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 37 deletions.
15 changes: 13 additions & 2 deletions src/components/chats/UnapprovedMemeCount.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { getUnapprovedMemesCountQuery } from '@/services/datahub/posts/query'
import { cx } from '@/utils/class-names'

export default function UnapprovedMemeCount({
address,
chatId,
className,
}: {
address: string
chatId: string
className?: string
}) {
const { data: count, isLoading } = getUnapprovedMemesCountQuery.useQuery({
address,
chatId,
})
if (isLoading) return null

const approved = count?.approved ?? 0
const unapproved = count?.unapproved ?? 0

return (
<div className='rounded-full bg-background-lightest px-1.5 py-0 text-xs'>
{(count ?? 0) >= 3 ? '✅' : '🚫'} {count ?? 0}
<div
className={cx(
'rounded-full bg-background-lightest px-1.5 py-0 text-sm',
className
)}
>
{`⏳ ${unapproved} / ✅ ${approved}`}
</div>
)
}
74 changes: 60 additions & 14 deletions src/components/extensions/common/CommonChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import useAuthorizedForModeration from '@/hooks/useAuthorizedForModeration'
import useIsMessageBlocked from '@/hooks/useIsMessageBlocked'
import { getSuperLikeCountQuery } from '@/services/datahub/content-staking/query'
import { getModerationReasonsQuery } from '@/services/datahub/moderation/query'
import { useApproveUser } from '@/services/datahub/posts/mutation'
import {
useApproveMessage,
useApproveUser,
} from '@/services/datahub/posts/mutation'
import { isMessageSent } from '@/services/subsocial/commentIds/optimistic'
import { useMyMainAddress } from '@/stores/my-account'
import { cx } from '@/utils/class-names'
Expand Down Expand Up @@ -74,7 +77,9 @@ export default function CommonChatItem({
showApproveButton,
dummySuperLike,
}: CommonChatItemProps) {
const { inView, ref } = useInView()
const { inView, ref } = useInView({
triggerOnce: true,
})
const myAddress = useMyMainAddress()
const { isAuthorized } = useAuthorizedForModeration(chatId)
const { mutate: moderate, isLoading: loadingModeration } =
Expand Down Expand Up @@ -190,6 +195,15 @@ export default function CommonChatItem({
)}
</div>
)}

{showApproveButton && inView && (
<UnapprovedMemeCount
className='absolute bottom-14 right-1.5 z-10 bg-black/50 text-white'
address={ownerId}
chatId={chatId}
/>
)}

<div
className={cx(
'relative flex flex-col gap-0.5 overflow-hidden rounded-2xl',
Expand Down Expand Up @@ -223,9 +237,6 @@ export default function CommonChatItem({
enableProfileModal={enableProfileModal}
className={cx('text-sm font-medium text-text-secondary')}
/>
{showApproveButton && inView && (
<UnapprovedMemeCount address={ownerId} chatId={chatId} />
)}
{/* <SubTeamLabel address={ownerId} /> */}
{othersMessage.checkMark === 'top' &&
otherMessageCheckMarkElement()}
Expand Down Expand Up @@ -293,7 +304,7 @@ export default function CommonChatItem({
<div
className={cx(
'grid items-center gap-2 px-2 pb-1 pt-2',
showApproveButton ? 'grid-cols-2' : 'grid-cols-1'
showApproveButton ? 'grid-flow-col gap-1' : 'grid-cols-1'
)}
>
<Button
Expand All @@ -315,15 +326,21 @@ export default function CommonChatItem({
})
}}
size='sm'
className={cx('w-full !text-text-red', {
['!bg-[#EF4444] disabled:border-none disabled:!text-white disabled:!ring-0 disabled:!brightness-100']:
isMessageBlocked,
})}
className={cx(
'w-full whitespace-nowrap px-0 text-xs !text-text-red',
{
['!bg-[#EF4444] disabled:border-none disabled:!text-white disabled:!ring-0 disabled:!brightness-100']:
isMessageBlocked,
}
)}
>
{isMessageBlocked ? 'Blocked' : 'Block message'}
{isMessageBlocked ? 'Blocked' : 'Block meme'}
</Button>
{showApproveButton && (
<ApproveButton ownerId={ownerId} chatId={chatId} />
<>
<ApproveUserButton ownerId={ownerId} chatId={chatId} />
<ApproveMemeButton messageId={message.id} chatId={chatId} />
</>
)}
</div>
)}
Expand Down Expand Up @@ -363,7 +380,7 @@ export default function CommonChatItem({
)
}

function ApproveButton({
function ApproveUserButton({
ownerId,
chatId,
}: {
Expand All @@ -374,7 +391,8 @@ function ApproveButton({
return (
<Button
variant='greenOutline'
className='disabled:!border-text-muted disabled:!text-text-muted disabled:!ring-text-muted'
size='sm'
className='whitespace-nowrap px-0 text-xs disabled:!border-text-muted disabled:!text-text-muted disabled:!ring-text-muted'
loadingText='Approving...'
isLoading={isLoading}
onClick={(e) => {
Expand All @@ -391,3 +409,31 @@ function ApproveButton({
</Button>
)
}

function ApproveMemeButton({
messageId,
chatId,
}: {
chatId: string
messageId: string
}) {
const { mutate, isLoading } = useApproveMessage()
return (
<Button
variant='greenOutline'
size='sm'
className='whitespace-nowrap px-0 text-xs disabled:!border-text-muted disabled:!text-text-muted disabled:!ring-text-muted'
loadingText='Approving...'
isLoading={isLoading}
onClick={(e) => {
e.stopPropagation()
mutate({
approvedInRootPost: true,
postId: messageId,
})
}}
>
Approve meme
</Button>
)
}
10 changes: 9 additions & 1 deletion src/pages/api/datahub/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { ApiResponse, handlerWrapper } from '@/server/common'
import {
CanUserDoAction,
CreatePostOptimisticInput,
SocialProfileAddReferrerIdInput,
UpdatePostOptimisticInput,
} from '@/server/datahub-queue/generated'
import {
approveMessage,
approveUser,
createPostData,
getCanAccountDo,
Expand Down Expand Up @@ -62,7 +64,11 @@ export type ApiDatahubPostMutationBody =
}
| {
action: 'approve-user'
payload: UpdatePostOptimisticInput
payload: SocialProfileAddReferrerIdInput
}
| {
action: 'approve-message'
payload: SocialProfileAddReferrerIdInput
}

export type ApiDatahubPostResponse = ApiResponse<{ callId?: string }>
Expand Down Expand Up @@ -108,6 +114,8 @@ function datahubPostActionMapping(data: ApiDatahubPostMutationBody) {
return updatePostData(data.payload)
case 'approve-user':
return approveUser(data.payload)
case 'approve-message':
return approveMessage(data.payload)
default:
throw new Error('Unknown action')
}
Expand Down
31 changes: 27 additions & 4 deletions src/server/datahub-queue/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export type Mutation = {
moderationExecuteForceCall: IngestDataResponseDto;
moderationInitModerator: IngestDataResponseDto;
moderationUnblockResource: IngestDataResponseDto;
setPostApproveStatus: IngestDataResponseDto;
socialProfileAddReferrerId: IngestDataResponseDto;
socialProfileSetActionPermissions: IngestDataResponseDto;
updatePostBlockchainSyncStatus: IngestDataResponseDto;
Expand Down Expand Up @@ -311,6 +312,11 @@ export type MutationModerationUnblockResourceArgs = {
};


export type MutationSetPostApproveStatusArgs = {
args: CreateMutatePostOffChainDataInput;
};


export type MutationSocialProfileAddReferrerIdArgs = {
args: SocialProfileAddReferrerIdInput;
};
Expand Down Expand Up @@ -442,6 +448,7 @@ export enum SocialCallName {
SynthModerationForceUnblockResource = 'synth_moderation_force_unblock_resource',
SynthModerationInitModerator = 'synth_moderation_init_moderator',
SynthModerationUnblockResource = 'synth_moderation_unblock_resource',
SynthSetPostApproveStatus = 'synth_set_post_approve_status',
SynthSocialProfileAddReferrerId = 'synth_social_profile_add_referrer_id',
SynthSocialProfileSetActionPermissions = 'synth_social_profile_set_action_permissions',
SynthUpdatePostTxFailed = 'synth_update_post_tx_failed',
Expand Down Expand Up @@ -579,11 +586,18 @@ export type UpdatePostOptimisticMutationVariables = Exact<{
export type UpdatePostOptimisticMutation = { __typename?: 'Mutation', updatePostOptimistic: { __typename?: 'IngestDataResponseDto', processed: boolean, callId?: string | null, message?: string | null } };

export type ApproveUserMutationVariables = Exact<{
input: UpdatePostOptimisticInput;
input: SocialProfileAddReferrerIdInput;
}>;


export type ApproveUserMutation = { __typename?: 'Mutation', socialProfileSetActionPermissions: { __typename?: 'IngestDataResponseDto', processed: boolean, callId?: string | null, message?: string | null } };

export type ApproveMessageMutationVariables = Exact<{
input: CreateMutatePostOffChainDataInput;
}>;


export type ApproveUserMutation = { __typename?: 'Mutation', updatePostOptimistic: { __typename?: 'IngestDataResponseDto', processed: boolean, callId?: string | null, message?: string | null } };
export type ApproveMessageMutation = { __typename?: 'Mutation', setPostApproveStatus: { __typename?: 'IngestDataResponseDto', processed: boolean, callId?: string | null, message?: string | null } };

export type SetReferrerIdMutationVariables = Exact<{
setReferrerIdInput: SocialProfileAddReferrerIdInput;
Expand Down Expand Up @@ -719,8 +733,17 @@ export const UpdatePostOptimistic = gql`
}
`;
export const ApproveUser = gql`
mutation ApproveUser($input: UpdatePostOptimisticInput!) {
updatePostOptimistic(updatePostOptimisticInput: $input) {
mutation ApproveUser($input: SocialProfileAddReferrerIdInput!) {
socialProfileSetActionPermissions(args: $input) {
processed
callId
message
}
}
`;
export const ApproveMessage = gql`
mutation ApproveMessage($input: CreateMutatePostOffChainDataInput!) {
setPostApproveStatus(args: $input) {
processed
callId
message
Expand Down
42 changes: 37 additions & 5 deletions src/server/datahub-queue/post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { gql } from 'graphql-request'
import {
ApproveMessageMutation,
ApproveMessageMutationVariables,
ApproveUserMutation,
ApproveUserMutationVariables,
CanAccountDoArgsInput,
Expand All @@ -8,6 +10,7 @@ import {
CreatePostOffChainMutationVariables,
GetCanAccountDoQuery,
GetCanAccountDoQueryVariables,
SocialProfileAddReferrerIdInput,
UpdatePostOptimisticInput,
UpdatePostOptimisticMutation,
UpdatePostOptimisticMutationVariables,
Expand Down Expand Up @@ -87,15 +90,15 @@ export async function updatePostData(input: UpdatePostOptimisticInput) {
}

const APPROVE_USER_MUTATION = gql`
mutation ApproveUser($input: UpdatePostOptimisticInput!) {
updatePostOptimistic(updatePostOptimisticInput: $input) {
mutation ApproveUser($input: SocialProfileAddReferrerIdInput!) {
socialProfileSetActionPermissions(args: $input) {
processed
callId
message
}
}
`
export async function approveUser(input: UpdatePostOptimisticInput) {
export async function approveUser(input: SocialProfileAddReferrerIdInput) {
const res = await datahubQueueRequest<
ApproveUserMutation,
ApproveUserMutationVariables
Expand All @@ -105,6 +108,35 @@ export async function approveUser(input: UpdatePostOptimisticInput) {
input,
},
})
throwErrorIfNotProcessed(res.updatePostOptimistic, 'Failed to approve user')
return res.updatePostOptimistic.callId
throwErrorIfNotProcessed(
res.socialProfileSetActionPermissions,
'Failed to approve user'
)
return res.socialProfileSetActionPermissions.callId
}

const APPROVE_MESSAGE_MUTATION = gql`
mutation ApproveMessage($input: CreateMutatePostOffChainDataInput!) {
setPostApproveStatus(args: $input) {
processed
callId
message
}
}
`
export async function approveMessage(input: SocialProfileAddReferrerIdInput) {
const res = await datahubQueueRequest<
ApproveMessageMutation,
ApproveMessageMutationVariables
>({
document: APPROVE_MESSAGE_MUTATION,
variables: {
input,
},
})
throwErrorIfNotProcessed(
res.setPostApproveStatus,
'Failed to approve message'
)
return res.setPostApproveStatus.callId
}
12 changes: 9 additions & 3 deletions src/services/datahub/generated-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,10 @@ export type GetUnapprovedMemesCountQueryVariables = Exact<{

export type GetUnapprovedMemesCountQuery = {
__typename?: 'Query'
posts: { __typename?: 'FindPostsResponseDto'; total?: number | null }
posts: {
__typename?: 'FindPostsResponseDto'
data: Array<{ __typename?: 'Post'; approvedInRootPost: boolean }>
}
}

export type SubscribePostSubscriptionVariables = Exact<{ [key: string]: never }>
Expand Down Expand Up @@ -3629,13 +3632,16 @@ export const GetUnapprovedMemesCount = gql`
posts(
args: {
filter: {
createdAtTimeGt: "2024-07-10T16:17:49.243Z"
createdByAccountAddress: $address
approvedInRootPost: false
rootPostId: $postId
}
pageSize: 100
}
) {
total
data {
approvedInRootPost
}
}
}
`
Expand Down
Loading

0 comments on commit 93a7cbf

Please sign in to comment.