mirror of
https://github.com/wassname/talk.git
synced 2026-07-03 08:19:42 +08:00
Merge branch 'next-edit' of https://github.com/coralproject/talk into next-edit
This commit is contained in:
@@ -99,7 +99,6 @@ export class CommentContainer extends Component<InnerProps, State> {
|
||||
if (showEditDialog) {
|
||||
return (
|
||||
<EditCommentFormContainer
|
||||
asset={asset}
|
||||
comment={comment}
|
||||
onClose={this.closeEditDialog}
|
||||
/>
|
||||
@@ -162,7 +161,6 @@ const enhanced = withShowAuthPopupMutation(
|
||||
asset: graphql`
|
||||
fragment CommentContainer_asset on Asset {
|
||||
...ReplyCommentFormContainer_asset
|
||||
...EditCommentFormContainer_asset
|
||||
}
|
||||
`,
|
||||
comment: graphql`
|
||||
|
||||
@@ -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<InnerProps, State> {
|
||||
) => {
|
||||
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<InnerProps>({
|
||||
asset: graphql`
|
||||
fragment EditCommentFormContainer_asset on Asset {
|
||||
id
|
||||
}
|
||||
`,
|
||||
comment: graphql`
|
||||
fragment EditCommentFormContainer_comment on Comment {
|
||||
id
|
||||
|
||||
@@ -26,7 +26,6 @@ export default (ctx: TenantContext) => ({
|
||||
ctx.user!,
|
||||
{
|
||||
id: input.commentID,
|
||||
asset_id: input.assetID,
|
||||
body: input.body,
|
||||
},
|
||||
ctx.req
|
||||
|
||||
@@ -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.
|
||||
"""
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user