mirror of
https://github.com/wassname/talk.git
synced 2026-09-11 12:51:33 +08:00
rename Comments.comment to Comments.visible and allow slack task to load any comment regardless of visibility (#2855)
Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
This commit is contained in:
co-authored by
Wyatt Johnson
parent
a059e70d05
commit
c052d37a6f
@@ -69,7 +69,7 @@ const primeCommentsFromConnection = (ctx: Context) => (
|
|||||||
if (!ctx.disableCaching) {
|
if (!ctx.disableCaching) {
|
||||||
// For each of the nodes, prime the comment loader.
|
// For each of the nodes, prime the comment loader.
|
||||||
connection.nodes.forEach(comment => {
|
connection.nodes.forEach(comment => {
|
||||||
ctx.loaders.Comments.comment.prime(comment.id, comment);
|
ctx.loaders.Comments.visible.prime(comment.id, comment);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ const mapVisibleComments = (user?: Pick<User, "role">) => (
|
|||||||
): Array<Readonly<Comment> | null> => comments.map(mapVisibleComment(user));
|
): Array<Readonly<Comment> | null> => comments.map(mapVisibleComment(user));
|
||||||
|
|
||||||
export default (ctx: Context) => ({
|
export default (ctx: Context) => ({
|
||||||
comment: new DataLoader<string, Readonly<Comment> | null>(
|
visible: new DataLoader<string, Readonly<Comment> | null>(
|
||||||
(ids: string[]) =>
|
(ids: string[]) =>
|
||||||
retrieveManyComments(ctx.mongo, ctx.tenant.id, ids).then(
|
retrieveManyComments(ctx.mongo, ctx.tenant.id, ids).then(
|
||||||
mapVisibleComments(ctx.user)
|
mapVisibleComments(ctx.user)
|
||||||
@@ -126,6 +126,14 @@ export default (ctx: Context) => ({
|
|||||||
cache: !ctx.disableCaching,
|
cache: !ctx.disableCaching,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
comment: new DataLoader<string, Readonly<Comment> | null>(
|
||||||
|
(ids: string[]) => retrieveManyComments(ctx.mongo, ctx.tenant.id, ids),
|
||||||
|
{
|
||||||
|
// Disable caching for the DataLoader if the Context is designed to be
|
||||||
|
// long lived.
|
||||||
|
cache: !ctx.disableCaching,
|
||||||
|
}
|
||||||
|
),
|
||||||
forFilter: ({
|
forFilter: ({
|
||||||
first,
|
first,
|
||||||
after,
|
after,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export const maybeLoadOnlyID = (
|
|||||||
|
|
||||||
// We want more than the ID! Get the comment!
|
// We want more than the ID! Get the comment!
|
||||||
// TODO: (wyattjoh) if the parent and the parents (containing the parent) are requested, the parent comment is retrieved from the database twice. Investigate ways of reducing i/o.
|
// TODO: (wyattjoh) if the parent and the parents (containing the parent) are requested, the parent comment is retrieved from the database twice. Investigate ways of reducing i/o.
|
||||||
return ctx.loaders.Comments.comment.load(id);
|
return ctx.loaders.Comments.visible.load(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Comment: GQLCommentTypeResolver<comment.Comment> = {
|
export const Comment: GQLCommentTypeResolver<comment.Comment> = {
|
||||||
@@ -77,7 +77,7 @@ export const Comment: GQLCommentTypeResolver<comment.Comment> = {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const children = await ctx.loaders.Comments.comment.loadMany(childIDs);
|
const children = await ctx.loaders.Comments.visible.loadMany(childIDs);
|
||||||
return children.reduce(
|
return children.reduce(
|
||||||
(sum: any, c: any) => (c && hasPublishedStatus(c) ? sum + 1 : sum),
|
(sum: any, c: any) => (c && hasPublishedStatus(c) ? sum + 1 : sum),
|
||||||
0
|
0
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const CommentModerationAction: GQLCommentModerationActionTypeResolver<
|
|||||||
actions.CommentModerationAction
|
actions.CommentModerationAction
|
||||||
> = {
|
> = {
|
||||||
revision: async (action, input, ctx) => {
|
revision: async (action, input, ctx) => {
|
||||||
const comment = await ctx.loaders.Comments.comment.load(action.commentID);
|
const comment = await ctx.loaders.Comments.visible.load(action.commentID);
|
||||||
if (!comment) {
|
if (!comment) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const Query: Required<GQLQueryTypeResolver<void>> = {
|
|||||||
user: (source, args, ctx) => ctx.loaders.Users.user.load(args.id),
|
user: (source, args, ctx) => ctx.loaders.Users.user.load(args.id),
|
||||||
users: (source, args, ctx) => ctx.loaders.Users.connection(args),
|
users: (source, args, ctx) => ctx.loaders.Users.connection(args),
|
||||||
comment: (source, { id }, ctx) =>
|
comment: (source, { id }, ctx) =>
|
||||||
id ? ctx.loaders.Comments.comment.load(id) : null,
|
id ? ctx.loaders.Comments.visible.load(id) : null,
|
||||||
comments: (source, args, ctx) => ctx.loaders.Comments.forFilter(args),
|
comments: (source, args, ctx) => ctx.loaders.Comments.forFilter(args),
|
||||||
settings: (source, args, ctx) => ctx.tenant,
|
settings: (source, args, ctx) => ctx.tenant,
|
||||||
viewer: (source, args, ctx) => ctx.user,
|
viewer: (source, args, ctx) => ctx.user,
|
||||||
|
|||||||
Reference in New Issue
Block a user