From 87d32680f0cd3242eebda674e8efb34aeafcc428 Mon Sep 17 00:00:00 2001 From: Vinh Date: Fri, 24 Jul 2020 18:48:02 +0200 Subject: [PATCH] fix: restore ReportCommentEvent (#3037) Co-authored-by: Wyatt Johnson --- .../CreateCommentDisagreeMutation.ts | 67 ++++++++++++------- .../ReportFlow/CreateCommentFlagMutation.ts | 67 +++++++++++++------ 2 files changed, 89 insertions(+), 45 deletions(-) diff --git a/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentDisagreeMutation.ts b/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentDisagreeMutation.ts index c60701468..f05a436c6 100644 --- a/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentDisagreeMutation.ts +++ b/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentDisagreeMutation.ts @@ -6,6 +6,7 @@ import { createMutation, MutationInput, } from "coral-framework/lib/relay"; +import { ReportCommentEvent } from "coral-stream/events"; import { CreateCommentDisagreeMutation as MutationTypes } from "coral-stream/__generated__/CreateCommentDisagreeMutation.graphql"; @@ -13,32 +14,52 @@ let clientMutationId = 0; const CreateCommentDisagreeMutation = createMutation( "createCommentDisagree", - (environment: Environment, input: MutationInput) => - commitMutationPromiseNormalized(environment, { - mutation: graphql` - mutation CreateCommentDisagreeMutation( - $input: CreateCommentDontAgreeInput! - ) { - createCommentDontAgree(input: $input) { - comment { - id - viewerActionPresence { - dontAgree + ( + environment: Environment, + input: MutationInput, + { eventEmitter } + ) => { + const reportCommentEvent = ReportCommentEvent.begin(eventEmitter, { + reason: "DONT_AGREE", + additionalDetails: input.additionalDetails || undefined, + commentID: input.commentID, + }); + try { + const result = commitMutationPromiseNormalized( + environment, + { + mutation: graphql` + mutation CreateCommentDisagreeMutation( + $input: CreateCommentDontAgreeInput! + ) { + createCommentDontAgree(input: $input) { + comment { + id + viewerActionPresence { + dontAgree + } + } + clientMutationId } } - clientMutationId - } + `, + variables: { + input: { + commentID: input.commentID, + commentRevisionID: input.commentRevisionID, + additionalDetails: input.additionalDetails, + clientMutationId: (clientMutationId++).toString(), + }, + }, } - `, - variables: { - input: { - commentID: input.commentID, - commentRevisionID: input.commentRevisionID, - additionalDetails: input.additionalDetails, - clientMutationId: (clientMutationId++).toString(), - }, - }, - }) + ); + reportCommentEvent.success(); + return result; + } catch (error) { + reportCommentEvent.error({ message: error.message, code: error.code }); + throw error; + } + } ); export default CreateCommentDisagreeMutation; diff --git a/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentFlagMutation.ts b/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentFlagMutation.ts index fd767a227..96bff1249 100644 --- a/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentFlagMutation.ts +++ b/src/core/client/stream/tabs/Comments/Comment/ReportFlow/CreateCommentFlagMutation.ts @@ -6,6 +6,7 @@ import { createMutation, MutationInput, } from "coral-framework/lib/relay"; +import { ReportCommentEvent } from "coral-stream/events"; import { CreateCommentFlagMutation as MutationTypes } from "coral-stream/__generated__/CreateCommentFlagMutation.graphql"; @@ -13,31 +14,53 @@ let clientMutationId = 0; const CreateCommentFlagMutation = createMutation( "createCommentFlag", - (environment: Environment, input: MutationInput) => - commitMutationPromiseNormalized(environment, { - mutation: graphql` - mutation CreateCommentFlagMutation($input: CreateCommentFlagInput!) { - createCommentFlag(input: $input) { - comment { - id - viewerActionPresence { - flag + ( + environment: Environment, + input: MutationInput, + { eventEmitter } + ) => { + const reportCommentEvent = ReportCommentEvent.begin(eventEmitter, { + reason: input.reason, + commentID: input.commentID, + additionalDetails: input.additionalDetails || undefined, + }); + try { + const result = commitMutationPromiseNormalized( + environment, + { + mutation: graphql` + mutation CreateCommentFlagMutation( + $input: CreateCommentFlagInput! + ) { + createCommentFlag(input: $input) { + comment { + id + viewerActionPresence { + flag + } + } + clientMutationId } } - clientMutationId - } + `, + variables: { + input: { + commentID: input.commentID, + commentRevisionID: input.commentRevisionID, + reason: input.reason, + additionalDetails: input.additionalDetails, + clientMutationId: (clientMutationId++).toString(), + }, + }, } - `, - variables: { - input: { - commentID: input.commentID, - commentRevisionID: input.commentRevisionID, - reason: input.reason, - additionalDetails: input.additionalDetails, - clientMutationId: (clientMutationId++).toString(), - }, - }, - }) + ); + reportCommentEvent.success(); + return result; + } catch (error) { + reportCommentEvent.error({ message: error.message, code: error.code }); + throw error; + } + } ); export default CreateCommentFlagMutation;