mirror of
https://github.com/wassname/talk.git
synced 2026-08-08 11:28:12 +08:00
[CORL-239, CORL-128] Support disabled commenting and closed stories in Stream (#2205)
* feat: closed story + disabled commenting * test: add feature test and fix bugs * fix: snapshot * fix: isClosed can't be null * fix: remove duplicate DeepPartial type * fix: border color
This commit is contained in:
@@ -189,6 +189,22 @@ export class TalkError extends VError {
|
||||
}
|
||||
}
|
||||
|
||||
export class CommentingDisabledError extends TalkError {
|
||||
constructor() {
|
||||
super({
|
||||
code: ERROR_CODES.COMMENTING_DISABLED,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class StoryClosedError extends TalkError {
|
||||
constructor() {
|
||||
super({
|
||||
code: ERROR_CODES.STORY_CLOSED,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class CommentBodyTooShortError extends TalkError {
|
||||
constructor(min: number) {
|
||||
super({
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { ERROR_CODES } from "talk-common/errors";
|
||||
|
||||
export const ERROR_TRANSLATIONS: Record<ERROR_CODES, string> = {
|
||||
COMMENTING_DISABLED: "error-commentingDisabled",
|
||||
STORY_CLOSED: "error-storyClosed",
|
||||
COMMENT_BODY_TOO_SHORT: "error-commentBodyTooShort",
|
||||
COMMENT_BODY_EXCEEDS_MAX_LENGTH: "error-commentBodyExceedsMaxLength",
|
||||
STORY_URL_NOT_PERMITTED: "error-storyURLNotPermitted",
|
||||
|
||||
@@ -7,7 +7,10 @@ import { storyModerationInputResolver } from "./ModerationQueues";
|
||||
|
||||
export const Story: GQLStoryTypeResolver<story.Story> = {
|
||||
comments: (s, input, ctx) => ctx.loaders.Comments.forStory(s.id, input),
|
||||
isClosed: () => false,
|
||||
isClosed: (s, input, ctx) => {
|
||||
const closedAt = getStoryClosedAt(ctx.tenant, s);
|
||||
return !!closedAt && new Date() >= closedAt;
|
||||
},
|
||||
closedAt: (s, input, ctx) => getStoryClosedAt(ctx.tenant, s),
|
||||
commentActionCounts: s => decodeActionCounts(s.commentCounts.action),
|
||||
commentCounts: s => s.commentCounts.status,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
error-commentingDisabled = Commenting has been disabled tenant wide.
|
||||
error-storyClosed = Story is currently closed for commenting.
|
||||
error-commentBodyTooShort = Comment body must have at least {$min} characters.
|
||||
error-commentBodyExceedsMaxLength =
|
||||
Comment body exceeds maximum length of {$max} characters.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CommentingDisabledError } from "talk-server/errors";
|
||||
import { ModerationSettings } from "talk-server/models/settings";
|
||||
import {
|
||||
IntermediateModerationPhase,
|
||||
@@ -16,7 +17,6 @@ export const commentingDisabled: IntermediateModerationPhase = ({
|
||||
testDisabledCommenting(tenant) ||
|
||||
(story.settings && testDisabledCommenting(story.settings))
|
||||
) {
|
||||
// TODO: (wyattjoh) return better error.
|
||||
throw new Error("commenting has been disabled tenant wide");
|
||||
throw new CommentingDisabledError();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { StoryClosedError } from "talk-server/errors";
|
||||
import {
|
||||
IntermediateModerationPhase,
|
||||
IntermediatePhaseResult,
|
||||
@@ -11,7 +12,6 @@ export const storyClosed: IntermediateModerationPhase = ({
|
||||
}): IntermediatePhaseResult | void => {
|
||||
const closedAt = getStoryClosedAt(tenant, story);
|
||||
if (closedAt && closedAt.valueOf() <= Date.now()) {
|
||||
// TODO: (wyattjoh) return better error.
|
||||
throw new Error("story is currently closed for commenting");
|
||||
throw new StoryClosedError();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user