Skip to content

Commit

Permalink
Merge pull request #4291 from coralproject/feat/CORL-2835-rejected-co…
Browse files Browse the repository at this point in the history
…mments-sync-with-queue

[CORL-2835] Reject all comments in queue
  • Loading branch information
tessalt authored Aug 18, 2023
2 parents 9ea46c7 + c8e2fef commit b177389
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 78 deletions.
1 change: 1 addition & 0 deletions src/core/client/admin/components/BanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ const BanModal: FunctionComponent<Props> = ({
message: customizeMessage ? emailMessage : getDefaultMessage,
banSiteIDs,
unbanSiteIDs,
rejectExistingComments,
});
} catch (err) {
return { [FORM_ERROR]: err.message };
Expand Down
157 changes: 85 additions & 72 deletions src/core/client/admin/components/BanUserMutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { graphql } from "react-relay";
import { Environment } from "relay-runtime";
import { commitLocalUpdate, Environment } from "relay-runtime";

import { getViewer } from "coral-framework/helpers";
import {
Expand All @@ -16,92 +16,105 @@ let clientMutationId = 0;

const BanUserMutation = createMutation(
"banUser",
(environment: Environment, input: MutationInput<MutationTypes>) => {
async (environment: Environment, input: MutationInput<MutationTypes>) => {
const viewer = getViewer(environment)!;
return commitMutationPromiseNormalized<MutationTypes>(environment, {
mutation: graphql`
mutation BanUserMutation($input: BanUserInput!) {
banUser(input: $input) {
user {
id
status {
current
warning {
active
}
premod {
active
}
suspension {
active
}
ban {
active
history {

const res = await commitMutationPromiseNormalized<MutationTypes>(
environment,
{
mutation: graphql`
mutation BanUserMutation($input: BanUserInput!) {
banUser(input: $input) {
user {
id
status {
current
warning {
active
}
premod {
active
}
suspension {
active
}
ban {
active
createdAt
createdBy {
history {
active
createdAt
createdBy {
id
username
}
}
sites {
id
username
}
}
sites {
id
}
}
}
clientMutationId
}
clientMutationId
}
}
`,
variables: {
input: {
...input,
clientMutationId: clientMutationId.toString(),
`,
variables: {
input: {
...input,
clientMutationId: clientMutationId.toString(),
},
},
},
optimisticResponse: {
banUser: {
user: {
id: input.userID,
status: {
current: lookup<GQLUser>(
environment,
input.userID
)!.status.current.concat(GQLUSER_STATUS.BANNED),
ban: {
active: true,
history: [
{
active: true,
createdAt: new Date().toISOString(),
createdBy: {
id: viewer.id,
username: viewer.username || null,
optimisticResponse: {
banUser: {
user: {
id: input.userID,
status: {
current: lookup<GQLUser>(
environment,
input.userID
)!.status.current.concat(GQLUSER_STATUS.BANNED),
ban: {
active: true,
history: [
{
active: true,
createdAt: new Date().toISOString(),
createdBy: {
id: viewer.id,
username: viewer.username || null,
},
},
},
],
sites:
input.siteIDs?.map((id) => {
return { id };
}) || [],
},
warning: {
active: false,
},
suspension: {
active: false,
},
premod: {
active: false,
],
sites:
input.siteIDs?.map((id) => {
return { id };
}) || [],
},
warning: {
active: false,
},
suspension: {
active: false,
},
premod: {
active: false,
},
},
},
clientMutationId: (clientMutationId++).toString(),
},
clientMutationId: (clientMutationId++).toString(),
},
},
});
}
);

if (input.rejectExistingComments) {
commitLocalUpdate(environment, (store) => {
const record = store.get(input.userID);
return record?.setValue(true, "allCommentsRejected");
});
}

return res;
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,15 @@ const enhanced = withFragmentContainer<Props>({
comment: graphql`
fragment ModerateCardContainer_comment on Comment {
id
site {
id
}
author {
id
email
username
allCommentsRejected
commentsRejectedOnSites
status {
current
ban {
Expand Down
16 changes: 13 additions & 3 deletions src/core/client/admin/components/UpdateUserBanMutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { graphql } from "react-relay";
import { Environment } from "relay-runtime";
import { commitLocalUpdate, Environment } from "relay-runtime";

import {
commitMutationPromiseNormalized,
Expand All @@ -12,15 +12,16 @@ let clientMutationId = 0;

const UpdateUserBanMutation = createMutation(
"updateUserBan",
(environment: Environment, input: MutationInput<QueryTypes>) => {
async (environment: Environment, input: MutationInput<QueryTypes>) => {
const {
userID,
banSiteIDs,
unbanSiteIDs,
message,
rejectExistingComments,
} = input;
return commitMutationPromiseNormalized(environment, {

const res = await commitMutationPromiseNormalized(environment, {
mutation: graphql`
mutation UpdateUserBanMutation($input: UpdateUserBanInput!) {
updateUserBan(input: $input) {
Expand Down Expand Up @@ -50,6 +51,15 @@ const UpdateUserBanMutation = createMutation(
},
},
});

if (input.rejectExistingComments) {
commitLocalUpdate(environment, (store) => {
const record = store.get(input.userID);
return record!.setValue(banSiteIDs, "commentsRejectedOnSites");
});
}

return res;
}
);

Expand Down
11 changes: 11 additions & 0 deletions src/core/client/admin/local/local.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ extend type CommentsConnection {
viewNewEdges: [CommentEdge!]
}

extend type User {
# Set to true when this user has had all of their comments
# rejected as part of the ban process, since it may take
# some time to take effect on the backend
allCommentsRejected: Boolean
# Contains ids of sites on which a user has had all of their
# comments rejected in the course of being banned on specific
# sites
commentsRejectedOnSites: [ID!]
}

extend type Local {
redirectPath: String
authView: View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ const enhanced = withPaginationContainer<
edges {
node {
id
site {
id
}
author {
commentsRejectedOnSites
allCommentsRejected
}
...ModerateCardContainer_comment
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ const enhanced = withFragmentContainer<Props>({
body
}
comment {
author {
allCommentsRejected
commentsRejectedOnSites
}
id
}
revision {
Expand Down
21 changes: 19 additions & 2 deletions src/core/client/admin/routes/Moderate/Queue/Queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ import styles from "./Queue.css";

interface Props {
comments: Array<
{ id: string } & PropTypesOf<typeof ModerateCardContainer>["comment"]
{
id: string;
site: { id: string };
author: {
allCommentsRejected: boolean | null;
commentsRejectedOnSites: ReadonlyArray<string> | null;
} | null;
} & PropTypesOf<typeof ModerateCardContainer>["comment"]
>;
settings: PropTypesOf<typeof ModerateCardContainer>["settings"];
viewer: PropTypesOf<typeof ModerateCardContainer>["viewer"];
Expand All @@ -41,7 +48,7 @@ interface Props {

const Queue: FunctionComponent<Props> = ({
settings,
comments,
comments: unfilteredComments,
viewer,
hasLoadMore: hasMore,
disableLoadMore,
Expand All @@ -61,8 +68,18 @@ const Queue: FunctionComponent<Props> = ({
useState(false);
const [conversationCommentID, setConversationCommentID] = useState("");
const [hasModerated, setHasModerated] = useState(false);
const [comments, setComments] = useState<typeof unfilteredComments>([]);
const memoize = useMemoizer();

useEffect(() => {
const filteredComments = unfilteredComments.filter(
(comment) =>
!comment.author?.allCommentsRejected &&
!comment.author?.commentsRejectedOnSites?.includes(comment.site.id)
);
setComments(filteredComments);
}, [unfilteredComments]);

// So we can register hotkeys for the first comment without immediately pulling focus
useEffect(() => {
if (comments.length > 0) {
Expand Down
14 changes: 14 additions & 0 deletions src/core/client/admin/routes/Moderate/Queue/QueueRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,26 @@ const createQueueRoute = (
cursor
node {
id
site {
id
}
author {
commentsRejectedOnSites
allCommentsRejected
}
...ModerateCardContainer_comment
}
}
edges {
node {
id
site {
id
}
author {
commentsRejectedOnSites
allCommentsRejected
}
...ModerateCardContainer_comment
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ const enhanced = withRouteConfig<Props, SingleModerateRouteQueryResponse>({
query SingleModerateRouteQuery($commentID: ID!) {
comment(id: $commentID) {
id
site {
id
}
author {
commentsRejectedOnSites
allCommentsRejected
}
...ModerateCardContainer_comment
}
settings {
Expand Down
Loading

0 comments on commit b177389

Please sign in to comment.