[next] Comment Editing (#1795)

* feat: initial impl of comment edits

* feat: added edit metadata

* review: switched out explcit null + nullable types

* fix: changed commentEdge -> edge, test comments

* [next] Tasks (#1777)

* feat: initial support for synced tenants

* fix: cleanup

* fix: logger now respects logging level

* fix: cache now ignores updates issued from itself

* feat: print subscriber count

* feat: initial moderation + validation for new comments

* fix: added Promiseable type

* feat: initial actions impl

* feat: more moderation phases

* fix: handle settings inheritence

* fix: moved settings into new file

* fix: defaults and documentation

* fix: replace merge with object spread

* feat: added integration with akismet

* fix: support tenant cache for oidc strategy

* fix: fixed compile

* fix: import ordering

* feat: added bull for queue support

* feat: support for scraping

* fix: fixes for scraper

- Implemented simple metascraper replacement (to resolve security advisory
  warning)
- Implemented simle dotize replacement (to resolve not
  working version that couldn't handle date objects)
- Plugged in asset scraping to asset creation process

* fix: handles array values

* feat: added initial scraper implementation

* feat: seperate queues but share config

* fix: simplified auth data access

* feat: moved more settings into the graph

* feat: improved mailer design

* fix: fixed issue with dotize

* fix: fixed some issues with adapter

* fix: queue cleanup

* feat: added organizationName to Tenant

* feat: email rendering

* review: support es6 imports

* fix: restore old ci step

* fix: adjusted logging messages

* fix: linting
This commit is contained in:
Wyatt Johnson
2018-09-04 18:57:41 +00:00
committed by GitHub
parent 59cf728681
commit 3897b06029
15 changed files with 289 additions and 30 deletions
@@ -1,11 +1,13 @@
import TenantContext from "talk-server/graph/tenant/context";
import { GQLCreateCommentInput } from "talk-server/graph/tenant/schema/__generated__/types";
import { Comment } from "talk-server/models/comment";
import { create } from "talk-server/services/comments";
import {
GQLCreateCommentInput,
GQLEditCommentInput,
} from "talk-server/graph/tenant/schema/__generated__/types";
import { create, edit } from "talk-server/services/comments";
export default (ctx: TenantContext) => ({
create: (input: GQLCreateCommentInput): Promise<Comment> => {
return create(
create: (input: GQLCreateCommentInput) =>
create(
ctx.mongo,
ctx.tenant,
ctx.user!,
@@ -16,6 +18,17 @@ export default (ctx: TenantContext) => ({
parent_id: input.parentID,
},
ctx.req
);
},
),
edit: (input: GQLEditCommentInput) =>
edit(
ctx.mongo,
ctx.tenant,
ctx.user!,
{
id: input.commentID,
asset_id: input.assetID,
body: input.body,
},
ctx.req
),
});
@@ -2,6 +2,16 @@ import { GQLCommentTypeResolver } from "talk-server/graph/tenant/schema/__genera
import { Comment } from "talk-server/models/comment";
const Comment: GQLCommentTypeResolver<Comment> = {
editing: (comment, input, ctx) => ({
// When there is more than one body history, then the comment has been
// edited.
edited: comment.body_history.length > 1,
// The date that the comment is editable until is the tenant's edit window
// length added to the comment created date.
editableUntil: new Date(
comment.created_at.valueOf() + ctx.tenant.editCommentWindowLength
),
}),
createdAt: comment => comment.created_at,
author: (comment, input, ctx) =>
ctx.loaders.Users.user.load(comment.author_id),
@@ -1,11 +1,15 @@
import { GQLMutationTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types";
const Mutation: GQLMutationTypeResolver<void> = {
editComment: async (source, { input }, ctx) => ({
comment: await ctx.mutators.Comment.edit(input),
clientMutationId: input.clientMutationId,
}),
createComment: async (source, { input }, ctx) => {
const comment = await ctx.mutators.Comment.create(input);
// TODO: (cvle) tell wyatt to take a look at this :-)
return {
commentEdge: {
edge: {
// FIXME: (wyattjoh) when we're using a replies/respect sort, it is index based instead of date based, needs some work!
cursor: comment.created_at,
node: comment,
},
@@ -552,6 +552,18 @@ type User {
## Comment
################################################################################
type EditInfo {
"""
edited will be True when the Comment has been edited in the past.
"""
edited: Boolean!
"""
editableUntil is the time that the comment is editable until.
"""
editableUntil: Time
}
enum COMMENT_STATUS {
"""
The comment is not PREMOD, but was not applied a moderation status by a
@@ -598,7 +610,7 @@ type Comment {
body: String
"""
createdAt is the date in which the comment was created.
createdAt is the date in which the Comment was created.
"""
createdAt: Time!
@@ -608,7 +620,7 @@ type Comment {
author: User
"""
status represents the Comment's current Status.
status represents the Comment's current status.
"""
status: COMMENT_STATUS!
@@ -619,13 +631,18 @@ type Comment {
replyCount: Int
"""
replies will return the replies to this comment.
replies will return the replies to this Comment.
"""
replies(
first: Int = 10
orderBy: COMMENT_SORT = CREATED_AT_DESC
after: Cursor
): CommentsConnection
"""
editing returns details about the edit status of a Comment.
"""
editing: EditInfo!
}
type PageInfo {
@@ -844,9 +861,54 @@ mutation.
"""
type CreateCommentPayload {
"""
CommentEdge is the possibly created comment edge.
edge is the possibly created comment edge.
"""
commentEdge: CommentEdge
edge: CommentEdge
"""
clientMutationId is required for Relay support.
"""
clientMutationId: String!
}
##################
## editComment
##################
"""
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.
"""
commentID: ID!
"""
body is the Comment body, the content of the Comment.
"""
body: String!
"""
clientMutationId is required for Relay support.
"""
clientMutationId: String!
}
"""
EditCommentPayload contains the edited Comment after the editComment
mutation.
"""
type EditCommentPayload {
"""
comment is the possibly edited comment.
"""
comment: Comment
"""
clientMutationId is required for Relay support.
@@ -1231,6 +1293,12 @@ type Mutation {
"""
createComment(input: CreateCommentInput!): CreateCommentPayload
"""
editComment will allow the author of a comment to change the body within the
time allotment.
"""
editComment(input: EditCommentInput!): EditCommentPayload @auth
"""
updateSettings will update the Settings for the given Tenant.
"""