diff --git a/src/core/client/stream/containers/CommentContainer.tsx b/src/core/client/stream/containers/CommentContainer.tsx index fe6747d2b..309c3d337 100644 --- a/src/core/client/stream/containers/CommentContainer.tsx +++ b/src/core/client/stream/containers/CommentContainer.tsx @@ -99,7 +99,6 @@ export class CommentContainer extends Component { if (showEditDialog) { return ( @@ -162,7 +161,6 @@ const enhanced = withShowAuthPopupMutation( asset: graphql` fragment CommentContainer_asset on Asset { ...ReplyCommentFormContainer_asset - ...EditCommentFormContainer_asset } `, comment: graphql` diff --git a/src/core/client/stream/containers/EditCommentFormContainer.tsx b/src/core/client/stream/containers/EditCommentFormContainer.tsx index bdf8130b1..9dee698d3 100644 --- a/src/core/client/stream/containers/EditCommentFormContainer.tsx +++ b/src/core/client/stream/containers/EditCommentFormContainer.tsx @@ -8,7 +8,6 @@ import { BadUserInputError } from "talk-framework/lib/errors"; import { withFragmentContainer } from "talk-framework/lib/relay"; import { PropTypesOf } from "talk-framework/types"; -import { EditCommentFormContainer_asset as AssetData } from "talk-stream/__generated__/EditCommentFormContainer_asset.graphql"; import { EditCommentFormContainer_comment as CommentData } from "talk-stream/__generated__/EditCommentFormContainer_comment.graphql"; import EditCommentForm, { @@ -20,7 +19,6 @@ interface InnerProps { editComment: EditCommentMutation; comment: CommentData; onClose?: () => void; - asset: AssetData; autofocus: boolean; } @@ -74,7 +72,6 @@ export class EditCommentFormContainer extends Component { ) => { try { await this.props.editComment({ - assetID: this.props.asset.id, commentID: this.props.comment.id, body: input.body, }); @@ -114,11 +111,6 @@ const enhanced = withContext(({ sessionStorage, browserInfo }) => ({ }))( withEditCommentMutation( withFragmentContainer({ - asset: graphql` - fragment EditCommentFormContainer_asset on Asset { - id - } - `, comment: graphql` fragment EditCommentFormContainer_comment on Comment { id diff --git a/src/core/server/graph/tenant/mutators/comment.ts b/src/core/server/graph/tenant/mutators/comment.ts index d0c26e431..aeaac70ee 100644 --- a/src/core/server/graph/tenant/mutators/comment.ts +++ b/src/core/server/graph/tenant/mutators/comment.ts @@ -26,7 +26,6 @@ export default (ctx: TenantContext) => ({ ctx.user!, { id: input.commentID, - asset_id: input.assetID, body: input.body, }, ctx.req diff --git a/src/core/server/graph/tenant/schema/schema.graphql b/src/core/server/graph/tenant/schema/schema.graphql index dc689f403..1ba2546d6 100644 --- a/src/core/server/graph/tenant/schema/schema.graphql +++ b/src/core/server/graph/tenant/schema/schema.graphql @@ -879,11 +879,6 @@ type CreateCommentPayload { EditCommentInput provides the input for the editComment Mutation. """ input EditCommentInput { - """ - assetID is the ID of the Asset where we are editing a comment on. - """ - assetID: ID! - """ commentID is the ID of the comment being edited. """ diff --git a/src/core/server/models/comment.ts b/src/core/server/models/comment.ts index d2c8e03a6..bec7cc382 100644 --- a/src/core/server/models/comment.ts +++ b/src/core/server/models/comment.ts @@ -2,6 +2,7 @@ import { Db } from "mongodb"; import uuid from "uuid"; import { Omit, Sub } from "talk-common/types"; +import { dotize } from "talk-common/utils/dotize"; import { GQLCOMMENT_SORT, GQLCOMMENT_STATUS, @@ -103,7 +104,7 @@ export async function createComment( export type EditCommentInput = Pick< Comment, - "id" | "author_id" | "body" | "status" + "id" | "author_id" | "body" | "status" | "metadata" > & { /** * lastEditableCommentCreatedAt is the date that the last comment would have @@ -125,7 +126,16 @@ export async function editComment( ]; const createdAt = new Date(); - const { id, body, lastEditableCommentCreatedAt, status, author_id } = input; + const { + id, + body, + lastEditableCommentCreatedAt, + status, + author_id, + metadata, + } = input; + + // TODO: (wyattjoh) consider resetting the action counts if we're starting fresh with a new comment const result = await collection(db).findOneAndUpdate( { @@ -144,6 +154,10 @@ export async function editComment( $set: { body, status, + // Embed all the metadata properties, this may override the existing + // metadata, but we won't replace metadata that has been recalculated. + // TODO: (wyattjoh) consider if we want to replace the metadata for edited comments instead of supplementing it + ...dotize({ metadata }), }, $push: { body_history: { diff --git a/src/core/server/services/comments/index.ts b/src/core/server/services/comments/index.ts index b356b919b..25a264f5a 100644 --- a/src/core/server/services/comments/index.ts +++ b/src/core/server/services/comments/index.ts @@ -74,12 +74,7 @@ export async function create( export type EditComment = Omit< EditCommentInput, "status" | "author_id" | "lastEditableCommentCreatedAt" -> & { - /** - * asset_id is the asset that the comment exists on. - */ - asset_id: string; -}; +>; export async function edit( mongo: Db, @@ -88,15 +83,22 @@ export async function edit( input: EditComment, req?: Request ) { + // Get the comment that we're editing. + let comment = await retrieveComment(mongo, tenant.id, input.id); + if (!comment) { + // TODO: replace to match error returned by the models/comments.ts + throw new Error("comment not found"); + } + // Grab the asset that we'll use to check moderation pieces with. - const asset = await retrieveAsset(mongo, tenant.id, input.asset_id); + const asset = await retrieveAsset(mongo, tenant.id, comment.asset_id); if (!asset) { // TODO: (wyattjoh) return better error. throw new Error("asset referenced does not exist"); } // Run the comment through the moderation phases. - const { status } = await processForModeration({ + const { status, metadata } = await processForModeration({ asset, tenant, comment: input, @@ -106,11 +108,12 @@ export async function edit( // TODO: (wyattjoh) use the actions somehow. - const comment = await editComment(mongo, tenant.id, { + comment = await editComment(mongo, tenant.id, { id: input.id, author_id: author.id, body: input.body, status, + metadata, // The editable time is based on the current time, and the edit window // length. By subtracting the current date from the edit window length, we // get the maximum value for the `created_at` time that would be permitted