mirror of
https://github.com/wassname/talk.git
synced 2026-07-31 12:50:48 +08:00
Merge branch 'next' into next-respect
This commit is contained in:
@@ -26,7 +26,6 @@ export default (ctx: TenantContext) => ({
|
||||
ctx.user!,
|
||||
{
|
||||
id: input.commentID,
|
||||
asset_id: input.assetID,
|
||||
body: input.body,
|
||||
},
|
||||
ctx.req
|
||||
|
||||
@@ -970,12 +970,8 @@ type Query {
|
||||
|
||||
"""
|
||||
me is the current logged in User.
|
||||
|
||||
clientAuthRevision is an implementation detail that is only
|
||||
used on the client to invalidate the cache.
|
||||
TODO: This should move to a client side directive if this becomes possible.
|
||||
"""
|
||||
me(clientAuthRevision: Int): User
|
||||
me: User
|
||||
|
||||
"""
|
||||
settings is the Settings for a given Tenant.
|
||||
@@ -1040,11 +1036,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.
|
||||
"""
|
||||
|
||||
@@ -104,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
|
||||
@@ -126,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(
|
||||
{
|
||||
@@ -145,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: {
|
||||
|
||||
@@ -136,12 +136,7 @@ async function addCommentActions(
|
||||
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,
|
||||
@@ -150,15 +145,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,
|
||||
@@ -168,11 +170,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