feat: added featured comment notifications (#2524)

This commit is contained in:
Wyatt Johnson
2019-09-05 17:10:03 +00:00
committed by GitHub
parent 04c56b3fb5
commit e35978096f
18 changed files with 228 additions and 58 deletions
@@ -31,6 +31,7 @@ import {
} from "coral-server/services/comments/actions";
import { approve } from "coral-server/services/comments/moderation";
import { publishCommentFeatured } from "coral-server/services/events";
import { validateMaximumLength, WithoutMutationID } from "./util";
export const Comments = (ctx: TenantContext) => ({
@@ -164,15 +165,23 @@ export const Comments = (ctx: TenantContext) => ({
ctx.user!,
GQLTAG.FEATURED,
ctx.now
).then(comment =>
comment.status !== GQLCOMMENT_STATUS.APPROVED
? approve(ctx.mongo, ctx.redis, ctx.publisher, ctx.tenant, {
commentID,
commentRevisionID,
moderatorID: ctx.user!.id,
})
: comment
),
)
.then(comment =>
comment.status !== GQLCOMMENT_STATUS.APPROVED
? approve(ctx.mongo, ctx.redis, ctx.publisher, ctx.tenant, {
commentID,
commentRevisionID,
moderatorID: ctx.user!.id,
})
: comment
)
.then(comment => {
// Publish that the comment was featured.
publishCommentFeatured(ctx.publisher, comment);
// Return it to the next step.
return comment;
}),
unfeature: ({ commentID }: WithoutMutationID<GQLUnfeatureCommentInput>) =>
removeTag(ctx.mongo, ctx.tenant, commentID, GQLTAG.FEATURED),
});
@@ -7,14 +7,13 @@ import {
} from "coral-server/graph/tenant/schema/__generated__/types";
import { decodeActionCounts } from "coral-server/models/action/comment";
import * as story from "coral-server/models/story";
import { getStoryClosedAt } from "coral-server/services/stories";
import TenantContext from "../context";
import { CommentCountsInput } from "./CommentCounts";
import { storyModerationInputResolver } from "./ModerationQueues";
const isStoryClosed = (s: story.Story, ctx: TenantContext) => {
const closedAt = getStoryClosedAt(ctx.tenant, s) || null;
const closedAt = story.getStoryClosedAt(ctx.tenant, s) || null;
return !!closedAt && new Date() >= closedAt;
};
@@ -25,7 +24,7 @@ export const Story: GQLStoryTypeResolver<story.Story> = {
status: (s, input, ctx) =>
isStoryClosed(s, ctx) ? GQLSTORY_STATUS.CLOSED : GQLSTORY_STATUS.OPEN,
isClosed: (s, input, ctx) => isStoryClosed(s, ctx),
closedAt: (s, input, ctx) => getStoryClosedAt(ctx.tenant, s) || null,
closedAt: (s, input, ctx) => story.getStoryClosedAt(ctx.tenant, s) || null,
commentActionCounts: s => decodeActionCounts(s.commentCounts.action),
commentCounts: (s): CommentCountsInput => s,
// Merge tenant settings into the story settings so we can easily inherit the
@@ -0,0 +1,30 @@
import { SubscriptionToCommentFeaturedResolver } from "coral-server/graph/tenant/schema/__generated__/types";
import { createIterator } from "./helpers";
import {
SUBSCRIPTION_CHANNELS,
SubscriptionPayload,
SubscriptionType,
} from "./types";
export interface CommentFeaturedInput extends SubscriptionPayload {
storyID: string;
commentID: string;
}
export type CommentFeaturedSubscription = SubscriptionType<
SUBSCRIPTION_CHANNELS.COMMENT_FEATURED,
CommentFeaturedInput
>;
export const commentFeatured: SubscriptionToCommentFeaturedResolver<
CommentFeaturedInput
> = createIterator(SUBSCRIPTION_CHANNELS.COMMENT_FEATURED, {
filter: (source, { storyID }) => {
if (source.storyID !== storyID) {
return false;
}
return true;
},
});
@@ -2,6 +2,7 @@ import { GQLSubscriptionTypeResolver } from "coral-server/graph/tenant/schema/__
import { commentCreated } from "./commentCreated";
import { commentEnteredModerationQueue } from "./commentEnteredModerationQueue";
import { commentFeatured } from "./commentFeatured";
import { commentLeftModerationQueue } from "./commentLeftModerationQueue";
import { commentReplyCreated } from "./commentReplyCreated";
import { commentStatusUpdated } from "./commentStatusUpdated";
@@ -12,4 +13,5 @@ export const Subscription: GQLSubscriptionTypeResolver = {
commentLeftModerationQueue,
commentReplyCreated,
commentStatusUpdated,
commentFeatured,
};
@@ -1,5 +1,6 @@
import { CommentCreatedSubscription } from "./commentCreated";
import { CommentEnteredModerationQueueSubscription } from "./commentEnteredModerationQueue";
import { CommentFeaturedSubscription } from "./commentFeatured";
import { CommentLeftModerationQueueSubscription } from "./commentLeftModerationQueue";
import { CommentReplyCreatedSubscription } from "./commentReplyCreated";
import { CommentStatusUpdatedSubscription } from "./commentStatusUpdated";
@@ -10,6 +11,7 @@ export enum SUBSCRIPTION_CHANNELS {
COMMENT_STATUS_UPDATED = "COMMENT_STATUS_UPDATED",
COMMENT_REPLY_CREATED = "COMMENT_REPLY_CREATED",
COMMENT_CREATED = "COMMENT_CREATED",
COMMENT_FEATURED = "COMMENT_FEATURED",
}
export interface SubscriptionPayload {
@@ -29,4 +31,5 @@ export type SUBSCRIPTION_INPUT =
| CommentLeftModerationQueueSubscription
| CommentStatusUpdatedSubscription
| CommentReplyCreatedSubscription
| CommentCreatedSubscription;
| CommentCreatedSubscription
| CommentFeaturedSubscription;
@@ -5275,6 +5275,16 @@ type CommentReplyCreatedPayload {
comment: Comment!
}
"""
CommentFeaturedPayload is returned when a Comment is featured.
"""
type CommentFeaturedPayload {
"""
comment is the Comment that was featured.
"""
comment: Comment!
}
type Subscription {
"""
commentEnteredModerationQueue returns when a Comment enters a ModerationQueue.
@@ -5312,4 +5322,10 @@ type Subscription {
comments.
"""
commentReplyCreated(ancestorID: ID!): CommentReplyCreatedPayload!
"""
commentFeatured returns when a Comment is featured.
"""
commentFeatured(storyID: ID!): CommentFeaturedPayload!
@auth(roles: [MODERATOR, ADMIN])
}