mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 03:31:05 +08:00
Comment History Working
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
import {
|
||||
retrieveCommentAssetConnection,
|
||||
retrieveCommentRepliesConnection,
|
||||
retrieveCommentUserConnection,
|
||||
retrieveManyComments,
|
||||
} from "talk-server/models/comment";
|
||||
|
||||
@@ -16,6 +17,20 @@ export default (ctx: Context) => ({
|
||||
comment: new DataLoader((ids: string[]) =>
|
||||
retrieveManyComments(ctx.mongo, ctx.tenant.id, ids)
|
||||
),
|
||||
forUser: (
|
||||
userID: string,
|
||||
// Apply the graph schema defaults at the loader.
|
||||
{
|
||||
first = 10,
|
||||
orderBy = GQLCOMMENT_SORT.CREATED_AT_DESC,
|
||||
after,
|
||||
}: AssetToCommentsArgs
|
||||
) =>
|
||||
retrieveCommentUserConnection(ctx.mongo, ctx.tenant.id, userID, {
|
||||
first,
|
||||
orderBy,
|
||||
after,
|
||||
}),
|
||||
forAsset: (
|
||||
assetID: string,
|
||||
// Apply the graph schema defaults at the loader.
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import DataLoader from "dataloader";
|
||||
import Context from "talk-server/graph/tenant/context";
|
||||
// import { retrieveCommentUserConnection } from "talk-server/models/comment";
|
||||
import { retrieveManyUsers, User } from "talk-server/models/user";
|
||||
|
||||
export default (ctx: Context) => ({
|
||||
me: ctx.user,
|
||||
user: new DataLoader<string, User | null>(ids =>
|
||||
retrieveManyUsers(ctx.mongo, ctx.tenant.id, ids)
|
||||
),
|
||||
|
||||
@@ -7,6 +7,7 @@ import Comment from "./comment";
|
||||
import Mutation from "./mutation";
|
||||
import Profile from "./profile";
|
||||
import Query from "./query";
|
||||
import User from "./user";
|
||||
|
||||
const Resolvers: GQLResolver = {
|
||||
Asset,
|
||||
@@ -16,6 +17,7 @@ const Resolvers: GQLResolver = {
|
||||
Mutation,
|
||||
Profile,
|
||||
Query,
|
||||
User,
|
||||
};
|
||||
|
||||
export default Resolvers;
|
||||
|
||||
@@ -5,7 +5,7 @@ const Query: GQLQueryTypeResolver<void> = {
|
||||
comment: (source, { id }, ctx) =>
|
||||
id ? ctx.loaders.Comments.comment.load(id) : null,
|
||||
settings: (source, args, ctx) => ctx.tenant,
|
||||
me: (source, args, ctx) => ctx.user,
|
||||
me: (source, args, ctx) => ctx.loaders.Users.me,
|
||||
};
|
||||
|
||||
export default Query;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { GQLUserTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
import { User } from "talk-server/models/User";
|
||||
|
||||
const User: GQLUserTypeResolver<User> = {
|
||||
comments: (asset, input, ctx) =>
|
||||
ctx.user ? ctx.loaders.Comments.forUser(ctx.user.id, input) : [],
|
||||
};
|
||||
|
||||
export default User;
|
||||
@@ -298,6 +298,30 @@ export async function retrieveCommentAssetConnection(
|
||||
return retrieveConnection(input, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieveCommentUserConnection returns a Connection<Comment> for a given User's
|
||||
* comments.
|
||||
*
|
||||
* @param db database connection
|
||||
* @param userID the User id for the comment to retrieve
|
||||
* @param input connection configuration
|
||||
*/
|
||||
export async function retrieveCommentUserConnection(
|
||||
db: Db,
|
||||
tenantID: string,
|
||||
userID: string,
|
||||
input: ConnectionInput
|
||||
) {
|
||||
// Create the query.
|
||||
const query = new Query(collection(db)).where({
|
||||
tenant_id: tenantID,
|
||||
author_id: userID,
|
||||
});
|
||||
|
||||
// Return a connection for the comments query.
|
||||
return retrieveConnection(input, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieveConnection returns a Connection<Comment> for the given input and
|
||||
* Query.
|
||||
|
||||
Reference in New Issue
Block a user