mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
* feat: initial impl * Create preliminary comment moderation slices CORL-688 * Move slices logic into stacks CORL-688 * Create user comment counts CORL-688 * Create naive mutation that initializes user comment counts CORL-688 * Use bulk updates in user counts migration CORL-688 * fix: review * fix: fixed issue with aggregation * Migrate creating comment into stacks CORL-688 * Migrate editing a comment to the stacks CORL-688 * Break publishing comment status out of updateAllCounts CORL-688 * review: removed variable scoping in favor of export * revert: feb8e8196cd448f5cd24f1ca2eb0b91fe9bd43c7 * review: simplification of stacks implementation This simplifies the stacks implementation to better reuse code related to count management and event publishing. This can be used to great effect with the upcomming events PR #2738. * Consolidate the tenant and common context together CORL-688 * review: removed variable scoping in favor of export * revert: feb8e8196cd448f5cd24f1ca2eb0b91fe9bd43c7 * review: simplification of stacks implementation This simplifies the stacks implementation to better reuse code related to count management and event publishing. This can be used to great effect with the upcomming events PR #2738. * fix: check if authorID is null before update user counts CORL-688 * Consolidate common/tenant context supporting files CORL-688 * feat: renamed TenantContext -> GraphContext Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { GraphQLResolveInfo } from "graphql";
|
|
|
|
import GraphContext from "coral-server/graph/context";
|
|
import {
|
|
GQLUser,
|
|
GQLUserTypeResolver,
|
|
} from "coral-server/graph/schema/__generated__/types";
|
|
import * as user from "coral-server/models/user";
|
|
import { roleIsStaff } from "coral-server/models/user/helpers";
|
|
|
|
import { RecentCommentHistoryInput } from "./RecentCommentHistory";
|
|
import { UserStatusInput } from "./UserStatus";
|
|
import { getRequestedFields } from "./util";
|
|
|
|
const maybeLoadOnlyIgnoredUserID = (
|
|
ctx: GraphContext,
|
|
info: GraphQLResolveInfo,
|
|
users?: user.IgnoredUser[]
|
|
) => {
|
|
// If there isn't any ids, then return nothing!
|
|
if (!users || users.length <= 0) {
|
|
return [];
|
|
}
|
|
|
|
// Get the field names of the fields being requested, if it's only the ID,
|
|
// we have that, so no need to make a database request.
|
|
const fields = getRequestedFields<GQLUser>(info);
|
|
if (fields.length === 1 && fields[0] === "id") {
|
|
return users.map(({ id }) => ({ id }));
|
|
}
|
|
|
|
// We want more than the ID! Get the user!
|
|
return Promise.all(users.map(({ id }) => ctx.loaders.Users.user.load(id)));
|
|
};
|
|
|
|
export const User: GQLUserTypeResolver<user.User> = {
|
|
comments: ({ id }, input, ctx) => ctx.loaders.Comments.forUser(id, input),
|
|
allComments: ({ id }, input, ctx) =>
|
|
ctx.loaders.Comments.forUserAll(id, input),
|
|
rejectedComments: ({ id }, input, ctx) =>
|
|
ctx.loaders.Comments.forUserRejected(id, input),
|
|
commentModerationActionHistory: ({ id }, input, ctx) =>
|
|
ctx.loaders.CommentModerationActions.forModerator(input, id),
|
|
status: ({ id, status }): UserStatusInput => ({
|
|
...status,
|
|
userID: id,
|
|
}),
|
|
ignoredUsers: ({ ignoredUsers }, input, ctx, info) =>
|
|
maybeLoadOnlyIgnoredUserID(ctx, info, ignoredUsers),
|
|
ignoreable: ({ role }) => !roleIsStaff(role),
|
|
recentCommentHistory: ({ id }): RecentCommentHistoryInput => ({ userID: id }),
|
|
profiles: ({ profiles }) => (profiles ? profiles : []),
|
|
};
|